I have a doubt about how cl::Buffer works when created with the CL_MEM_ALLOC_HOST_PTR flag. I create it using a NULL host pointer:
Code :
cl::Buffer myBuffer(myContext, CL_MEM_ALLOC_HOST_PTR, n * sizeof(double);
Then inside a loop I map it to a host memory area:
Code :
double *hostPtr = NULL;
hostPtr = myQueue.enqueueMapBuffer(myBuffer, CL_FALSE, CL_MAP_WRITE)
This should allocate pinned host memory, map device memory to pinned host memory and return the host pointer. I fill the host memory with the data to be crunched and then send it to the device with:
Code :
myQueue.enqueueUnmapMemObject(myBuffer, hostPtr);
At this point I enqueue my kernel for execution and retrieve processed data with:
Code :
hostPtr = myQueue.enqueueMapBuffer(myBuffer, CL_TRUE, CL_MAP_READ)
// Do some stuff
myQueue.enqueueUnmapMemObject(myBuffer, hostPtr);
and the iterate the loop. I fear that calling enqueueMapBuffer with a NULL host ptr as argument may trigger host memory allocation every time, so that in my loop hostPtr is allocated twice. Is this true? If so, is it connected to calling enqueueUnmapMemObject after enqueueMapBuffer? I think that for this continuous data transfer between host and device could be sufficient to simply call enqueueMapBuffer alternating CL_MAP_WRITE and CL_MAP_READ properly, and the call enqueueUnmapMemObject only after exiting the loop, but I may be misunderstanding something.
Thanks.