title: CUDA programming
body: <p>I am new to CUDA. I had a question on a simple program, hope someone can notice my mistake.</p>
  
  <pre><code>__global__ void ADD(float* A, float* B, float* C)
  {
     const int ix = blockDim.x * blockIdx.x + threadIdx.x;
     const int iy = blockDim.y * blockIdx.y + threadIdx.y;
  
     if(ix &lt; 16 &amp;&amp; iy &lt; 16)
     {
        for(int i = 0; i&lt;256; i++)
        C[i] = A[ix+iy*16] + B[ix+iy*16] + C[i]; // &lt;&lt; I wish to store all in C
     }
  }
  
  extern "C" void cuda_p(float* A, float* B, float* C)
  {
      float* dev_A;
      float* dev_B;
      float* dev_C;
      cudaMalloc((void**) &amp;dev_A,  sizeof(float) * 256);
      cudaMalloc((void**) &amp;dev_B,  sizeof(float) * 256);
      cudaMalloc((void**) &amp;dev_C,  sizeof(float) * 256);
      cudaMemcpy(dev_A, A, sizeof(float) * 256, cudaMemcpyHostToDevice);
      cudaMemcpy(dev_B, B, sizeof(float) * 256, cudaMemcpyHostToDevice);
      cudaMemcpy(dev_C, C, sizeof(float) * 256, cudaMemcpyHostToDevice);
      ADDD&lt;&lt;&lt;16,16&gt;&gt;&gt;(dev_A,dev_B,dev_C);
      cudaMemcpy(A, dev_A, sizeof(float) * 256, cudaMemcpyDeviceToHost);
      cudaMemcpy(B, dev_B, sizeof(float) * 256, cudaMemcpyDeviceToHost);
      cudaMemcpy(C, dev_C, sizeof(float) * 256, cudaMemcpyDeviceToHost);
   cudaFree(dev_A);
   cudaFree(dev_B);
   cudaFree(dev_C);
  }
  </code></pre>