title: Type Qualifiers for a device class in CUDA
body: <p>I'm currently attempting to make a piece of CUDA code with a class that will be used solely on the device side (i.e. host doesn't need to know of it's existence). However I cannot work out the correct qualifiers for the class (<code>deviceclass</code> below):</p>
  
  <pre><code>__device__ float devicefunction (float *x) {return x[0]+x[1];}
  
  class deviceclass {
      private:
          float _a;
  
      public:
          deviceclass(float *x) {_a = devicefunction(x);}
  
          float getvalue () {return _a;}
  };    
  
  // Device code
  __global__ void VecInit(float* A, int N)
  {
      int i = blockDim.x * blockIdx.x + threadIdx.x;
      if (i &lt; N) {
          deviceclass *test;
  
          test = new deviceclass(1.0, 2.0);
  
          A[i] = test-&gt;getvalue();
      }
  }
  
  // Standard CUDA guff below: Variables
  float *h_A, *d_A;
  
  // Host code
  int main(int argc, char** argv)
  {
      printf("Vector initialization...\n");
      int N = 10000;
      size_t size = N * sizeof(float);
  
      // Allocate
      h_A = (float*)malloc(size);
      cudaMalloc(&amp;d_A, size);
  
      printf("Computing...\n");
      // Invoke kernel
      int threadsPerBlock = 256;
      int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
      VecInit&lt;&lt;&lt;blocksPerGrid, threadsPerBlock&gt;&gt;&gt;(d_A, N);
  
      // Copy result from device memory to host memory
      cudaMemcpy(h_A, d_A, size, cudaMemcpyDeviceToHost);
  
      //...etc
  }
  </code></pre>
  
  <p>Setting <code>Deviceclass</code> as solely a <code>__device__</code> throws an error as it's called from a global function, however setting it as <code>__device__ __host__</code> or <code>__global__</code> seems unnecessary. Can someone point me in the right direction?</p>