title: pinned memory in multiple GPUs
body: <p>I am using 4 GPUs and to speed up the memory transfer I am trying to use pinned memory using cudaHostAlloc().</p>
  
  <p>The main UI thread(mfc base) creates 4 threads and each thread calls cudaSetDevice(nDeviceID).</p>
  
  <p>Here is my question. Can I call cudaHostAlloc() at the main thread and give the pointer as a lParam or I have to call it in each branch thread after calling the cudaSetDevice(nDeviceID)?</p>
  
  <p>Here is the pseudo code.</p>
  
  <p>1) Calling cudaHostAlloc at the main thread</p>
  
  <p>Main thread</p>
  
  <pre><code>cudaHostAlloc((void**)h_arrfBuf, size*sizeof(float), cudaHostAllocDefault);
  AcqBuf(h_arrfBuf, size);
  for i =1:4
      ST_Param* pstParam = new ST_Param(i, size/4, h_arrfBuf);
      AfxBeginThread(Calc, pstParam );
  </code></pre>
  
  <p>Branch thread</p>
  
  <pre><code>UINT Calc(LPVOID lParam)
      ST_Param pstParam = reinterpret_cast&lt;ST_Param*&gt;(lParam);
      cudaSetDevice(pstParam-&gt;nDeviceID);
      Cudafunc(pstParam-&gt;size/4, pstParam-&gt;h_arrfBuf+(pstParam-&gt;nDeviceID-1)*size/4);
  </code></pre>
  
  <p>2) Calling cudaHostAlloc at the branch threads</p>
  
  <p>Main thread</p>
  
  <pre><code>AcqBuf(arrfRaw, size);
  for i =1:4
      ST_Param* pstParam = new ST_Param(i, size/4, arrfRaw + (i-1)*size/4);
      AfxBeginThread(Calc, pstParam);
  </code></pre>
  
  <p>Branch thread</p>
  
  <pre><code>UINT Calc(LPVOID lParam)
      ST_Param pstParam = reinterpret_cast&lt;ST_Param*&gt;(lParam);
      cudaSetDevice(pstParam-&gt;nDeviceID);
      cudaHostAlloc((void**)h_arrfBuf, size/4*sizeof(float), cudaHostAllocDefault);
      memcpy(h_arrfBuf, pstParam-&gt;arrfRaw, size/4*sizeof(float));
      Cudafunc(pstParam-&gt;size/4, h_arrfBuf);
  </code></pre>
  
  <p>What I am basically curious about is whether pinned memory is device specific or not.</p>