Fix command queue creation in PROFANITY_DEBUG builds - #58
Merged
cursor[bot] merged 1 commit intoAug 2, 2026
Merged
Conversation
clCreateCommandQueueWithProperties expects a zero-terminated
cl_queue_properties list of {name, value} pairs, but createQueue passed
&p, the address of a bare cl_command_queue_properties scalar.
In release builds p == 0, so &p happens to read as a valid empty
property list and the call succeeds by accident. With -DPROFANITY_DEBUG,
p == CL_QUEUE_PROFILING_ENABLE (0x2), so the same memory is parsed as
property name 0x2 with no value and no terminator. The call returns NULL
and createQueue throws std::runtime_error("failed to create command
queue") at startup, so no -DPROFANITY_DEBUG build can start on an
OpenCL 2.0 or newer platform.
Pass a proper { CL_QUEUE_PROPERTIES, p, 0 } list instead. The OpenCL 1.2
fallback path is unchanged; clCreateCommandQueue takes a bitfield rather
than a property list.
This was referenced Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Any build with
-DPROFANITY_DEBUGdies immediately at startup:The stock release build is unaffected and runs normally.
Root cause
Dispatcher::Device::createQueuepasses&ptoclCreateCommandQueueWithProperties:clCreateCommandQueueWithPropertiesdoes not take a bitfield. Its third argument is azero-terminated
cl_queue_properties[]list of{property name, value, ...}pairs.&pis the address of a bare scalar, not such a list.With
-DPROFANITY_DEBUG,p == CL_QUEUE_PROFILING_ENABLE(0x2), so the runtime readsthe memory at
&pas property name0x2followed by no value and no terminator. Thelist is malformed, the call returns
NULL, and the next line throwsstd::runtime_error("failed to create command queue").Why the release build is unaffected
In the release path
p == 0, so&ppoints at a single zero word, which reads as avalid empty property list. The call succeeds by accident. That is why this has gone
unnoticed: only the debug path puts a non-zero value in
p, and every debug build hasbeen broken since OpenCL 2.0 headers became the norm.
The OpenCL 1.2 fallback (
clCreateCommandQueue) is correct as written and is untouched,since that function really does take a
cl_command_queue_propertiesbitfield.Fix
Two lines, no other changes.
Verification
Linux / NVIDIA RTX 5090, Fedora 44, gcc 16.1.1, driver 595.71.05, OpenCL 3.0 (CUDA 13.2):
-DPROFANITY_DEBUGbuild (unpatched master): aborts at startup withfailed to create command queue.-DPROFANITY_DEBUGbuild with this patch: starts normally and emits the per-kernelprofiling output the debug path is meant to produce.
macOS (Apple
OpenCL.framework): release build compiles clean with this patch. Notethat Apple's headers do not define
CL_VERSION_2_0, so macOS takes the 1.2 fallback andnever reaches the changed line either way. The changed function was additionally
type-checked against the Khronos OpenCL 3.0 headers with and without
-DPROFANITY_DEBUG; both compile without warnings beyond the pre-existingNULL-to-integer conversion on the line above.