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.2Using platform: Intel(R) OpenCL, ver OpenCL 1.2Creating cl::Buffer(CL_MEM_USE_HOST_
PTR, 00000083B8E33430)Performing multiple mappings (should use internal OpenCL counter as per Khronos)Mapping buffer #1... returned 00000083B8E33430Mapping buffer #2...*****OpenCL runtime error: clEnqueueMapBuffer(-59)
while the expected output is:
PTR, 0000004AD96DE160)Performing multiple mappings (should use internal OpenCL counter as per Khronos)Mapping buffer #1... returned 0000004AD96DE160Mapping buffer #2... returned 0000004AD96DE160Mapping buffer #3... returned 0000004AD96DE160Unmapping buffer #1Unmapping buffer #2Unmapping buffer #3All done.
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
-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:
Please correct your program accordingly.