clamp quesiton

hey there

I’m using this way to read data through texture:

[codebox]texture<float,1> tex_x_float_A; // as global variable

cudaChannelFormatDesc channelDesc =

    cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);

cudaError_t err = cudaBindTexture(0,tex_x_float_A,A,channelDesc);

tex1Dfetch(tex_x_float_A, i);[/codebox]

In this way, does clamp work if variable i is too large and falls out of boundary?

Thanks!

Clamping should be the default behaviour in that case, yes.

Clamping should be the default behaviour in that case, yes.

Just out of curiosity, how does CUDA know the size of the array A so that it knows where the boundary is?

Just out of curiosity, how does CUDA know the size of the array A so that it knows where the boundary is?

If you’re using tex1Dfetch you don’t get clamping or filtering (see programming guide B.8.1). tex1Dfetch isn’t like a real texture lookup, it’s just a convenient way to read memory taking advantage of the texture cache and without coalescing restrictions.

BTW, you do have to specify the memory size when calling cudaBindTexture.

If you’re using tex1Dfetch you don’t get clamping or filtering (see programming guide B.8.1). tex1Dfetch isn’t like a real texture lookup, it’s just a convenient way to read memory taking advantage of the texture cache and without coalescing restrictions.

BTW, you do have to specify the memory size when calling cudaBindTexture.