Your texture reference is invalid because you are using the wrap address mode with non-normalized coordinates. See the programming guide section 3.2.4.3 where it stats that this is not supported. I also think that normalized coordinates are only supported with cudaBindTextureToArray, but don’t see any mention of that in the guide - maybe it was a limitation in older versions of CUDA?
Your texture reference is invalid because you are using the wrap address mode with non-normalized coordinates. See the programming guide section 3.2.4.3 where it stats that this is not supported. I also think that normalized coordinates are only supported with cudaBindTextureToArray, but don’t see any mention of that in the guide - maybe it was a limitation in older versions of CUDA?
Attempting to bind to the address of the reference is likely what is causing your error message. Missing the *sizeof(float) would only clamp your addresses sooner than you intended :)
Attempting to bind to the address of the reference is likely what is causing your error message. Missing the *sizeof(float) would only clamp your addresses sooner than you intended :)
Unfortunately that is how it is, according to section 3.2.4.1 of the Programming Guide:
“A texture reference is declared at file scope as a variable of type texture: […] A texture reference can only be declared as a static global variable and cannot be passed as an argument to a function.”
Unfortunately that is how it is, according to section 3.2.4.1 of the Programming Guide:
“A texture reference is declared at file scope as a variable of type texture: […] A texture reference can only be declared as a static global variable and cannot be passed as an argument to a function.”
If you don’t want to use your texture as a global variable in header files, there is a little trick I use, don’t know if it’s what you are looking for.
I declare the texture as global variable in my .cu, write a function getref to get the ref on that texture, declare the function in my header file and include this header and I can use it anywhere in my program :
If you don’t want to use your texture as a global variable in header files, there is a little trick I use, don’t know if it’s what you are looking for.
I declare the texture as global variable in my .cu, write a function getref to get the ref on that texture, declare the function in my header file and include this header and I can use it anywhere in my program :
Nice trick, I didn’t know that would work given that textures are implicit static and all that. I guess references to static variables still translate across compilation units.
My solution is to only declare texture references in the .cu file where they are used. Then I simply call cudaBindTexture prior to every single kernel call as these functions map calls from classes and it is not known what instances will call the functions in what order. Bind is very cheap: the overhead of calling bind before every single kernel launch is barely measurable.
Nice trick, I didn’t know that would work given that textures are implicit static and all that. I guess references to static variables still translate across compilation units.
My solution is to only declare texture references in the .cu file where they are used. Then I simply call cudaBindTexture prior to every single kernel call as these functions map calls from classes and it is not known what instances will call the functions in what order. Bind is very cheap: the overhead of calling bind before every single kernel launch is barely measurable.
I wonder if it’s also possible to use references to other objects in a different module, such as areas of constant storage - and whether these will actually be cached on access.