CLCREATECOMMANDQUEUE(3clc)
π CLCREATECOMMANDQUEUE π
okay bestie, so this one lives in the OpenCL Manual as CLCREATECOMMANDQUEUE(3clc) and it's literally the function that spins up your command-queue. it's giving "let's make a line of stuff for the GPU to do." slay.
β¨ NAME β¨
clCreateCommandQueue β create a command-queue on a specific device. that's it, that's the whole job π
cl_command_queue clCreateCommandQueue(cl_context context,
cl_device_id device,
cl_command_queue_properties properties,
cl_int *errcode_ret);
πΈ PARAMETERS πΈ
contextβ has to be a valid OpenCL context. no random nonsense, please.deviceβ has to be a device associated withcontext. and it can be either one of the devices you listed whencontextgot created withclCreateContext(3clc), or it can have the same device type as the device type you specified when the context was created withclCreateContextFromType(3clc). both paths are valid, pick your fighter π«Άpropertiesβ this is your list of properties for the command-queue, and it's a bit-field, described in the lil' table below. important: only the command-queue properties in that table can be set inpropertiesβ if you put anything else in there, the value you specified inpropertiesis considered not valid. periodt.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLEβ determines whether the commands queued in the command-queue are executed in-order or out-of-order. if set, the commands in the command-queue are executed out-of-order. otherwise, commands are executed in-order. see the note below for more info πCL_QUEUE_PROFILING_ENABLEβ enable or disable profiling of commands in the command-queue. if set, profiling of commands is enabled. otherwise profiling of commands is disabled. seeclGetEventProfilingInfo(3clc)for more info. (iykyk)
errcode_retβ returns an appropriate error code. iferrcode_retisNULL, no error code is returned. it's giving optional, bestie.
π¦ NOTES π¦
OpenCL objects like memory, program and kernel objects are created using a context. operations on those objects are performed using a command-queue. the command-queue can be used to queue a set of operations (we call them commands) in order. having multiple command-queues lets applications queue multiple independent commands without needing synchronization. lowkey important caveat: this should work as long as these objects are not being shared. sharing objects across multiple command-queues means the application has to do the appropriate synchronization itself. this whole thing is described in Appendix A of the specification. the section is titled Out-of-order Execution of Kernels and Memory Object Commands.
The OpenCL functions that are submitted to a command-queue are enqueued in the order the calls are made, but they can be configured to execute in-order or out-of-order. the properties argument in clCreateCommandQueue is how you specify the execution order. π
β In-order vibes
If the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property of a command-queue is not set, the commands enqueued to a command-queue execute in order. for example, if an application calls clEnqueueNDRangeKernel(3clc) to execute kernel A followed by a clEnqueueNDRangeKernel(3clc) to execute kernel B, the application can assume that kernel A finishes first and then kernel B is executed. if the memory objects output by kernel A are inputs to kernel B, then kernel B will see the correct data in the memory objects produced by execution of kernel A. so polite, so orderly π
If the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property of a commandqueue is set, then there is no guarantee that kernel A will finish before kernel B starts execution. π chaos, honestly.
π₯ Out-of-order execution
Applications can configure the commands enqueued to a command-queue to execute out-of-order by setting the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property of the command-queue. this can be specified when the command-queue is created. in out-of-order execution mode there is no guarantee that the enqueued commands will finish execution in the order they were queued. and because there's no guarantee kernels will be executed in order β that is, based on when the clEnqueueNDRangeKernel(3clc) calls are made within a command-queue β it is therefore possible that an earlier clEnqueueNDRangeKernel(3clc) call to execute kernel A (identified by event A) may execute and/or finish later than a clEnqueueNDRangeKernel(3clc) call to execute kernel B, which was called by the application at a later point in time. wild, right? π
To guarantee a specific order of execution of kernels, a wait on a particular event (in this case event A) can be used. that wait for event A can be specified in the event_wait_list argument to clEnqueueNDRangeKernel(3clc) for kernel B. problem solved, bestie. β¨
π Waits and barriers
In addition, a wait for events (clEnqueueMarkerWithWaitList(3clc)) or a barrier (clEnqueueBarrierWithWaitList(3clc)) command can be enqueued to the command-queue.
- the wait for events command ensures that previously enqueued commands identified by the list of events to wait for have finished before the next batch of commands is executed.
- the barrier command ensures that all previously enqueued commands in a command-queue have finished execution before the next batch of commands is executed.
π§ Memory commands, be careful
Similarly, commands to read, write, copy or map memory objects that are enqueued after clEnqueueNDRangeKernel(3clc), clEnqueueTask(3clc) or clEnqueueNativeKernel(3clc) commands are not guaranteed to wait for kernels scheduled for execution to have completed (if the CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE property is set). to ensure correct ordering of commands, the event object returned by clEnqueueNDRangeKernel(3clc), clEnqueueTask or clEnqueueNativeKernel(3clc) can be used to enqueue a wait for event, or a barrier command can be enqueued that must complete before reads or writes to the memory object(s) occur. don't skip this, fr fr π
π ERRORS π
clCreateCommandQueue returns a valid non-zero command-queue and errcode_ret is set to CL_SUCCESS if the command-queue is created successfully. otherwise, it returns a NULL value with one of the following error values returned in errcode_ret:
CL_INVALID_CONTEXTifcontextis not a valid context.CL_INVALID_DEVICEifdeviceis not a valid device or is not associated withcontext.CL_INVALID_VALUEif values specified inpropertiesare not valid.CL_INVALID_QUEUE_PROPERTIESif values specified inpropertiesare valid but are not supported by the device.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 π
clGetCommandQueueInfo(3clc), clReleaseCommandQueue(3clc), clRetainCommandQueue(3clc), clCreateContext(3clc), clCreateContextFromType(3clc), classDiagram(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 condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
π NOTES π
- OpenCL Specification β page 61, section 5.1 - Command Queues
and that's the whole page, bestie π
the Khronos Group wrote this one, it's dated 01/14/2021, and it ships as part of the CLCREATECOMMANDQUEUE(3clc) manual page in the OpenCL Manual. go forth and queue responsibly π«Άβ¨
π¦ 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