one texture in different kernels?


I want to split up an existing kernel file. Therefore i have to pass on my textures somehow. I tried to implement a declaration of the texture into a .cuh file and do the bind array in the corresponding .cu file. After the split of the kernel file i have to pass on the textures somehow. Therefore i simply added a parameter to the kernel functions like
global void testKernel(texture<float, 2, cudaReadModeElementType> texTest, …)

when i try to compile my code i get this from make:
Segmentation fault (core dumped)
make[2]: *** [file-path/filename.o] Error 255

whereas filename.o is the corresponding object file where an array should be bound to the texture…

In the kernel part itself i only have access operations of course (tex2D)…

Is there a solution to my problem or is it simply not possible to have a texture as a paremter and as a result be not able to use it in multiple kernels.

Kind regards,

  1. It is not possible to have a texture as a parameter. They must be global variables.
  2. Each .cu file compiles to a separate cubin. And cubins are where the textures are really defined. So, you cannot share a texture reference between multiple compilation units.

Here is hoping that they improve this with the next release. For now, your only option is to write your multiple .cu files sharing a texture declared in a .h file. But, don’t compile the .cu files separately. Make a “” that includes all the .cu files and compile only

Thx for the quick reply. I’ll try that workaround tomorrow.



Well, you can still share textures/arrays between kernels in different compilation units, just not the descriptors, as they’re basically just an id value in 0…31 which has only a local meaning.

Yes, but then you have to have a bindTexture call in each compilation unit and whenever you want to bind an array/global mem to a “shared” texture, you need to call each bindTexture. That is just a bit of a nightmare to mange IMHO.