CUDA: illegal combination of memory qualifiers
<p>I have the following code:</p>

<p>main.cu:</p>

<pre><code>#include "class.h"
int main () {}
</code></pre>

<p>class.h:</p>

<pre><code>class Class {
    __global__
    void Function() {};
};
</code></pre>

<p>When I compile this code using the command <code>nvcc -c main.cu -o main.o</code>, I get the following errors:</p>

<pre><code>class.h(3): warning: inline qualifier ignored for "global" function
class.h(3): error: illegal combination of memory qualifiers
</code></pre>

<p>I have a question about each of these errors. Why does it "ignore" the <code>__global__</code> qualifier for the function, and why is the <code>__global__</code> memory qualifier illegal in this context? I have read in the <a href="http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#function-members" rel="noreferrer">documentation</a> that</p>

<pre><code>E.2.10.2. Function Members
Static member functions cannot be __global__ functions.
</code></pre>

<p>However, my function is not a static member, as far as I know. Removing the <code>__global__</code> line allows it to compile, and so does moving the <code>__global__</code> and <code>void Function();</code> 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?</p>

<p>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.</p>