title: cuMemHostAlloc out of memory errors
body: <p>I am having a memory allocation problem I can't quite understand. I am trying to allocate a fairly large chunk of the GPU's memory (I am guessing it is probably a memory fragmentation issue perhaps?)</p>
  
  <p>My very simplified code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cuda.h&gt;
  
  int main()
  {
      CUcontext ctx;
      CUdevice dev = 0;
      void *toSpace;
      CUdeviceptr ptr = (CUdeviceptr)NULL;
      int status;
      int size = 1280*1024*1024;
  
      status = cuInit(0);
      printf("status: %i\n",status); 
  
      status = cuCtxCreate(&amp;ctx, 0, dev);
      printf("status: %i\n",status); 
  
      status = cuMemHostAlloc(&amp;toSpace, size, 0); 
      printf("status: %i\n",status); 
  
      status = cuMemAlloc(&amp;ptr, size);
      printf("status: %i\n",status); 
  
      status = cuCtxDestroy(ctx);
      printf("status: %i\n",status); 
  
      printf("\nPress any key to exit...");
      char c;
      scanf("%c", &amp;c);
  
      return 0;
  }
  </code></pre>
  
  <p>Editted:</p>
  
  <p><code>cuMemHostAlloc</code> only lets me allocate <code>686MB</code>, anymore and I get out of memory errors. But I have over 4GB free of RAM.</p>
  
  <p>I then want to allocate GPU memory too if i try the allocating with <code>cuMemAlloc</code> I can do a maximum of <code>1279MB</code>. But according to the device info I have <code>2048MB</code> of which <code>1981MB</code> are free.</p>
  
  <p>If this is a fragmentation problem is there anyway to find the largest chunk of memory I can allocate?</p>
  
  <p>Device info is</p>
  
  <pre><code>Version:                       2.1
  Name:                          GeForce GT 525M
  Total global memory:           1981/2047 (Free/Total) MBytes
  Total registers per block:     32768    
  Warp size:                     32
  Maximum memory pitch:          2147483647
  Maximum threads per block:     1024
  Total shared memory per block  49152 Bytes
  Clock rate:                    1 MHz
  Memory Clock rate:             900000
  Total constant memory:         65536
  Integrated:                    0
  Max threads per multiprocessor:1536
  Number of multiprocessors:     2
  Maximum dimension x of block:  1024
  Maximum dimension y of block:  1024
  Maximum dimension z of block:  64
  Maximum dimension x of grid:   65535
  Maximum dimension y of grid:   65535
  Maximum dimension z of grid:   65535
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>So after mucking around alot the GPU memory allocation is fine I believe it is the host allocation going wrong.</p>
  
  <p>Problem is I free'd up even more RAM now to 6GB (8GB total) and the host allocation still fails. If I try and malloc 4GB though it works fine.</p>