cuTexRefSetAddress vs cuTexRefSetArray

We would like to do the following using the driver API:

On the Host:

  1. Create an Array (2D array of 32bit words)
  2. Attach a texture reference to the array to allow cached access to the array
  3. Get the pointer to the array through the texture reference using cuTexRefGetAddress
  4. pass the kernel the pointer to the device memory as well as the texture reference
  5. Launch the kernel

On the Kernel:

  1. read from texture memory
  2. perform an operation
  3. write back to the address where the texture references the device memory

We’ve noticed that we can get the valid address from a texture reference if we used cuTexRefSetAddress to attach the texture, and we can get a valid array back when using SetArray to attach, but we cannot get a pointer to the memory allocated by the array when attaching an array.

The question is, what is the best way to go about getting the device address of an array that is attached to a texture?

Also, is there any example of using cuTexRefGetAddress or cuTexRefSetAddress? What is *pdptr - there does not seem to be any documentation on that parameter.

The short answer is that there is no way to get the device address of an array (texture) in CUDA currently.

Arrays are stored a special memory layout, and there’s no way to write directly to this layout from a CUDA kernel. You can’t “render to texture” in CUDA.

You should however be able to memcpy from linear memory to an array.

This parameter will actually disappear in the next release.

For now, just specify the same address twice and that should work.

OK, that is what we deduced from the limitations, but thanks for the clarification!

Yes, but we are trying to save a memcpy. What would be the best way to go about using textures as a cached area of memory that gets updated by the kernel? Is constant memory better suited for this? Can we write back to constant memory from the kernel?