cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

ginquo
Adept II

Pinned memory and CL_MEM_ALLOC_HOST_PTR for clEnqueueWriteBuffer()

Hello,

According to the AMD APP OpenCL Programming Guide, the best way to assure optimal buffer host-device write-performance is to use pinned memory using the CL_MEM_ALLOC_HOST_PTR flag with clCreateBuffer().

But I'm currently unsure how this is supposed to work. The way I'm currently doing it leads to segmentation faults on both Linux and Windows with the AMD driver.

Here's what I'm doing:

0 Likes
Reply
4 Replies
ginquo
Adept II

Re: Pinned memory and CL_MEM_ALLOC_HOST_PTR for clEnqueueWriteBuffer()

Sorry, the message got posted before I was done.

Here's what I'm doing:

Buffer::Buffer(Device& device, size_t size, cl_mem_flags flags, void** host_ptr)

{

    cl_int status;

    _buffer = clCreateBuffer(device.get_context(), flags | CL_MEM_ALLOC_HOST_PTR, size, NULL, &status);

    OPENCL_ASSERT(status);

    status = clGetMemObjectInfo(_buffer, CL_MEM_HOST_PTR, sizeof(void*), host_ptr, NULL);

    OPENCL_ASSERT(status);

}

I then use the the host_ptr to write my data into and send it to the device using clEnqueueWriteBuffer().

Am I doing something wrong here? It works perfectly fine when I'm allocating a host pointer myself using malloc and submit it to clCreateBuffer() using CL_MEM_USE_HOST_PTR. The buffers are quite small around 32 KB or so. They contain surface patch control points that are diced and rasterized by the OpenCL kernels.

Is CL_MEM_ALLOC_HOST_PTR only supposed to be used for buffer mapping? The spec is quite fuzzy on this. Isn't buffer mapping quite slow for pure host->device writes?

0 Likes
Reply
tzachi_cohen
Staff
Staff

Re: Pinned memory and CL_MEM_ALLOC_HOST_PTR for clEnqueueWriteBuffer()

clGetMemObjectInfo returns the host_ptr argument value specified when the memory object is created, which is relevant only when you specify CL_MEM_USE_HOST_PTR.(spec 1.1 section 5.4.3)

Use clEnqueueMapBuffer to acquire a pointer to a buffer created with CL_MEM_ALLOC_HOST_PTR.

ginquo
Adept II

Re: Pinned memory and CL_MEM_ALLOC_HOST_PTR for clEnqueueWriteBuffer()

Thank you that did the trick. The performance difference compared to CL_MEM_USE_HOST_PTR is quite noticeable.

It's still strange, however, that clGetMemObjectInfo() returned CL_SUCCESS and host_ptr was non-NULL afterwards.

0 Likes
Reply
tzachi_cohen
Staff
Staff

Re: Pinned memory and CL_MEM_ALLOC_HOST_PTR for clEnqueueWriteBuffer()

Thank you for your feedback! We are looking into this issue.

0 Likes
Reply