First of all my app is quite large and split into quite some files. I’m mentioning this in case this could be related to my prob. All my kernels are in one place cu file, all my constant variables are located in a .h file which is included in my main and my kernel cu files, and of course one main cu file that invokes the kernels. I’m importing the kernels to the main app using an .cuh file.
Constant variables are just defined in the header file using the following code:
They are afterwards initialized in the main code file and are passed on the device using cudaMemcpyToSymbol().
The problem is that for some reason, all the constant variables within the kernels are 0.0…
I’ve even tried to get the constant variables back from the device using cudaMemcpyFromSymbol() function and it returns the correct value.
Do i need to define or setup the constants otherwise?
I have no idea where to start looking, and i would really appreciate some advice
thanks in advance
EDIT: I tried to assemble a sample program, putting everything into one file and this worked fine. Could this be happening because of my multifile approach?
I’m running on a GTX750 btw.
It is not entirely clear as to what exactly you are doing. Could you post a minimal, buildable, runnable code that reproduces the problem?
constant data has file scope (i.e. “implied static storage”, see Programming Guide, section E.2.3.1). So the calls to cudaMemcpyToSymbol() have to reside in the same file where the constant data is defined.
As i said i did try to do a minimal example but i moved everything on one file and it worked smoothly. I’ll try to test this out by keeping the multiple files scheme and post it asap.
Btw i think what you said sort of helps. I am heading the same direction right now. I moved the constant variables declaration in the kernels cu file, and i wrote a small wrapper function to handle all the necessary cudaMemcpyToSymbol calls. But this doesn’t seem to work as well for some reason…
I’ve declared the following function in the kernel’s file: