CLENQUEUECOPYIMAGETO(3clc)
π CLENQUEUECOPYIMAGETO π
okay bestie, sit down, hydrate, because today we're learning about clEnqueueCopyImageToBuffer from the OpenCL Manual (that's the 3clc manual, iykyk) β¨
This one does exactly what it says on the tin: it enqueues a command to copy an image object to a buffer object. Image β buffer. That's the whole vibe. π¦
β¨ SYNOPSIS β¨
cl_int clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
cl_mem src_image, cl_mem dst_buffer,
const size_t *src_origin,
const size_t *region,
size_t dst_offset,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event);
πΈ PARAMETERS πΈ
command_queueβ has to be a valid command-queue, no exceptions. And listen: the OpenCL context associated withcommand_queue,src_image, anddst_buffermust all be the same. They have to be in the same friend group, periodt.src_imageβ a valid image object. that's it, that's the requirement πdst_bufferβ a valid buffer object. the destination, the moment, the main character.src_originβ this one defines the (x, y, z) offset in pixels in the 1D, 2D or 3D image, the (x, y) offset and the image index in the 2D image array, or the (x) offset and the image index in the 1D image array. Now the rules, and yes you have to follow them:- if
src_imageis a 2D image object,src_origin[2]must be0. - if
src_imageis a 1D image or 1D image buffer object,src_origin[1]andsrc_origin[2]must be0. - if
src_imageis a 1D image array object,src_origin[2]must be0. - if
src_imageis a 1D image array object,src_origin[1]describes the image index in the 1D image array. - if
src_imageis a 2D image array object,src_origin[2]describes the image index in the 2D image array.
- if
regionβ defines the (width, height, depth) in pixels of the 1D, 2D or 3D rectangle, the (width, height) in pixels of the 2D rectangle and the number of images of a 2D image array, or the (width) in pixels of the 1D rectangle and the number of images of a 1D image array. The rules:- if
src_imageis a 2D image object,region[2]must be1. - if
src_imageis a 1D image or 1D image buffer object,region[1]andregion[2]must be1. - if
src_imageis a 1D image array object,region[2]must be1.
- if
dst_offsetβ the offset where you start copying data intodst_buffer. The size in bytes of the region being copied, calleddst_cb, gets computed like this, and this is giving math class but make it graphics:width * height * depth * bytes/image elementifsrc_imageis a 3D image objectwidth * height * bytes/image elementifsrc_imageis a 2D imagewidth * height * arraysize * bytes/image elementifsrc_imageis a 2D image array objectwidth * bytes/image elementifsrc_imageis a 1D image or 1D image buffer objectwidth * arraysize * bytes/image elementifsrc_imageis a 1D image array object
event_wait_list,num_events_in_wait_listβ these specify the events that need to complete before this particular command can even think about executing. The deets:- if
event_wait_listisNULL, then this command does not wait on any event to complete. - if
event_wait_listisNULL,num_events_in_wait_listmust be0. - if
event_wait_listis notNULL, the list of events pointed to byevent_wait_listmust be valid andnum_events_in_wait_listmust be greater than0. - the events specified in
event_wait_listact as synchronization points. - the context associated with events in
event_wait_listandcommand_queuemust be the same. - the memory associated with
event_wait_listcan be reused or freed after the function returns. so you can let it go, bestie ποΈ
- if
eventβ returns an event object that identifies this particular copy command and can be used to query or queue a wait for this command to complete.eventcan beNULL, 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.clEnqueueBarrierWithWaitList(3clc)can be used instead. And one lil gotcha: if theevent_wait_listand theeventarguments are notNULL, theeventargument should not refer to an element of theevent_wait_listarray. don't do it. π
π₯ ERRORS π₯
clEnqueueCopyImageToBuffer returns CL_SUCCESS if the function is executed successfully (slay π). Otherwise, it returns one of the following errors:
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid command-queue.CL_INVALID_CONTEXTif the context associated withcommand_queue,src_imageanddst_bufferare not the same, or if the context associated withcommand_queueand events inevent_wait_listare not the same.CL_INVALID_MEM_OBJECTifsrc_imageis not a valid image object ordst_bufferis not a valid buffer object, or ifsrc_imageis a 1D image buffer object created fromdst_buffer.CL_INVALID_VALUEif the 1D, 2D, or 3D rectangular region specified bysrc_originandsrc_origin + regionrefers to a region outsidesrc_image, or if the region specified bydst_offsetanddst_offset + dst_cbrefers to a region outsidedst_buffer.CL_INVALID_VALUEif values insrc_originandregiondo not follow the rules described in the argument description forsrc_originandregion.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_MISALIGNED_SUB_BUFFER_OFFSETifdst_bufferis a sub-buffer object and the offset specified when the sub-buffer object is created is not aligned toCL_DEVICE_MEM_BASE_ADDR_ALIGNvalue for the device associated with queue. alignment matters, no cap. πCL_INVALID_IMAGE_SIZEif image dimensions (image width, height, specified or compute row and/or slice pitch) forsrc_imageare not supported by the device associated with queue.CL_INVALID_IMAGE_FORMATif image format (image channel order and data type) forsrc_imageare not supported by the device associated with queue.CL_MEM_OBJECT_ALLOCATION_FAILUREif there is a failure to allocate memory for the data store associated withsrc_imageordst_buffer.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_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.
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
clEnqueueReadBuffer(3clc), clEnqueueWriteBuffer(3clc), clCreateBuffer(3clc), clEnqueueCopyBuffer(3clc), clEnqueueCopyBufferToImage(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 condition: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Materials.
π§ NOTES π§
- OpenCL Specification β page
107, section5.3.4- Copying between Image and Buffer Objects
and that's the whole page, bestie π«Ά go forth and copy your images into your buffers responsibly. this lil masterpiece came from The Khronos Group, dated 01/14/2021, from the 3clc manual. mwah πβ¨
π¦ 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