cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

shailu1995
Journeyman III

CL_MEM_ALLOC_HOST_PTR

Jump to solution

Hello,

I am a newbie and playing with OpenCL for a while. I can't get a simple working example of clEnqueueMapBuffer(). Basically I want to see the effect of CL_MEM_ALLOC_HOST_PTR while creating buffer. Just a small example of vector addiction will also do.

Thanks in advance.

Shailesh

0 Likes
Reply
1 Solution

Accepted Solutions
dipak
Staff
Staff

Re: CL_MEM_ALLOC_HOST_PTR

Jump to solution

Hi Shailesh,

Welcome to this forum.

Actually, when CL_MEM_ALLOC_HOST_PTR flag  is used, the buffer is created in pinned host memory and it's a zero copy buffer. So, it has following properties compared to normal device buffer (i.e. default or created with 0 flag)

  • mapping to host or clEnqueueMapBuffer is much faster.
  • directly accessible from the GPU device(s) but in slower speed (for dGPUs, the speed is much slower and limited by PCIe bus speed)
  • Same memory location is used for each map, so, the mapping pointer will be same.

For more information, please refer the section "OpenCL Memory Objects" in AMD OpenCL Programming Optimization guide.

I've attached a small program to demonstrate the above points. [Note: memory release and other unrelated things have been ignored]

In the source file, please change MEM_FLAG and NUM_ELEMENTS macros to see the effects. Hope it will be helpful to you.

Regards,

View solution in original post

0 Likes
Reply
2 Replies
dipak
Staff
Staff

Re: CL_MEM_ALLOC_HOST_PTR

Jump to solution

Hi Shailesh,

Welcome to this forum.

Actually, when CL_MEM_ALLOC_HOST_PTR flag  is used, the buffer is created in pinned host memory and it's a zero copy buffer. So, it has following properties compared to normal device buffer (i.e. default or created with 0 flag)

  • mapping to host or clEnqueueMapBuffer is much faster.
  • directly accessible from the GPU device(s) but in slower speed (for dGPUs, the speed is much slower and limited by PCIe bus speed)
  • Same memory location is used for each map, so, the mapping pointer will be same.

For more information, please refer the section "OpenCL Memory Objects" in AMD OpenCL Programming Optimization guide.

I've attached a small program to demonstrate the above points. [Note: memory release and other unrelated things have been ignored]

In the source file, please change MEM_FLAG and NUM_ELEMENTS macros to see the effects. Hope it will be helpful to you.

Regards,

View solution in original post

0 Likes
Reply
shailu1995
Journeyman III

Re: CL_MEM_ALLOC_HOST_PTR

Jump to solution

Thanks dipak.

It helped a lot.

0 Likes
Reply