title: Can't get simple CUDA program to work
body: <p>I'm trying the "hello world" program of CUDA programming: adding two vectors together. Here's the program I have tried:</p>
  
  <pre><code>#include &lt;cuda.h&gt;
  #include &lt;stdio.h&gt; 
  #define  SIZE 10
  
  __global__  void vecAdd(float* A, float* B, float* C) 
  { 
     int i = threadIdx.x; 
     C[i] = A[i] + B[i]; 
  } 
  
  int  main() 
  { 
       float A[SIZE], B[SIZE], C[SIZE]; 
       float *devPtrA, *devPtrB, *devPtrC; 
       size_t memsize= SIZE * sizeof(float); 
  
       for (int i=0; i&lt; SIZE; i++) {
          A[i] = i;
          B[i] = i;
       }
  
       cudaMalloc(&amp;devPtrA, memsize); 
       cudaMalloc(&amp;devPtrB, memsize); 
       cudaMalloc(&amp;devPtrC, memsize); 
       cudaMemcpy(devPtrA, A, memsize,  cudaMemcpyHostToDevice); 
       cudaMemcpy(devPtrB, B, memsize,  cudaMemcpyHostToDevice); 
  
       vecAdd&lt;&lt;&lt;1, SIZE&gt;&gt;&gt;(devPtrA,  devPtrB, devPtrC); 
       cudaMemcpy(C, devPtrC, memsize,  cudaMemcpyDeviceToHost); 
  
       for (int i=0; i&lt;SIZE; i++) 
           printf("C[%d]: %f + %f =&gt; %f\n",i,A[i],B[i],C[i]); 
  
       cudaFree(devPtrA); 
       cudaFree(devPtrB); 
       cudaFree(devPtrC); 
  }
  </code></pre>
  
  <p>Compiled with:</p>
  
  <pre><code>nvcc cuda.cu
  </code></pre>
  
  <p>Output is this:</p>
  
  <pre><code>C[0]: 0.000000 + 0.000000 =&gt; 0.000000
  C[1]: 1.000000 + 1.000000 =&gt; 0.000000
  C[2]: 2.000000 + 2.000000 =&gt; 0.000000
  C[3]: 3.000000 + 3.000000 =&gt; 0.000000
  C[4]: 4.000000 + 4.000000 =&gt; 0.000000
  C[5]: 5.000000 + 5.000000 =&gt; 0.000000
  C[6]: 6.000000 + 6.000000 =&gt; 0.000000
  C[7]: 7.000000 + 7.000000 =&gt; 0.000000
  C[8]: 8.000000 + 8.000000 =&gt; 366987238703104.000000
  C[9]: 9.000000 + 9.000000 =&gt; 0.000000
  </code></pre>
  
  <p>Every time I run it, I get a different answer for C[8], but the results for all the other elements are always 0.000000.</p>
  
  <p>The Ubuntu 11.04 system a 64-bit Xeon server with 4 cores running the latest NVIDIA drivers (downloaded on Oct 4, 2012). The card is an EVGA GeForce GT 430 with 96 cores and 1GB of RAM.</p>
  
  <p>What should I do to figure out what's going on?</p>