Nir G
Nir G

Reputation: 21

clCreateBuffer: CL_MEM_COPY_HOST_PTR with CL_MEM_ALLOC_HOST_PTR

In Khronos documentation of 'clCreateBuffer' it is stated that

  1. CL_MEM_COPY_HOST_PTR if specified, it indicates that the application wants the OpenCL implementation to allocate memory for the memory object and copy the data from memory referenced by host_ptr.

  2. "CL_MEM_COPY_HOST_PTR can be used with CL_MEM_ALLOC_HOST_PTR to initialize the contents of the cl_mem object allocated using host-accessible (e.g. PCIe) memory. "

What is the meaning of allocating memory and copying its content before/without updating it? how is it related to the PCIe example ?

Upvotes: 2

Views: 1390

Answers (1)

DarkZeros
DarkZeros

Reputation: 8410

CL_MEM_ALLOC_HOST_PTR is the flag that is usually used to indicate that the CL object has a copy (or resides) in Host memory. Usually called the pinned memory, and allows very fast copy operations. On some platforms with shared memory models, this indicates that the memory is shared between CPU and GPU. (no need for any IO extra operation)

However, the memory allocated by that flag is a special memory zone, and so, uninitialized. This is why, you can optionally use the CL_MEM_COPY_HOST_PTR to indicate that you want the buffer to be initialized with the content you are passing in the pointer (host_ptr)

cl_mem clCreateBuffer (     cl_context context,
    cl_mem_flags flags,
    size_t size,
    void *host_ptr, //<- Here
    cl_int *errcode_ret)

That flag is equivalent to doing a normal allocation + clEnqueueWriteBuffer()

Upvotes: 1

Related Questions