Skip to content

Fix command queue creation in PROFANITY_DEBUG builds - #58

Merged
cursor[bot] merged 1 commit into
1inch:masterfrom
wock9000:fix-debug-build-command-queue-properties
Aug 2, 2026
Merged

Fix command queue creation in PROFANITY_DEBUG builds#58
cursor[bot] merged 1 commit into
1inch:masterfrom
wock9000:fix-debug-build-command-queue-properties

Conversation

@wock9000

Copy link
Copy Markdown

Symptom

Any build with -DPROFANITY_DEBUG dies immediately at startup:

failed to create command queue

The stock release build is unaffected and runs normally.

Root cause

Dispatcher::Device::createQueue passes &p to clCreateCommandQueueWithProperties:

#ifdef PROFANITY_DEBUG
	cl_command_queue_properties p = CL_QUEUE_PROFILING_ENABLE;
#else
	cl_command_queue_properties p = NULL;
#endif

#ifdef CL_VERSION_2_0
	const cl_command_queue ret = clCreateCommandQueueWithProperties(clContext, clDeviceId, &p, NULL);

clCreateCommandQueueWithProperties does not take a bitfield. Its third argument is a
zero-terminated cl_queue_properties[] list of {property name, value, ...} pairs.
&p is the address of a bare scalar, not such a list.

With -DPROFANITY_DEBUG, p == CL_QUEUE_PROFILING_ENABLE (0x2), so the runtime reads
the memory at &p as property name 0x2 followed by no value and no terminator. The
list is malformed, the call returns NULL, and the next line throws
std::runtime_error("failed to create command queue").

Why the release build is unaffected

In the release path p == 0, so &p points at a single zero word, which reads as a
valid 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 has
been 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_properties bitfield.

Fix

 #ifdef CL_VERSION_2_0
-	const cl_command_queue ret = clCreateCommandQueueWithProperties(clContext, clDeviceId, &p, NULL);
+	const cl_queue_properties props[] = { CL_QUEUE_PROPERTIES, p, 0 };
+	const cl_command_queue ret = clCreateCommandQueueWithProperties(clContext, clDeviceId, props, NULL);
 #else

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):

  • Stock release build (unpatched master): compiles and runs clean at 2.089 GH/s.
  • Stock -DPROFANITY_DEBUG build (unpatched master): aborts at startup with
    failed to create command queue.
  • -DPROFANITY_DEBUG build with this patch: starts normally and emits the per-kernel
    profiling output the debug path is meant to produce.
  • Release build with this patch: unchanged, no regression.

macOS (Apple OpenCL.framework): release build compiles clean with this patch. Note
that Apple's headers do not define CL_VERSION_2_0, so macOS takes the 1.2 fallback and
never 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-existing
NULL-to-integer conversion on the line above.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant