Repository navigation
opencl: size device-partition property lists by their keys - #566
Merged
Merged
Conversation
The tracer walks the properties of clCreateSubDevices and
clCreateSubDevicesEXT to know how much of the list to record. That walk
switched on each key's value rather than on the key, used the
cl_ext_device_fission constants for the core API's list too, and never
counted the final terminator. So:
- a BY_COUNTS list (core or EXT) was recorded without its terminator;
- a BY_NAMES_EXT list stopped after the key, losing the device names;
- the BY_NAMES_EXT branch never advanced its index, an infinite loop that
only the value-for-key mix-up kept out of reach.
Switch on the key, give each key its own list terminator, core and EXT
spelled with their own constants, take one value for any other key, and
count the terminator.
Checked by running the generated walk on sample lists:
list length before after
EQUALLY(_EXT) 4 3 3 3
BY_AFFINITY_DOMAIN(_EXT) 3 3 3
BY_COUNTS(_EXT) 2,3 5 4 5
BY_NAMES_EXT 0,1 5 2 5
{0}, NULL 1, 0 1, 0 1, 0
Only those two blocks of tracer_opencl.c change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cl_intel_device_partition_by_names adds CL_DEVICE_PARTITION_BY_NAMES_INTEL to the core clCreateSubDevices list: device names ended by CL_PARTITION_BY_NAMES_LIST_END_INTEL (-1). The walk took it as a key with one value, so the names after the first were read as keys. With an odd number of names it stepped over the -1 and the final 0 and kept reading past the array. Traced clCreateSubDevices on the Intel CPU OpenCL runtime, which supports the key. Recorded length, list in a buffer of nonzero guard words: list length before after BY_NAMES_INTEL 0 4 guards 4 BY_NAMES_INTEL 0,1 5 5 5 BY_NAMES_INTEL 2,3,4 6 guards 6 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 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.
Found while reviewing #564. This is a separate fix: it changes
tracer_opencl.c.Bug
To know how much of a property list to record, the tracer walks the
propertiesofclCreateSubDevicesandclCreateSubDevicesEXT(DeviceFissionPropertyListinopencl_model.rb). That walk had three problems:cl_ext_device_fissionconstants for the core API's list too, so it never knew the core keys, norCL_DEVICE_PARTITION_BY_NAMES_INTEL(cl_intel_device_partition_by_names, core list);As a result:
BY_COUNTSlist (core or EXT) was recorded without its terminator;BY_NAMES_EXTorBY_NAMES_INTELlist stopped at the first name equal to 0, losing the names;BY_NAMES_EXTbranch never advanced its index: an infinite loop whenever a value equals0x4052(16466).Fix
Switch on the key. Each key that takes a list of values has its own terminator:
BY_COUNTSandBY_NAMES_INTELfor the core list,BY_COUNTS_EXTandBY_NAMES_EXTfor the EXT list. Any other key takes one value, and the final terminator is counted.A key that takes a list must be in that table: the walk takes any other key as having one value, so it would read past the array. (The first commit missed
BY_NAMES_INTEL, and with an odd number of names, it read past the array.)Checked
Traced a test program with
iprofon Sunspot, Intel CPU OpenCL runtime, which supportsBY_NAMES_INTEL. Each list sits in a buffer of nonzero guard words, so an overlong size shows up in the trace. Recorded length:develEQUALLY4BY_AFFINITY_DOMAINnumaBY_COUNTS2,3BY_NAMES_INTEL0BY_NAMES_INTEL0,1BY_NAMES_INTEL2,3,4EQUALLY_EXT4BY_COUNTS_EXT2,3BY_NAMES_EXT0,1(The runtime rejects
clCreateSubDevicesEXTwithCL_INVALID_OPERATION; the tracer records the list before the call, so these still check the walk.)develdiffers only intracer_opencl.c, and only in those two blocks.tracer_opencl.ccompiles with-Wall -Wextra -Werror(gcc).make checkpasses 9/9.#564 will carry the same walk once this is merged.
🤖 Generated with Claude Code