Skip to content

[xpupti] Support more than 1 device in ptiMetricsScopeConfigure - #1479

Open
aostrowski-hbn wants to merge 3 commits into
pytorch:mainfrom
aostrowski-hbn:pytorchdgq-8150-multi-device-scope
Open

[xpupti] Support more than 1 device in ptiMetricsScopeConfigure#1479
aostrowski-hbn wants to merge 3 commits into
pytorch:mainfrom
aostrowski-hbn:pytorchdgq-8150-multi-device-scope

Conversation

@aostrowski-hbn

Copy link
Copy Markdown
Contributor

Enables the XPU Scope Profiler to collect hardware metrics on more than one XPU. Previously enableScopeProfiler hardcoded device_count=1 in the ptiMetricsScopeConfigure call, so metrics were only ever collected on a single card even on multi-GPU hosts.

What changed

  • Default (no device list) → PTI auto-detect (devices=nullptr, count=0): profiles all available devices.
  • New Kineto config key XPUPTI_PROFILER_DEVICES=0,2,3 selects an explicit device subset via a new selectDeviceHandles helper (C++20 std::span + std::ranges gather with bounds validation).
  • Version-guarded by PTI_VERSION_AT_LEAST(0, 18): multi-device support in ptiMetricsScopeConfigure landed in PTI 0.18. On older PTI, single-device behavior is preserved and a request for >1 device is rejected with a clear error.

Device attribution needs no change: each scope record is already correlated to its kernel activity (and thus device/resource) via _kernel_id.

Testing

Verified on a 16-tile Intel Data Center GPU Max (PVC) host built against PTI 0.18:

  • Host-only gtests (XpuptiScopeProfilerConfigTest): 8/8 pass — config-key parsing + selectDeviceHandles bounds validation.
  • Real-HW gtests (XpuptiScopeProfilerTest): 3/3 pass, including a new PerKernelScopeExplicitDevice0 exercising the explicit-subset path.
  • Device-count evidence from PTI's own logs: auto-detect initializes 16 per-device metrics handlers vs 1 for an explicit single device — confirming multi-device configure actually engages all cards.

@meta-cla meta-cla Bot added the cla signed label Jul 10, 2026
@aostrowski-hbn

Copy link
Copy Markdown
Contributor Author

@pytorchbot label ciflow/xpu

@pytorch-bot

pytorch-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

The ciflow label(s) ciflow/xpu will be added, but CI won't be triggered until the workflows are approved (scroll to the bottom of this page).

Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot

pytorch-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/xpu

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

Empty list means all devices (PTI auto-detect); a comma-separated list
selects an explicit device-index subset, parsed with a C++20
views::filter|transform pipeline. PYTORCHDGQ-8150.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aostrowski-hbn
aostrowski-hbn force-pushed the pytorchdgq-8150-multi-device-scope branch from 7ee6615 to 8f18fc8 Compare July 10, 2026 15:34
aostrowski-hbn and others added 2 commits July 10, 2026 17:41
Remove the hardcoded device_count=1 in enableScopeProfiler. On PTI >= 0.18
(PTI-363) default to auto-detect (all devices) and honor an explicit
XPUPTI_PROFILER_DEVICES subset; on older PTI keep single-device behavior
and reject a >1-device request with a clear error.

Add selectDeviceHandles(std::span<const pti_device_handle_t>,
std::span<const int>): a C++20 ranges gather (find_if bounds check +
transform) mapping requested indices to device handles. Host-only gtests
cover the config key and the helper. PYTORCHDGQ-8150.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add PerKernelScopeExplicitDevice0 driving the selectDeviceHandles ->
ptiMetricsScopeConfigure(handles,count) branch on real hardware;
parameterize RunTest with an optional XPUPTI_PROFILER_DEVICES value.
PYTORCHDGQ-8150.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aostrowski-hbn
aostrowski-hbn force-pushed the pytorchdgq-8150-multi-device-scope branch from 8f18fc8 to f2275e5 Compare July 10, 2026 15:48

#if PTI_VERSION_AT_LEAST(0, 18)
if (requestedDevices.empty()) {
// Default: profile every available device (PTI auto-detect mode).

@Rogersyp Rogersyp Jul 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was inaccurate. When requested devices is 0, it will profile whichever devices the workload actually uses.

Note: you may also want to update the PR body.

xpuptiProfilerMaxScopes_);
xpuptiProfilerMaxScopes_,
xpuptiProfilerDevices_.empty()
? std::string("all")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"auto" may be more accurate than "all" here - For example, on a host where the workload only touches 4 of 16 cards, only 4 get profiled, not "all."

@Rogersyp

Copy link
Copy Markdown

One comment to the Testing description: "Auto-detect initializes 16 per-device metrics handlers" is true because the 16-tile PVC test workload dispatched to all 16 tiles — not because auto-detect unconditionally profiles all devices.

@Rogersyp

Copy link
Copy Markdown

Nit: The PTI implementation validates uniformity for any multi-device configure:

if (candidate_devices.size() > 1) {
  result = ValidateDevicesUniform(candidate_devices, all_devices);
  ...
}

So on a mixed-GPU host, both explicit multi-device selection and auto-detect (if the workload touches >1 non-uniform device) will fail inside ptiMetricsScopeConfigure — surfaced through XPUPTI_CALL as a runtime error. The kineto side doesn't (and probably shouldn't) pre-validate this, but a one-line note in the comment or config-key docs ("all selected devices must be the same model") would save users a confusing failure.

TEST_F(XpuptiScopeProfilerConfigTest, DevicesParsedList) {
KN::Config cfg;
EXPECT_TRUE(cfg.parse("XPUPTI_PROFILER_METRICS = metric1"));
EXPECT_TRUE(cfg.parse("XPUPTI_PROFILER_DEVICES = 0, 2, 3"));

@Rogersyp Rogersyp Jul 16, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would be nice to add a test for testing empty "tokens", for example:
EXPECT_TRUE(cfg.parse("XPUPTI_PROFILER_DEVICES = 0, ,2,"));

Trailing comma + doubled comma: empty tokens must be skipped, not parsed as index 0 or rejected as invalid integers.

Additionally, what if there are duplicated indices: XPUPTI_PROFILER_DEVICES=0,0,2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants