2 Replies Latest reply on Jul 11, 2016 12:57 PM by shailu1995

    CL_MEM_ALLOC_HOST_PTR

    shailu1995

      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

        • Re: CL_MEM_ALLOC_HOST_PTR
          dipak

          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,