It turns out that in file B, the texRef is not the texRef I defined in file A anymore, or at least I did not the right result. But I put the exactly the same code which use the texRef in file B into file A, it give me correct result. Any thing I did wrong here?
When I read some post in the forum, I found that the texture reference is a static variable at the file scope. So it seems that it is not ok to extern this variable in another file. Any idea to share the texture variable in different file?
Don’t share the reference. Share the cudaArray between files. You need to bind indifidual texture references inside each compilation unit (binding is very cheap).
I follow an object oriented pardigm and never have any global variables. Instead, cuda arrays and device pointers are all allocated and managed in c++ classes an passed into functions in .cu files as parameters.