Jacko
Jacko

Reputation: 13195

Want read only buffer that only copies data from host to device

I am creating a buffer using CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR.

I only want to copy memory one way, from host to device.

I am using clEnqueueMapBuffer to get a host pointer, and clEnqueueUnmapBuffer to copy the data to device.

When I call clEnqueueMapBuffer, does this trigger a copy of memory from device to host?

Upvotes: 0

Views: 393

Answers (1)

jprice
jprice

Reputation: 9925

If you are using CL_MAP_WRITE, then it will likely incur a device to host memory copy. The spec says:

The pointer returned by clEnqueueMap{Buffer | Image} is guaranteed to contain the latest bits in the region being mapped when the clEnqueueMap{Buffer | Image} command has completed

If you are using OpenCL 1.2, then you can use CL_MAP_WRITE_INVALIDATE_REGION to indicate that you intend to overwrite the entire mapped region from the host, which means that the runtime need not copy any data from the device to the host.

Upvotes: 2

Related Questions