title: Piecemeal processing of a matrix - CUDA
body: <p>OK, so lets say I have an ( N x N ) matrix that I would like to process. This matrix is quite large for my computer, and if I try to send it to the device all at once I get a 'out of memory error.' </p>
  
  <p>So is there a way to send sections of the matrix to the device? One way I can see to do it is copy portions of the matrix on the host, and then send these manageable copied portions from the host to the device, and then put them back together at the end. </p>
  
  <p>Here is something I have tried, but the cudaMemcpy in the for loop returns error code 11, 'invalid argument.' </p>
  
  <pre><code>int h_N = 10000;
  size_t h_size_m = h_N*sizeof(float);
  h_A  = (float*)malloc(h_size_m*h_size_m);
  
  int d_N = 2500;
  size_t d_size_m = d_N*sizeof(float);
  
  InitializeMatrices(h_N);
  
  int i;
  int iterations = (h_N*h_N)/(d_N*d_N);
  
  for( i = 0; i &lt; iterations; i++ ) 
  {
      float* h_array_ref = h_A+(i*d_N*d_N);
      cudasafe( cudaMemcpy(d_A, h_array_ref, d_size_m*d_size_m, cudaMemcpyHostToDevice), "cudaMemcpy");
      cudasafe( cudaFree(d_A), "cudaFree(d_A)" );
  }
  </code></pre>
  
  <p>What I'm trying to accomplish with the above code is this: instead of send the entire matrix to the device, I simply send a pointer to a place within that matrix and reserve enough space on the device to do the work, and then with the next iteration of the loop move the pointer forward within the matrix, etc. etc.</p>