CLENQUEUEMAPIMAGE(3clc)
okay so bestie, you're looking at the CLENQUEUEMAPIMAGE(3clc) manual page β part 1 of 2, so don't go anywhere π
β¨ NAME β¨
clEnqueueMapImage β Enqueues a command to map a region of an image object into the host address space and returns a pointer to this mapped region.
here's the exact signature, no cap:
void * clEnqueueMapImage(cl_command_queue command_queue, cl_mem image,
cl_bool blocking_map, cl_map_flags map_flags,
const size_t * origin, const size_t * region,
size_t *image_row_pitch,
size_t *image_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event, cl_int *errcode_ret);
β¨ PARAMETERS β¨
command_queueβ bestie, this has to be a valid command-queue, no exceptions. πimageβ a valid image object, and the OpenCL context linked to bothcommand_queueandimagemust be the same. πΌοΈblocking_mapβ tells you if the map operation is blocking or non-blocking. π¦- if it's
CL_TRUE,clEnqueueMapImagedoes not return until that region inimageis mapped into host address space, and then you can access it with the returned pointer. - if it's
CL_FALSE(non-blocking), the returned pointer can't be used until the map command finishes. Theeventargument gives you an event object to query the map command's status. Once it's done, you can access the mapped region with the pointer.
- if it's
map_flagsβ a bit-field with these supported values: π₯CL_MAP_READβ maps the region for reading. The pointer fromclEnqueueMapBuffer(3clc)orclEnqueueMapImageis guaranteed to have the latest bits when the command completes.CL_MAP_WRITEβ maps the region for writing. Same guarantee about latest bits when the command completes.CL_MAP_WRITE_INVALIDATE_REGIONβ maps the region for writing, but the contents are discarded. Usually when the host overwrites the region. This lets the implementation skip guaranteeing latest bits, which can be a huge performance boost. Note:CL_MAP_READorCL_MAP_WRITEandCL_MAP_WRITE_INVALIDATE_REGIONare mutually exclusive. π«
originβ defines the offset. For 1D/2D/3D images it's(x, y, z)in pixels; for 2D image array it's(x, y)offset and image index; for 1D image array it's(x)offset and image index. Ifimageis 2D,origin[2]must be 0. If 1D image or 1D image buffer,origin[1]andorigin[2]must be 0. If 1D image array,origin[2]must be 0, andorigin[1]describes the image index. If 2D image array,origin[2]describes the image index. πregionβ defines the size. For 1D/2D/3D rectangle it's(width, height, depth)in pixels; for 2D rectangle it's(width, height)and number of images in 2D image array; for 1D rectangle it's(width)and number of images in 1D image array. If 2D image,region[2]must be 1. If 1D image or 1D image buffer,region[1]andregion[2]must be 1. If 1D image array,region[2]must be 1. πimage_row_pitchβ returns the scan-line pitch in bytes for the mapped region. Must be non-NULL. πimage_slice_pitchβ returns the size in bytes of each 2D slice of a 3D image, or the size of each 1D or 2D image in a 1D or 2D image array, for the mapped region. For 1D and 2D images, zero is returned if this argument isn'tNULL. For 3D image, 1D, and 2D image array, it must be non-NULL. π°event_wait_list,num_events_in_wait_listβ these specify events that must complete beforeclEnqueueMapImageruns. Ifevent_wait_listisNULL, then no events are waited on, andnum_events_in_wait_listmust be 0. If it's notNULL, the list must be valid andnum_events_in_wait_listmust be > 0. The events act as synchronization points. The context of the events andcommand_queuemust match. You can reuse or free the memory forevent_wait_listafter the function returns. β³eventβ returns an event object that identifies this specific copy command, so you can query or queue a wait for it.eventcan beNULL, but then you can't query status or wait on it. If bothevent_wait_listandeventare notNULL,eventshould not be an element ofevent_wait_list. π«errcode_retβ returns an appropriate error code. If it'sNULL, no error code comes back. β οΈ
part 2 loading... π¦
π NOTES π
okay bestie, listen up, this part is lowkey the most important vibe check of the whole page π«Ά
So the pointer you get back maps a 1D, 2D or 3D region starting at origin, and here's how big it is (and it's at least this big, no cap):
- For a 1D image, 1D image buffer or 1D image array:
region[0]pixels in size β¨ - For a 2D image or 2D image array:
(image_row_pitch * region[1])pixels in size π - For a 3D image:
(image_slice_pitch * region[2])pixels in size π
π¨ and if you go touching memory outside that region? the result is undefined. literally do not. that's the void, bestie, we don't go there π
Now, if the image object was created with CL_MEM_USE_HOST_PTR set in mem_flags, then the following is true (this is the good stuff, iykyk):
- The
host_ptryou specified inclCreateImage(3clc)is guaranteed to contain the latest bits in the region being mapped once theclEnqueueMapImagecommand has completed π - The pointer value returned by
clEnqueueMapImagewill be derived from thehost_ptryou specified when the image object was created π
Mapped image objects get unmapped using clEnqueueUnmapMemObject(3clc) β that's the exit door, don't forget to use it.
Okay now, the mapped count lore, because this is where people get caught slipping π
clEnqueueMapBuffer(3clc) 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(3clc) or clEnqueueMapImage on the same memory object will increment this mapped count by the appropriate number of calls. And clEnqueueUnmapMemObject decrements the mapped count of the memory object.
So likeβ¦ it's a counter. Count your maps, count your unmaps. Balance. β¨
Also! clEnqueueMapBuffer(3clc) and clEnqueueMapImage act as synchronization points for a region of the buffer object being mapped.
π¨ ERRORS π¨
clEnqueueMapImage will return a pointer to the mapped region if the function is executed successfully β and errcode_ret is set to CL_SUCCESS. slay π
Otherwise? You get a NULL pointer returned, with one of the following error values dropped into errcode_ret:
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid command-queue.CL_INVALID_CONTEXTif the context associated withcommand_queueandimageare not the same, or if the context associated withcommand_queueand events inevent_wait_listare not the same.CL_INVALID_MEM_OBJECTifimageis not a valid image object.CL_INVALID_VALUEif the region being mapped given by(origin, origin+region)is out of bounds, or if values specified inmap_flagsare not valid.CL_INVALID_VALUEif values inoriginandregiondo not follow the rules described in the argument description fororiginandregion.CL_INVALID_VALUEifimage_row_pitchisNULL.CL_INVALID_VALUEifimageis a 3D image, 1D or 2D image array object andimage_slice_pitchisNULL.CL_INVALID_EVENT_WAIT_LISTifevent_wait_listisNULLandnum_events_in_wait_list > 0, orevent_wait_listis notNULLandnum_events_in_wait_listis0, or if event objects inevent_wait_listare not valid events.CL_INVALID_IMAGE_SIZEif image dimensions (image width, height, specified or compute row and/or slice pitch) forimageare not supported by the device associated withqueue.CL_INVALID_IMAGE_FORMATif image format (image channel order and data type) forimageare not supported by the 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 image 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_OPERATIONif the device associated withcommand_queuedoes not support images (i.e.CL_DEVICE_IMAGE_SUPPORTspecified in the table of OpenCL Device Queries forclGetDeviceInfo(3clc)isCL_FALSE.CL_INVALID_OPERATIONifimagehas been created withCL_MEM_HOST_WRITE_ONLYorCL_MEM_HOST_NO_ACCESSandCL_MAP_READis set inmap_flags, or ifimagehas been created withCL_MEM_HOST_READ_ONLYorCL_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 there is a failure to allocate resources required by the OpenCL implementation on the host.
π«Ά read those twice, bestie. every single one of them is a real thing that can happen to you.
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
clEnqueueMapBuffer(3clc), clEnqueueUnmapMemObject(3clc)
ποΈ AUTHORS ποΈ
The Khronos Group
Β©οΈ COPYRIGHT Β©οΈ
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
(yes bestie, we keep the whole license. it's legally iconic. do not touch a single character. π)
π NOTES (the reference one) π
- OpenCL Specification page 112, section 5.3.5 - Mapping Image Objects
and that's a wrap on CLENQUEUEMAPIMAGE(3clc) π go forth and map responsibly, bestie, and always unmap π
The Khronos Group blessed us with this one on 01/14/2021 β that's the source, that's the version, and she's iconic for it. π¦β¨
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms