OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

Multiple Map/Unmap buffer

Andrey_P_1
Beginner
197 Views

According to OpenCL 1.2 spec:

​clEnqueueMapBuffer and clEnqueueMapImage increment the mapped count of the memory object. The initial mapped count value of a memory object is zero. Multiple calls to clEnqueueMapBuffer or clEnqueueMapImage on the same memory object will increment this mapped count by appropriate number of calls. clEnqueueUnmapMemObject decrements the mapped count of the memory object.​

But it happens that the 2nd mapping attempt returns an error code (-59).

I've prepared a simple reproducer for the problem (attached), it's output is:

Using device: Intel(R) HD Graphics 4600 (iGPU), ver OpenCL 1.2
Using platform: Intel(R) OpenCL, ver OpenCL 1.2
Creating cl::Buffer(CL_MEM_USE_HOST_PTR, 00000083B8E33430)
Performing multiple mappings (should use internal OpenCL counter as per Khronos)
Mapping buffer #1... returned 00000083B8E33430
Mapping buffer #2...
*****
OpenCL runtime error: clEnqueueMapBuffer(-59)

 

while the expected output is:

Creating cl::Buffer(CL_MEM_USE_HOST_PTR, 0000004AD96DE160)
Performing multiple mappings (should use internal OpenCL counter as per Khronos)
Mapping buffer #1... returned 0000004AD96DE160
Mapping buffer #2... returned 0000004AD96DE160
Mapping buffer #3... returned 0000004AD96DE160
Unmapping buffer #1
Unmapping buffer #2
Unmapping buffer #3
All done.
 
0 Kudos
2 Replies
Robert_I_Intel
Employee
197 Views

Hi Andrey,

Yes, this looks like a bug to me. I can reproduce it on my side as well. Thanks for reporting the issue! I will file a bug.

Robert_I_Intel
Employee
197 Views

Hi Andrey,

After consulting with our driver architect, we think that you program is actually operating correctly. According to rev19 of the 1.2 spec, page 123, section 5.4.3. https://www.khronos.org/registry/cl/specs/opencl-1.2.pdf

“Mapping (and unmapping) overlapped regions in a memory object and/or associated memory

objects (sub-buffer objects or 1D image buffer objects that overlap this region) for writing is an

error and will result in CL_INVALID_OPERATION error returned by  clEnqueueMapBuffer, or

clEnqueueMapImage.”

 

-59 is CL_INVALID_OPERATION, so you are getting expected behavior.

 

The problem here is in the 1.2 man pages, which don't have the above wording. The spec takes precedence, though :) Both 1.1 and 2.0 man pages have this wording:

 

https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapBuffer.html

https://www.khronos.org/registry/cl/sdk/2.0/docs/man/xhtml/clEnqueueMapBuffer.html

Please correct your program accordingly.

 

Reply