pinned memory in multiple GPUs

Viewed 459

I am using 4 GPUs and to speed up the memory transfer I am trying to use pinned memory using cudaHostAlloc().

The main UI thread(mfc base) creates 4 threads and each thread calls cudaSetDevice(nDeviceID).

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)?

Here is the pseudo code.

1) Calling cudaHostAlloc at the main thread

Main thread

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 );

Branch thread

UINT Calc(LPVOID lParam)
    ST_Param pstParam = reinterpret_cast<ST_Param*>(lParam);
    cudaSetDevice(pstParam->nDeviceID);
    Cudafunc(pstParam->size/4, pstParam->h_arrfBuf+(pstParam->nDeviceID-1)*size/4);

2) Calling cudaHostAlloc at the branch threads

Main thread

AcqBuf(arrfRaw, size);
for i =1:4
    ST_Param* pstParam = new ST_Param(i, size/4, arrfRaw + (i-1)*size/4);
    AfxBeginThread(Calc, pstParam);

Branch thread

UINT Calc(LPVOID lParam)
    ST_Param pstParam = reinterpret_cast<ST_Param*>(lParam);
    cudaSetDevice(pstParam->nDeviceID);
    cudaHostAlloc((void**)h_arrfBuf, size/4*sizeof(float), cudaHostAllocDefault);
    memcpy(h_arrfBuf, pstParam->arrfRaw, size/4*sizeof(float));
    Cudafunc(pstParam->size/4, h_arrfBuf);

What I am basically curious about is whether pinned memory is device specific or not.

1 Answers
Related