CLENQUEUEWRITEBUFFER(3clc)
π clEnqueueWriteBufferRect β the OpenCL manual page, bestie edition π
okay so you've stumbled into clEnqueueWriteBufferRect(3clc), which lives in the OpenCL Manual, and honestly? she's a whole vibe. this is the one that lets you yeet a 2D or 3D rectangular region out of your host memory and into a buffer object. no cap. let's get into it π«Ά
β¨ NAME β¨
clEnqueueWriteBufferRect β enqueue commands to write a 2D or 3D rectangular region to a buffer object from host memory. π¦
β¨ SYNOPSIS β¨
cl_int clEnqueueWriteBufferRect(cl_command_queue command_queue,
cl_mem buffer, cl_bool blocking_write,
const size_t * buffer_origin,
const size_t * host_origin,
const size_t *region,
size_t buffer_row_pitch,
size_t buffer_slice_pitch,
size_t host_row_pitch,
size_t host_slice_pitch, void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event);
look at her. fourteen arguments. she's high maintenance and she knows it π
β¨ PARAMETERS β¨
command_queueβ the command-queue where this write command is gonna get queued up. important:command_queueandbufferhave to be created with the same OpenCL context, or it's not gonna fly, bestie.bufferβ has to point at a valid buffer object. that's it, that's the rule. πblocking_writeβ the drama switch. does the write block or not:- if
blocking_writeisCL_TRUE, the OpenCL implementation copies the data thatptrpoints to and enqueues the write operation in the command-queue. the memory thatptrpoints to can be reused by the application once theclEnqueueWriteBufferRectcall returns. so like, you're free π - if
blocking_writeisCL_FALSE, the OpenCL implementation will useptrto do a nonblocking write. because the write is non-blocking, the implementation can just return immediately, no thoughts. but heads up: the memoryptrpoints to cannot be reused by the application after the call returns. theeventargument gives you back an event object you can use to query the execution status of the write command. once the write command has completed, then the memoryptrpoints to can be reused. patience, queen. π§
- if
buffer_originβ the(x, y, z)offset in the memory region associated withbuffer. for a 2D rectangle region, thezvalue given bybuffer_origin[2]should be 0. the offset in bytes is computed as:
buffer_origin[2] * buffer_slice_pitch + buffer_origin[1] * buffer_row_pitch + buffer_origin[0]
host_originβ the(x, y, z)offset in the memory region pointed to byptr. for a 2D rectangle region, thezvalue given byhost_origin[2]should be 0. the offset in bytes is computed as:
host_origin[2] * host_slice_pitch + host_origin[1] * host_row_pitch + host_origin[0]
regionβ the(width, height, depth)in bytes of the 2D or 3D rectangle being read or written. for a 2D rectangle copy, the depth value given byregion[2]should be 1. βbuffer_row_pitchβ the length of each row in bytes to be used for the memory region associated withbuffer. ifbuffer_row_pitchis0, thenbuffer_row_pitchis computed asregion[0]. she's self-sufficient like that.buffer_slice_pitchβ the length of each 2D slice in bytes to be used for the memory region associated withbuffer. ifbuffer_slice_pitchis0, thenbuffer_slice_pitchis computed asregion[1] * buffer_row_pitch.host_row_pitchβ the length of each row in bytes to be used for the memory region pointed to byptr. ifhost_row_pitchis0, thenhost_row_pitchis computed asregion[0].host_slice_pitchβ the length of each 2D slice in bytes to be used for the memory region pointed to byptr. ifhost_slice_pitchis0, thenhost_slice_pitchis computed asregion[1] * host_row_pitch.ptrβ the pointer to buffer in host memory where data is to be written from. π₯event_wait_list,num_events_in_wait_listβ these two specify events that need to complete before this particular command can even be executed. the deets:- if
event_wait_listisNULL, then this particular command does not wait on any event to complete. - if
event_wait_listisNULL, thennum_events_in_wait_listmust be 0. - if
event_wait_listis notNULL, the list of events pointed to byevent_wait_listmust be valid, andnum_events_in_wait_listmust be greater than 0. - 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. π
- if
eventβ returns an event object that identifies this particular write command, and can be used to query or queue a wait for this particular 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. so like, your loss, but valid. π
β οΈ NOTES β οΈ
okay this part is the serious one, don't skip it, bestie. π
calling clEnqueueWriteBufferRect to update the latest bits in a region of the buffer object, with the ptr argument value set to host_ptr and host_origin, buffer_origin values the same β where host_ptr is a pointer to the memory region specified when the buffer object being written is created with CL_MEM_USE_HOST_PTR β must meet the following requirements in order to avoid undefined behavior:
- the host memory region given by
(buffer_origin region)contains the latest bits when the enqueued write command begins execution. - the buffer object, or memory objects created from this buffer object, are not mapped.
- the buffer object, or memory objects created from this buffer object, are not used by any command-queue until the write command has finished execution.
undefined behavior is not a cute look. read those three bullets again. π
π ERRORS π
clEnqueueWriteBufferRect returns CL_SUCCESS if the function is executed successfully. otherwise, she returns one of the following errors, and every single one is a different flavor of "ma'am":
CL_INVALID_COMMAND_QUEUEβ ifcommand_queueis not a valid command-queue.CL_INVALID_CONTEXTβ if 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_OBJECTβ ifbufferis not a valid buffer object.CL_INVALID_VALUEβ if the region being read specified by(buffer_origin, region, buffer_row_pitch, buffer_slice_pitch)is out of bounds.CL_INVALID_VALUEβ ifptris aNULLvalue.CL_INVALID_VALUEβ if anyregionarray element is0.CL_INVALID_VALUEβ ifbuffer_row_pitchis not0and is less thanregion[0].CL_INVALID_VALUEβ ifhost_row_pitchis not0and is less thanregion[0].CL_INVALID_VALUEβ ifbuffer_slice_pitchis not0and is less thanregion[1] * buffer_row_pitchand not a multiple ofbuffer_row_pitch.CL_INVALID_VALUEβ ifhost_slice_pitchis not0and is less thanregion[1] * host_row_pitchand not a multiple ofhost_row_pitch.CL_INVALID_EVENT_WAIT_LISTβ ifevent_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_OFFSETβ ifbufferis 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 withqueue.CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LISTβ if the read and write operations are blocking and the execution status of any of the events inevent_wait_listis a negative integer value.CL_MEM_OBJECT_ALLOCATION_FAILUREβ if there is a failure to allocate memory for data store associated withbuffer.CL_INVALID_OPERATIONβ ifclEnqueueWriteBufferRectis called onbufferwhich has been created withCL_MEM_HOST_READ_ONLYorCL_MEM_HOST_NO_ACCESS.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.
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
clEnqueueCopyBuffer(3clc)clEnqueueCopyBufferRect(3clc)clEnqueueWriteBuffer(3clc)clEnqueueReadBufferRect(3clc)clEnqueueReadBuffer(3clc)
the whole friend group. iconic. π₯
π 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 condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
π NOTES π
- OpenCL Specification page 75, section 5.2.2 - Reading, Writing and Copying Buffer Objects
that's the whole page, bestie, you ate it. π
β¨ this came to you from The Khronos Group, dated 01/14/2021, and it's CLENQUEUEWRITEBUFFER(3clc) β go forth and write some rectangles, and please, for the love of everything, keep command_queue and buffer in the same context. 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