OpenCL: Device / host memory coherency for variables passed to the kernel with CL_MEM_USE_HOST_PTR

If a variable is passed to the kernel with CL_MEM_USE_HOST_PTR, does this mean that any change to the variable in the device will also be shown in the host memory?

I am in a scenario where I use the CPU as a device instead of a GPU, so everything transferred to the kernel will be marked with CL_MEM_USE_HOST_PTR.

If this is true, I no longer need to read everything on the host, which is very convenient.

+5
source share
1 answer

Your understanding is correct, except for one possible mistake: the documentation states that

OpenCL host_ptr . .

, , , host_ptr. , host_ptr , .

, . , / :

CL_MEM_USE_HOST_PTR, mem_flags, host_ptr, clCreateBuffer, , , clEnqueueMapBuffer ; clEnqueueMapBuffer, host_ptr .

, Khronos:

cl_mem device_output = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, size, original_output, NULL);
// run the kernel
void* pointer = clEnqueueMapBuffer(queue, device_output, CL_TRUE, CL_MAP_READ, size, 0, 0, NULL, NULL, NULL);
// work with 'original_output'
clEnqueueUnmapMemObject(queue, device_output, pointer, 0, NULL, NULL);
clReleaseMemObject(device_output);
+8

All Articles