CUDA error: invalid texture reference

Hi,

I am using a texture reference that I declare as global in one file.

texture<float4, 2, cudaReadModeElementType> texRef;

Then I have another file, where I do all the memory managment (cudamalloc & cudafree)

at the begining I was compiling one single .so library from the two files and everything worked fine.

But now I need to split those two files into two different libraries.

When I allocate memory with the first library and then run a kernel in the second I get this error :

CUDA error: invalid texture reference

as soon as I used texRef in lib2 (which is declared as global in it).

So I don’t really understand what’s going on in there.

Is there some issues here about context ?

or should I declare my texture into lib1 and somehow get the reference back to lib2 ?

if so how can I do that ?

If you compile this file into two libs, you have two global variables. So you have to synchronize them as you already said.

Peter

No, I am declaring the texture only in the second library (as global) but first I run the first library to allocate memory

Have you find a solution yet? I’ve got a similar problem … ( [url=“http://forums.nvidia.com/index.php?showtopic=41299”]The Official NVIDIA Forums | NVIDIA )

regards
Pototschnig

I experience this issue too. It seems that texture references have implied static storage, although such is not mentioned in the documentation. Thus, if you bindTexture in one file, it will not bind the texture in the other file, even though they are the same texture declared extern.

My solution is to create a “big.cu” file which includes all the other .cu files in my project. Only big.cu is compiled into the library. Kludgy, but it works.

Yes no magic solution yet,

they were talking about array of text like with DirectX10 but nothing yet,

maybe in the next releases…who knows ?

I encounter a similar problem now. In my main function, I will call two CUDA functions (func1, func2) at different time. Each CUDA function will access the same texture. I can include both functions in one big.cu file, but I don’t know where to unbind texture.

Say the main function will call func1 first, then after some other functions, call func2. Should I bind texture in func1 and unbind texture in func2?

Thanks,

Yuping

You don’t ever need to unbind.

And note that you are reviving a positively ancient thread. I don’t do things the way I described above any more :) It is very challenging to work with for large projects.

The simplest solutions is to just declare local textures in each compilation unit and pass the data array or cudaArray into the kernel driver function. That kernel driver can then bind the texture just prior to calling the kernel. The overhead from this operation is very minimal.

Thank you, MisterAnderson! Your new solution is very smart!!

My question is how can I pass cudaArray between different driver functions? Do I have to allocate device memory for each function?

Thanks,

Yuping

A cudaArray* is just a pointer. You can allocate it anywhere (doesn’t even have to be in a .cu file) and pass it around like any other pointer.

Oh, you are right! I’m just passing a pointer, don’t have to bother if it’s a device array or host array at all. I was confused by myself…

Thanks for your reply. I’ll let you know my progress.

Yuping