C Specification
To enqueue a command to map a region of the buffer object given by buffer into the host address space and returns a pointer to this mapped region, call the function
// Provided by CL_VERSION_1_0
void* clEnqueueMapBuffer(
cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_map,
cl_map_flags map_flags,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event* event_wait_list,
cl_event* event,
cl_int* errcode_ret);
Parameters
-
command_queue must be a valid host command-queue.
-
blocking_map indicates if the map operation is blocking or non-blocking.
Description
If blocking_map is CL_TRUE, clEnqueueMapBuffer does not return until the
specified region in buffer is mapped into the host address space and the
application can access the contents of the mapped region using the pointer
returned by clEnqueueMapBuffer.
If blocking_map is CL_FALSE i.e. map operation is non-blocking, the
pointer to the mapped region returned by clEnqueueMapBuffer cannot be used
until the map command has completed.
The event argument returns an event object which can be used to query the
execution status of the map command.
When the map command is completed, the application can access the contents
of the mapped region using the pointer returned by clEnqueueMapBuffer.
-
map_flags is a bit-field and is described in the Memory Map Flags table.
-
buffer is a valid buffer object. The OpenCL context associated with command_queue and buffer must be the same.
-
offset and size are the offset in bytes and the size of the region in the buffer object that is being mapped.
-
event_wait_list and num_events_in_wait_list specify events that need to complete before this particular command can be executed. If event_wait_list is
NULL, then this particular command does not wait on any event to complete. If event_wait_list isNULL, num_events_in_wait_list must be 0. If event_wait_list is notNULL, the list of events pointed to by event_wait_list must be valid and num_events_in_wait_list must be greater than 0. The events specified in event_wait_list act as synchronization points. The context associated with events in event_wait_list and command_queue must be the same. The memory associated with event_wait_list can be reused or freed after the function returns. -
event returns an event object that identifies this command and can be used to query or queue a wait for this command to complete. If event is
NULLor the enqueue is unsuccessful, no event will be created and therefore it will not be possible to query the status of this command or to wait for this command to complete. If event_wait_list and event are notNULL, event must not refer to an element of the event_wait_list array. -
errcode_ret will return an appropriate error code. If errcode_ret is
NULL, no error code is returned.
clEnqueueMapBuffer will return a pointer to the mapped region.
The errcode_ret is set to CL_SUCCESS.
A NULL pointer is returned otherwise with one of the following error
values returned in errcode_ret:
-
CL_INVALID_COMMAND_ QUEUE -
if command_queue is not a valid host command-queue
-
-
CL_INVALID_CONTEXT -
if the context associated with command_queue and buffer are not the same
-
if the context associated with command_queue and events in event_wait_list are not the same
-
-
CL_INVALID_MEM_ OBJECT -
if buffer is not a valid buffer object
-
-
CL_INVALID_VALUE -
if the region being mapped specified by offset and size is out of bounds
-
if size is zero
-
if values specified in map_flags are not valid
-
-
CL_INVALID_EVENT_ WAIT_ LIST -
if event_wait_list is
NULLand num_events_in_wait_list is greater than zero -
if event_wait_list is not
NULLand num_events_in_wait_list is zero -
if event objects in event_wait_list are not valid events
-
-
CL_MISALIGNED_SUB_ BUFFER_ OFFSET -
if buffer is a sub-buffer object and the offset specified when the sub-buffer object was created is not aligned to the
CL_DEVICE_value for the device associated with command_queue. This error code is missing before version 1.1.MEM_ BASE_ ADDR_ ALIGN
-
-
CL_MAP_FAILURE -
if there is a failure to map the requested region into the host address space. This error cannot occur for buffer objects created with
CL_MEM_orUSE_ HOST_ PTR CL_MEM_.ALLOC_ HOST_ PTR
-
-
CL_EXEC_STATUS_ ERROR_ FOR_ EVENTS_ IN_ WAIT_ LIST -
if the map operations is blocking and the execution status of any of the events in event_wait_list is a negative integer value indicating an error. This error code is missing before version 1.1.
-
-
CL_MEM_OBJECT_ ALLOCATION_ FAILURE -
if there is a failure to allocate memory for the data store associated with buffer
-
-
CL_INVALID_OPERATION -
if buffer was created with
CL_MEM_orHOST_ WRITE_ ONLY CL_MEM_andHOST_ NO_ ACCESS CL_MAP_is set in map_flagsREAD -
if buffer was created with
CL_MEM_orHOST_ READ_ ONLY CL_MEM_andHOST_ NO_ ACCESS CL_MAP_orWRITE CL_MAP_is set in map_flagsWRITE_ INVALIDATE_ REGION -
if buffer was created with
CL_MEM_andIMMUTABLE_ EXT CL_MAP_orWRITE CL_MAP_is set in map_flagsWRITE_ INVALIDATE_ REGION -
if mapping would lead to overlapping regions being mapped for writing
-
-
CL_OUT_OF_ RESOURCES -
if there is a failure to allocate resources required by the OpenCL implementation on the device
-
-
CL_OUT_OF_ HOST_ MEMORY -
if there is a failure to allocate resources required by the OpenCL implementation on the host
-
The pointer returned maps a region starting at offset and is at least size bytes in size. The result of a memory access outside this region is undefined.
If the buffer object is created with CL_MEM_ set in mem_flags,
the following will be true:
-
The host_ptr specified in clCreateBuffer or clCreateBufferWithProperties will contain the latest bits in the region being mapped when the clEnqueueMapBuffer command has completed.
-
The pointer value returned by clEnqueueMapBuffer will be derived from the host_ptr specified when the buffer object is created.
Mapped buffer objects are unmapped using clEnqueueUnmapMemObject. This is described in Unmapping Mapped Memory Objects.
| Map Flags | Description |
|---|---|
|
This flag specifies that the region being mapped in the memory object is being mapped for reading. The pointer returned by clEnqueueMapBuffer (clEnqueueMapImage) is guaranteed to contain the latest bits in the region being mapped when the clEnqueueMapBuffer (clEnqueueMapImage) command has completed. |
|
This flag specifies that the region being mapped in the memory object is being mapped for writing. The pointer returned by clEnqueueMapBuffer (clEnqueueMapImage) is guaranteed to contain the latest bits in the region being mapped when the clEnqueueMapBuffer (clEnqueueMapImage) command has completed |
missing before version 1.2. |
This flag specifies that the region being mapped in the memory object is being mapped for writing. The contents of the region being mapped are to be discarded. This is typically the case when the region being mapped is overwritten by the host. This flag allows the implementation to no longer guarantee that the pointer returned by clEnqueueMapBuffer (clEnqueueMapImage) contains the latest bits in the region being mapped which can be a significant performance enhancement. |
Document Notes
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.