8000 opencl: map sub-devices created with a NULL count in the interval plugin by TApplencourt · Pull Request #573 · argonne-lcf/THAPI · GitHub
[go: up one dir, main page]

Skip to content

opencl: map sub-devices created with a NULL count in the interval plugin - #573

Merged
TApplencourt merged 6 commits into
develfrom
fix-cl-sub-devices-count
Nov 12, 2026
Merged

TApplencourt merged 6 commits into
develfrom
fix-cl-sub-devices-count

Conversation

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

Fixes #572.

Bug

The interval plugin maps sub-devices to their root device by looping over the count clCreateSubDevices returns (num_devices_ret_val). When the application passes num_devices_ret = NULL, which is legal and common when out_devices is big enough, the tracer records 0. The loop then runs zero times, the sub-devices are never mapped, and the device_to_root_device lookup at queue creation misses. A command on a sub-device is reported as did = <sub-device>, sdid = 0, as if it were a root device. Same for clCreateSubDevicesEXT (num_devices).

Fix

The tracer records what the application passed, so the fix is in the interval plugin (btx_clinterval_callbacks.cpp), not in the tracer:

  • A successful call creates at least one sub-device, so a count of 0 on success means the application passed NULL.
  • In that case the plugin maps every recorded entry of out_devices. The tracer records that array with the requested capacity (num_devices), so the plugin cannot know where the sub-devices end. Entries past them are whatever the application left in its array.
  • btx_clmatching_model.yaml passes _out_devices_vals_length to both exit callbacks for this.

When the count is known, nothing changes.

Checked

  • Sunspot, Intel CPU OpenCL runtime, the OpenCL: sub-devices are not mapped to their root device when num_devices_ret is NULL #572 reproducer: with NULL counts, a write on a sub-device is now reported as did = <root>, sdid = <sub-device>, the same as when the application passes &n.
  • New integration test integration_tests/backend_opencl.bats: the program creates sub-devices with num_devices_ret = NULL, writes a buffer on one of them, and prints that root device and sub-device as the extended tally names them. The test runs it once under iprof -e and greps that line in the analysis. It fails without the fix (the tally reports the sub-device as the root device) and skips if the device can't be partitioned. The program builds against THAPI's own OpenCL headers and libOpenCL.so.1, so the CI (PoCL) needs no new package.
  • OpenCL make check passes; shfmt and clang-format-18 are clean on the changed files.

🤖 Generated with Claude Code

@TApplencourt
TApplencourt force-pushed the fix-cl-sub-devices-count branch 2 times, most recently from 03ddde3 to 6cc9c7a Compare November 12, 2026 22:57
The interval plugin maps sub-devices to their root device by looping over
the count clCreateSubDevices(EXT) returns. When the application passes NULL
for that count, the tracer records 0, so the sub-devices were never mapped
and a command on a sub-device was reported as running on a root device
(did = <sub-device>, sdid = 0).

The tracer records what the application did, so the fix is in the interval
plugin: a successful call creates at least one sub-device, so a count of 0
means NULL. The plugin then maps every recorded entry of out_devices (the
requested capacity), as it cannot know where the sub-devices end.

New integration test backend_opencl.bats: create sub-devices with
num_devices_ret = NULL, write a buffer on the first one, and check that
iprof -e reports it with a Subdevice pointer. It fails before this change,
and skips when the device cannot be partitioned.

Fixes #572

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TApplencourt
TApplencourt force-pushed the fix-cl-sub-devices-count branch from 6cc9c7a to d0b5284 Compare November 12, 2026 23:11
TApplencourt and others added 4 commits November 12, 2026 23:15
Compile in the test, write the iprof analysis to a file and grep it, as
backend_mpi.bats does. Drop the skip: CI (PoCL) partitions its device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…artitioned

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vices

The program prints its root device and sub-device as the extended tally
names them; the test greps that exact line in the analysis of the same run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iprof returns the program exit code, so one run gives both the skip
status and the devices the program printed. Name the sub-device the
program uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TApplencourt TApplencourt changed the title opencl: record the sub-device count when num_devices_ret is NULL opencl: map sub-devices created with a NULL count in the interval plugin Nov 12, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TApplencourt
TApplencourt merged commit 251a80d into devel Nov 12, 2026
27 checks passed
@TApplencourt
TApplencourt deleted the fix-cl-sub-devices-count branch November 12, 2026 23:51
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.

OpenCL: sub-devices are not mapped to their root device when num_devices_ret is NULL

1 participant

0