8000 opencl: size device-partition property lists by their keys by TApplencourt · Pull Request #566 · argonne-lcf/THAPI · GitHub
[go: up one dir, main page]

Skip to content
{"props":{"contextRegion":{"crumbs":[{"crumb_type":"organization","label":"argonne-lcf","is_root":false,"href":"/argonne-lcf"},{"crumb_type":"repository","label":"THAPI","is_root":false,"href":"/argonne-lcf/THAPI"}],"localNavigation":[{"id":"code","icon":"code","label":"Code","href":"/argonne-lcf/THAPI","selectedLinks":["repo_source","repo_downloads","repo_commits","repo_releases","repo_tags","repo_branches","repo_packages","repo_deployments","repo_attestations"],"popoverTarget":false,"commandId":"repositories:go-to-code","reactNav":{"appTarget":"code-view","anchor":"code-view-repo-link"},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"issues","icon":"issue-opened","label":"Issues","href":"/argonne-lcf/THAPI/issues","selectedLinks":["repo_issues","repo_labels","repo_milestones"],"count":41,"popoverTarget":false,"commandId":"repositories:go-to-issues","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"pull-requests","icon":"git-pull-request","label":"Pull requests","href":"/argonne-lcf/THAPI/pulls","selectedLinks":["repo_pulls","checks"],"count":10,"popoverTarget":false,"commandId":"repositories:go-to-pull-requests","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"actions","icon":"play","label":"Actions","href":"/argonne-lcf/THAPI/actions","selectedLinks":["repo_actions"],"popoverTarget":false,"commandId":"repositories:go-to-actions","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"projects","icon":"table","label":"Projects","href":"/argonne-lcf/THAPI/projects","selectedLinks":["repo_projects","new_repo_project","repo_project"],"popoverTarget":false,"commandId":"repositories:go-to-projects","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"security-and-quality","icon":"shield","label":"Security and quality","href":"/argonne-lcf/THAPI/security","selectedLinks":["security","overview","alerts","policy","token_scanning","code_scanning"],"count":0,"popoverTarget":false,"commandId":"repositories:go-to-security","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"insights","icon":"graph","label":"Insights","href":"/argonne-lcf/THAPI/insights","selectedLinks":["repo_graphs","repo_contributors","dependency_graph","dependabot_updates","pulse","people","community"],"popoverTarget":false,"commandId":"repositories:go-to-insights","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}}],"localNavigationUpdateChannel":null,"selectedLink":"repo_pulls"},"owner":null,"headerLogo":{"href":"/","aria-label":"Homepage "},"notifications":{"indicatorMode":"disabled","websocketChannel":null,"fetchIndicatorSrc":"/notifications/indicator","fetchIndicatorEnabled":false},"issues":{"href":"/issues"},"pulls":{"href":"/pulls"},"contributedRepos":{"href":"/repos"},"copilot":{"show":false,"showAgentsButton":false,"showRelaunchAnnouncement":false,"licenseGrantNudge":null,"copilotChatUrl":null,"copilotApiUrl":"https://api.githubcopilot.com"},"search":{"show":true,"showCommandPalette":false,"isSearchPage":false,"isJumpToSearch":false,"searchContext":{"scope":"repo:argonne-lcf/THAPI","current_repo_name":"THAPI","current_repo_nwo":"argonne-lcf/THAPI","current_repo_org":"argonne-lcf","user_id":"argonne-lcf"}},"commandPalette":null,"enterpriseBar":{"show":false},"globalTransactionalMessage":[],"ipmNudgeDelivery":null,"payloadsUrl":"/_global-navigation/payloads.json?can_toggle_site_admin_and_employee_status=0\u0026is_admin_mode_on=0\u0026is_ui_opted_out=0\u0026show_ui_opt_out=0\u0026v=9","contextRegionUrl":null}}

opencl: size device-partition property lists by their keys - #566

Merged
TApplencourt merged 2 commits into
develfrom
fix-device-partition-size
Nov 9, 2026
Merged

TApplencourt merged 2 commits into
develfrom
fix-device-partition-size

Conversation

@TApplencourt
@TApplencourt TApplencourt commented Nov 9, 2026 •
Copy link
Copy Markdown
Collaborator

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 properties of clCreateSubDevices and clCreateSubDevicesEXT (DeviceFissionPropertyList in opencl_model.rb). That walk had three problems:

  • it switched on each key's value instead of on the key;
  • it used the cl_ext_device_fission constants for the core API's list too, so it never knew the core keys, nor CL_DEVICE_PARTITION_BY_NAMES_INTEL (cl_intel_device_partition_by_names, core list);
  • it never counted the final terminator.

As a result:

  • a BY_COUNTS list (core or EXT) was recorded without its terminator;
  • a BY_NAMES_EXT or BY_NAMES_INTEL list stopped at the first name equal to 0, losing the names;
  • the BY_NAMES_EXT branch never advanced its index: an infinite loop whenever a value equals 0x4052 (16466).

Fix

Switch on the key. Each key that takes a list of values has its own terminator: BY_COUNTS and BY_NAMES_INTEL for the core list, BY_COUNTS_EXT and BY_NAMES_EXT for 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 iprof on Sunspot, Intel CPU OpenCL runtime, which supports BY_NAMES_INTEL. Each list sits in a buffer of nonzero guard words, so an overlong size shows up in the trace. Recorded length:

list length devel this PR
EQUALLY 4 3 3 3
BY_AFFINITY_DOMAIN numa 3 3 3
BY_COUNTS 2,3 5 4 5
BY_NAMES_INTEL 0 4 2 4
BY_NAMES_INTEL 0,1 5 2 5
BY_NAMES_INTEL 2,3,4 6 6 6
EQUALLY_EXT 4 3 3 3
BY_COUNTS_EXT 2,3 5 4 5
BY_NAMES_EXT 0,1 5 2 5

(The runtime rejects clCreateSubDevicesEXT with CL_INVALID_OPERATION; the tracer records the list before the call, so these still check the walk.)

  • The generated-files comparison against devel differs only in tracer_opencl.c, and only in those two blocks.
  • tracer_opencl.c compiles with -Wall -Wextra -Werror (gcc).
  • OpenCL make check passes 9/9.

#564 will carry the same walk once this is merged.

🤖 Generated with Claude Code

TApplencourt and others added 2 commits November 9, 2026 21:26
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>
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

0