Array of texture references

Hi,

In my application, I need a variable number of texture references (number ‘n’ specified by user at runtime). Like this:

texture<float, 3, cudaReadModeElementType> *texrefs;

texrefs = (texture<float, 3, cudaReadModeElementType> *) malloc(n*sizeof(texture<float, 3, cudaReadModeElementType>));

A dynamic array for that purpose is good. Is it possible to do it and how do I access the texrefs inside a kernel?

Every member of the texref will be bound to its own cudaArray.

I’m fine even if it is somehow possible to unbind/bind to different cudaArrays inside a kernel to a single texref, but I don’t think that’s possible.

Any suggestion will be highly appreciated.

-Oj

http://forums.nvidia.com/index.php?showtopic=80654

Says that it is not possible. Is it still the case with cuda 2.1? Do I have any option then?

-Oj

Yes, this is a hardware limitation (fixed in DirectX 11, btw).

Your options are:

  1. use a switch statement like in the other thread
  2. use a 3D texture

Thanks for reply. In fact I needed an array of 3D tex references.

-Oj

Sorry, missed that. Unfortunately we don’t have 4D textures. Yet!

The number of texture units is dependent on the hardware. Is there any limitation on number of 3D textures that can be simultaneously used in CUDA (did I miss that in the CUDA manuals anywhere??)? or is it again the same as the hardware limit?

I should then query CUDA to return me that limit? Is there an API for that?

As a side note, I just checked on my card (8600 M GT that supports 4 tex units) that I could use 5 texture references bound to 5 cudaArrays at the same time in a kernel!

Did I understand something wrong here??

I think I have a clue of what to do.
I can concatenate my 3D textures for form a larger (rather longer) 3D texture and kinda emulate a 4D texture!
(http://forums.nvidia.com/index.php?showtopic=44424)

Thanks Simon for the info.

-Oj

Yes, packing multiple textures into a larger texture atlas is a good solution if this works for you.

BTW, I don’t see it documented anywhere, but I believe CUDA supports up to 16 texture references.