surface vector (is it possible?) I need to use n surfaces


I have spent the whole day trying to get my code to compile without success because it includes a vector of surfaces

surface<void,2> surfaceRefs2[128];


surface<void,2> *surfaceRefs; (in this case I do of course malloc memory to store the surfrefs)

I know the surface references have to be global variables and I thought the errors about surfRef (or surfRef2) being undefined in my global code were due to me being too dumb at placing the global variables declaration.

Out of despair I have tried modifying the simpleSurfaceWrite example and noticed that as soon as declare a vector of surfaces (surface<void, 2> output_surface[128]) instead of just one (surface<void, 2> output_surface) and change the appearences of output_surface with output_surface[2] I get the same error as in my proyect. The compiler complains about output_surface being undefined

Could anybody tell if it is possible to declare a 1D array of surfaces or if I just making any stupid mistake ?

Thank you very much in advance

Pointers and arrays of surface types might not be possible. This sort of pointer indirection does not work with textures, since, according to the CUDA Programming Guide, “some of the attributes of a texture reference are immutable and must be known at compile time.”

Since surfaces are presented as writable textures, it is quite likely that the same restriction applies.

First of all, thank you very much for your reply.

I just had a look at the cuda 4.1 RC2 new features and I found “3D surfaces”. Maybe cuda 4.1 will just be what I need but any other suggestions will be welcome

After some years of requests for arrays of textures, NVIDIA added “layered textures” to CUDA, which allow you to access a 3D CUDA array as if it was an array of 2D textures (the distinction is important for interpolation and locality). The Programming Guide does not say there are “layered surfaces,” but as you note, you can often make due with a 3D data structure by accessing it in 2D slices.

Finally I managed to make my code work using 3D surfaces, although I would prefer 2D layered ones. Does anybody know if the 2D layered surfaces are in cuda 4.1. I could declare such a surface but as it did not seem to work I am unsure if they are really supported by the upcoming cuda release. They are not specifically mentioned in the programming guide: I found only references to 3D surfaces and to cubemap 2D layered surfaces.

Why don’t you download CUDA 4.1 RC2 yourself and check the documentation? Or update your code, compile and run it.

Hint: Layered surfaces are not declared as arrays of surface references.


template<class Type> Type surf2DLayeredread( surface<void, cudaSurfaceType2DLayered> surfRef, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap);

I have CUDA 4.1 RC2 installed and that’s the version I used for the 3D texture version of my code that is working.

But you are absolutely right, 2D layered surfaces are mentioned in the documentation which means I must have checked the wrong documentation PDF. My fault. Will try switch from 3D to 2DLayered