2013年9月12日 星期四

CUDA Zerp copy, Pinned Memory

cudaDeviceProp deviceprop;
//Get hardwared properties

cudaGetDeviceProperties(&deviceprop, 0);
//check the map memory is available or not
if(!deviceprop.canMapHostMemory)
    printf("cudaError: cannot support map host to device memory\n");


//this flag must be set in order to allocate pinned host memory that is accessible to the device
cudaSetDeviceFlags(cudaDeviceMapHost);

//allocate host page-locked and accessible to the device memory maps the memory allocation on host into cuda device

address

cudaHostAlloc((void**)&host_mm, sizeof(char)*size, cudaHostAllocMapped);


//pass back the device pointer and map with host
cudaHostGetDevicePointer((void**)&cuda_gm, (void*)&host_mm, 0);


//execute device kenel codes
kenelfuns<< >>(cuda_gm, xxxxx);


//Free the memory space which must have been returned by a previous call to cudaMallocHost or cudaHostAlloc
cudaFreeHost(host_mm);

reference
http://www.clear.rice.edu/comp422/resources/cuda/html/group__CUDART__MEMORY_g15a3871f15f8c38f5b7190946845758c.html
http://www.clear.rice.edu/comp422/resources/cuda/html/group__CUDART__MEMORY_ga475419a9b21a66036029d5001ea908c.html

沒有留言:

張貼留言