CLENQUEUEREADBUFFER(3clc)
π CLENQUEUEREADBUFFER π
okay bestie, so this is a page from the OpenCL Manual (section 3clc) and it's literally all about getting data OUT of a buffer object and INTO your host memory. no cap. let's get into it π«Ά
β¨ NAME β¨
clEnqueueReadBuffer β enqueues commands to read from a buffer object to host memory. it's giving "bring the data home" energy π β¨
β¨ SYNOPSIS β¨
cl_int clEnqueueReadBuffer(cl_command_queue command_queue,
cl_mem buffer, cl_bool blocking_read,
size_t offset, size_t size, void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
cl_event *event);
look at her. nine arguments. main character energy fr fr π
β¨ PARAMETERS β¨
command_queueβ this is the command-queue where your read command is gonna get queued up. IMPORTANT:command_queueandbufferhave to be created with the same OpenCL context. they're a package deal, no exceptions πbufferβ has to be a valid buffer object. that's it, that's the vibe.blocking_readβ tells us if the read ops are blocking or non-blocking, and bestie this one actually matters:- if
blocking_readisCL_TRUE, i.e. the read command is blocking, thenclEnqueueReadBufferdoes not return until the buffer data has been read and copied into the memory thatptrpoints to. she waits. patiently. π§ - if
blocking_readisCL_FALSE, i.e. the read command is non-blocking, thenclEnqueueReadBufferqueues a non-blocking read command and dips. the contents of the buffer thatptrpoints to cannot be used until the read command has completed. theeventargument returns an event object you can use to query the execution status of the read command. once the read command has completed, the contents of the buffer thatptrpoints to are finally usable by your application. π¦
- if
offsetβ the offset in bytes in the buffer object to read from. where we start, basically.sizeβ the size in bytes of the data being read. how much we're grabbing.ptrβ the pointer to the buffer in host memory where the data is gonna be read into. the landing zone. π¬event_wait_list,num_events_in_wait_listβ these two specify events that need to complete before this particular command can execute. here's the tea:- 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, then 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. so like, don't stress about cleanup timing, she's done with it. π
- if
eventβ returns an event object that identifies this particular read 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. and heads up: if theevent_wait_listand theeventarguments are notNULL, theeventargument should not refer to an element of theevent_wait_listarray. don't do it. π
β¨ NOTES β¨
so there's a specific situation here and it's lowkey important. calling clEnqueueReadBuffer to read a region of the buffer object with the ptr argument value set to host_ptr + offset, where host_ptr is a pointer to the memory region specified when the buffer object being read is created with CL_MEM_USE_HOST_PTR, must meet the following requirements in order to avoid undefined behavior:
- All commands that use this buffer object or a memory object (buffer or image) created from this buffer object have finished execution before the read 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 read command has finished execution.
π¨ bestie these three are not suggestions. undefined behavior is that girl you do NOT want to meet in a dark alley. respect the rules. π¨
β¨ ERRORS β¨
clEnqueueReadBuffer returns CL_SUCCESS if the function is executed successfully. otherwise, she returns one of the following errors:
CL_INVALID_COMMAND_QUEUEifcommand_queueis not a valid 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 buffer object.CL_INVALID_VALUEif the region being read specified by(offset, size)is out of bounds or ifptris aNULLvalue or ifsizeis 0. (yes, zero bytes counts as invalid, sorry π₯²)CL_INVALID_EVENT_WAIT_LISTifevent_wait_listisNULLandnum_events_in_wait_listgreater than 0, orevent_wait_listis notNULLandnum_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 with queue. π§CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LISTif 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_FAILUREif there is a failure to allocate memory for data store associated withbuffer.CL_INVALID_OPERATIONifclEnqueueReadBufferis called on buffer which has been created withCL_MEM_HOST_WRITE_ONLYorCL_MEM_HOST_NO_ACCESS. (like, you literally said "don't read this" and then tried to read it. rude. π)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 β¨
clEnqueueCopyBuffer(3clc), clEnqueueWriteBuffer(3clc), clEnqueueWriteBufferRect(3clc), clEnqueueReadBufferRect(3clc)
the whole friend group fr fr π«
β¨ AUTHORS β¨
The Khronos Group π
β¨ COPYRIGHT β¨
Copyright Β© 2007-2010 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 72, section 5.2.2 - Reading, Writing, Copying Buffer Objects π
and that's the whole page bestie!! this lil masterpiece is brought to you by The Khronos Group, dated 01/14/2021, and it lives under the name CLENQUEUEREADBUFFER(3clc). go read some buffers, slay, and remember: check your blocking_read flag before you touch ptr. 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