I have the following code:
main.cu:
#include "class.h"
int main () {}
class.h:
class Class {
__global__
void Function() {};
};
When I compile this code using the command nvcc -c main.cu -o main.o, I get the following errors:
class.h(3): warning: inline qualifier ignored for "global" function
class.h(3): error: illegal combination of memory qualifiers
I have a question about each of these errors. Why does it "ignore" the __global__ qualifier for the function, and why is the __global__ memory qualifier illegal in this context? I have read in the documentation that
E.2.10.2. Function Members
Static member functions cannot be __global__ functions.
However, my function is not a static member, as far as I know. Removing the __global__ line allows it to compile, and so does moving the __global__ and void Function(); lines into main.cu. If this actually ISN'T allowed, why does CUDA force this limitation, and what is a way to get around this while still maintaining structured code?
To clarify, I know no other way to make classes that have functions which can create GPU kernels. It seems to me like kernels can only be created from global functions in main.cu. I am fairly new to CUDA programming, so I may just be missing some CUDA conventions which may have been unclear to me. If this is the case, then please let me know so I can keep up with proper programming practice.
__host__function in my class, and the implementation of that function calls a__global__function? If so, what scope should the__global__function be in? - Simon Ewing__global__qualifier is not independent from the idea of the global scope. That is, any__global__function must be a global function, in that it is defined in the global scope. I was under the understanding that__global__strictly meant that the function was defined on both the host and device, whereas a function in the global scope is accessible from any object on the host. If this explanation is correct, please post your answer as a formal answer so I can accept it. - Simon Ewing