Enqueues 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.
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)command_queue-
Must be a valid host command-queue.
blocking_map-
Indicates if the map operation is
blockingornon-blocking.If
blocking_mapisCL_TRUE,clEnqueueMapBufferdoes not return until the specified region inbufferis mapped into the host address space and the application can access the contents of the mapped region using the pointer returned byclEnqueueMapBuffer.If
blocking_mapisCL_FALSEi.e. map operation is non-blocking, the pointer to the mapped region returned byclEnqueueMapBuffercannot be used until the map command has completed. Theeventargument 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 byclEnqueueMapBuffer. map_flags-
A bit-bield with the following supported values.
buffer-
A valid buffer object. The OpenCL context associated with
command_queueandbuffermust be the same. offset,size-
The offset in bytes and the size of the region in the buffer object that is being mapped.
event_wait_list,num_events_in_wait_list-
Specify events that need to complete before this particular command can be executed. If
event_wait_listis NULL, then this particular command does not wait on any event to complete. Ifevent_wait_listis NULL,num_events_in_wait_listmust be 0. Ifevent_wait_listis not NULL, the list of events pointed to byevent_wait_listmust be valid andnum_events_in_wait_listmust be greater than 0. The events specified inevent_wait_listact as synchronization points. The context associated with events inevent_wait_listandcommand_queuemust be the same. The memory associated withevent_wait_listcan be reused or freed after the function returns. event-
Returns an event object that identifies this particular copy command and can be used to query or queue a wait for this particular command to complete.
eventcan be NULL in which case it will not be possible for the application to query the status of this command or queue a wait for this command to complete. If theevent_wait_listand theeventarguments are not NULL, theeventargument should not refer to an element of theevent_wait_listarray. errcode_ret-
Returns an appropriate error code. If
errcode_retis NULL, no error code is returned.
The returned pointer 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_USE_HOST_PTR set in mem_flags, the following will be true:
-
The
host_ptrspecified inclCreateBufferis guaranteed to contain the latest bits in the region being mapped when theclEnqueueMapBuffercommand has completed. -
The pointer value returned by
clEnqueueMapBufferwill be derived from thehost_ptrspecified when the buffer object is created.
Mapped buffer objects are unmapped using clEnqueueUnmapMemObject.
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.
clEnqueueMapBuffer and clEnqueueMapImage act as synchronization points for a region of the buffer object being mapped.
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_QUEUEifcommand_queueis not a valid host command-queue. -
CL_INVALID_CONTEXTif the context associated withcommand_queueandbufferare not the same or if the context associated withcommand_queueand events inevent_wait_listare not the same. -
CL_INVALID_MEM_OBJECTifbufferis not a valid image object. -
CL_INVALID_VALUEif region being mapped given by (offset,size) is out of bounds or ifsizeis 0 or values specified inmap_flagsare not valid. -
CL_INVALID_EVENT_WAIT_LISTifevent_wait_listis NULL andnum_events_in_wait_list> 0, orevent_wait_listis not NULL andnum_events_in_wait_listis 0, or if event objects inevent_wait_listare not valid events. -
CL_MISALIGNED_SUB_BUFFER_OFFSETifbufferis a sub-buffer object andoffsetspecified when the sub-buffer object is created is not aligned toCL_DEVICE_MEM_BASE_ADDR_ALIGNvalue for device associated withqueue. -
CL_MAP_FAILUREif there is a failure to map the requested region into the host address space. This error cannot occur for buffer objects created withCL_MEM_USE_HOST_PTRorCL_MEM_ALLOC_HOST_PTR. -
CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LISTif the map operation is blocking and the execution status of any of the events inevent_wait_listis a negative integer value. -
CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for data store associated withbuffer. -
CL_INVALID_OPERATIONifbufferhas been created withCL_MEM_HOST_WRITE_ONLYorCL_MEM_HOST_NO_ACCESSandCL_MAP_READis set inmap_flagsor ifbufferhas been created withCL_MEM_HOST_READ_ONLorCL_MEM_HOST_NO_ACCESSandCL_MAP_WRITEorCL_MAP_WRITE_INVALIDATE_REGIONis set inmap_flags. -
CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device. -
CL_OUT_OF_HOST_MEMORYif mapping would lead to overlapping regions being mapped for writing. -
CL_INVALID_OPERATIONif there is a failure to allocate resources required by the OpenCL implementation on the host.