Questions about texture memory to which point it would stop caching data

Hi all,

I have three questions about texture memory.

  1. Is the 2^27 width limit on linear memory in bytes or in elements?

  2. I have a 1638416384 matrix and I use cudaMalloc ( (void **)d_C, 1638416384sizeof(float) ) to get a linear memory and then use cudaBindTexture(&offsetC, texRefC, d_C) and cudaBindTexture(&offsetC, texRefC, d_C+163848192) to bind. Does the caching in the former one also contain the latter one. My question is how CUDA decides to which point of the memory address it would stop caching? Does my case exceed the width limit?

  3. Can I revise data in the memory area that has already been binded to a texture?


  1. elements

  2. It depends on what you give for the size parameter to the bind. Texture fetches will return zero for reads past the end of the indicated length. If that is chosen such that the two areas overlap, then yes - reading from either reference will be cached.

  3. Of course, with one caveat. You must allow the kernel that performs the writes to complete before you can expect a tex fetch from to read the modified data.

Thank you for the reply. But I’m still confused about 1 and 2.

  1. Does that mean if the element type is float4, then there are at most 2^27*sizeof(float4) bytes which would be about 2 Gigabytes cached. Then where does this 2 Gigabytes cache space come from?

  2. There seems to be different type of cudaBindTexture. In my case,

cudaBindTexture(&offsetC, texRefC, d_C)

just works fine and there is no parameter indicating how much data would be cached in this function. However, in CUDA library, cudaBindTexture is defined to be

cudaError_t cudaBindTexture (size_t * offset, const struct textureReference * texref, const void * devPtr, const struct cudaChannelFormatDesc *desc, size_t size)

where indeed there is a parameter indicating the length of the caching. I wonder what is the difference between these two? And if I use the former one, how could the compiler know how much data should be cached?