title: vector addition CUDA
body: <p>I am new to CUDA and working on the first exercise which is vector addition</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  
  // Compute vector sum C = A+B
  //CUDA kernel. Each thread performes one pair-wise addition
  
  __global__ void vecAddKernel(float *A, float *B, float *C, int n)
  {
  //Get our global thread ID
  int i = blockDim.x*blockIdx.x+threadIdx.x;
  
  if (i&lt;n) C[i] = A[i] + B[i];
  }
  
  int main(int argc, char* argv[])
  {
  
  //Size of vectors
  int n = 100000;
  
  int size = n * sizeof(float);
  
  
  //Host input vectors
  float *h_A, *h_B;
  //Host output vector
  float *h_C;
  
  //Device input vectors
  float *d_A, *d_B;
  //Device output vector
  float *d_C;
  
  //Allocate memory for each vector on host
  h_A = (float*)malloc(sizeof(size));
  h_B = (float*)malloc(sizeof(size));
  h_C = (float*)malloc(sizeof(size));
  
  //Allocate memory for each vector on GPU
  cudaMalloc( (void **) &amp;d_A, size);
  cudaMalloc( (void **) &amp;d_B, size);
  cudaMalloc( (void **) &amp;d_C, size);
  
  //Copy host vectors to device
  cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice);
  cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice);
  
  int blockSize, gridSize;
  
  //Number of threads in each block
  blockSize = 1024;//Execute the kernel
  vecAddKernel&lt;&lt;&lt;gridSize,blockSize&gt;&gt;&gt;(d_A, d_B, d_C, n);
  
  //Synchronize threads
  cudaThreadSynchronize();
  
  //Copy array back to host
  cudaMemcpy( h_C, d_C, size, cudaMemcpyDeviceToHost );
  
  
  //Release device memory
  cudaFree(d_A);
  cudaFree(d_B);
  cudaFree(d_C);
  
  //Release host memory
  free(h_A);
  free(h_B);
  free(h_C);
  
  return 0;
  }
  </code></pre>
  
  <p>The compilation was succeeded, but while running the code I get: `Segmentation fault (core dumped). I do not see where the issue is. I've tried to use nvprof, but it's not helpful in any fashion. 
  Can anyone help me to figure out where I made a mistake? </p>