title: Passing a class object to a kernel
body: <p>Can we pass an object to a kernel function ?</p>
  
  <p>Consider I have a class </p>
  
  <pre><code>class MyClass
  {
      public:
          int value;
          float rate;
          MyClass()
          {
              value = 0; rate = 0;
          }
          MyClass(int v,float r)
          {
              value = v; rate = r;
          }
  };
  </code></pre>
  
  <p>and my Kernel takes an array of the objects of MyClass</p>
  
  <pre><code>__global__ void MyKernel(MyClass * mc)
  {
      //Some Calculation
  }
  </code></pre>
  
  <p>Can I pass the array ? How to allocate memory ?? Right now I tried with the following code got CudaMemcpy error</p>
  
  <pre><code>cudaError_t cudaStatus;
  
  MyClass darr[10] ;
  cudaStatus = cudaMalloc((void**)&amp;darr, size * sizeof(MyClass));
  
  if (cudaStatus != cudaSuccess) {
      fprintf(stderr, "cudaMalloc failed!");
      goto label1;
  }
  
  cudaStatus = cudaMemcpy(darr, arr, size * sizeof(MyClass), cudaMemcpyHostToDevice);
  //arr is a host array
  </code></pre>