Skip to content

[RFC] Migrate torch-xpu-ops DeviceProperties.h to XPUContext.h #5245

Open

Description

@Stonepia

TL; DR

Following PyTorch PR #195146, migrate torch-xpu-ops to the APIs in ATen/xpu/XPUContext.h and remove src/comm/DeviceProperties.h.

PR Stage 1: Use upstream XPU device-property APIs

This is the direct 1-to-1 mapping, just API change, no calculation or anything to change. Possibly just one PR is enough.

PR Stage 2: Remove DeviceProperties.h while preserving launch calculations

This PR would be a code logic change because there are no 1-to-1 mapping. See the following for details. Possibly 3 PRs.

API migration and affected files

All replacement APIs below belong to at::xpu. Preserve the caller's device argument.

PR Stage 1: Equivalent API replacements

Existing API or expression Change Consumer files
syclMaxWorkGroupSize (3 overloads) Use getKernelMaxWorkGroupSize 46
syclDeviceMaxWorkGroupSize Use getDeviceMaxWorkGroupSize 9
syclMaxSubGroupSize Use getDeviceMaxSubGroupSize 14
syclMinSubGroupSize Use getDeviceMinSubGroupSize 3
syclMaxWorkItemsPerTile Use getDeviceMaxWorkItems 20
syclLocalMemSize Use getDeviceLocalMemSize 6
syclGpuEUCountPerSubslice Use getDeviceEUCountPerXeCore, except when folded into the quotient below 3
syclGpuEuCount() * syclGpuHWThreadsPerEU() Use getDeviceHWThreads() 6
syclGpuEuCount() / syclGpuEUCountPerSubslice() Use getDeviceXeCoreCount() 1

PR Stage 2: Proposed Changes

In the expressions below, props means at::xpu::getDeviceProperties(device). All upstream comparisons refer to the surveyed XPUContext.h.

A. Upstream APIs exist, but their calculations differ.

A rename would change launch sizes or scheduling. PR 2 preserves the old values explicitly.

Old helper Difference in upstream API Change in PR 2 Files
syclMaxWorkItemsPerSubSlice Old: maximum subgroup size times EUs per Xe Core. getDeviceMaxWorkItemsPerXeCore additionally multiplies by hardware threads per EU, so it represents resident capacity. getDeviceMaxWorkGroupSize is a separate launch limit and also need not equal the old value. Replace calls with getDeviceMaxSubGroupSize(device) * getDeviceEUCountPerXeCore(device). Preserve existing multipliers, including BatchNorm's * 2 launch bound and Loops' * 4 latency threshold. 18
syclMaxDSSNum Old numerator: max_compute_units. getDeviceXeCoreCount uses gpu_eu_count. These are separately queried properties; equality is not guaranteed by the implementation. Replace calls with props->max_compute_units / getDeviceEUCountPerXeCore(device). 2

B. No dedicated upstream equivalent exists.

The needed fields or component APIs already exist, so PR 2 does not add getters to PyTorch.

Old helper What is missing Change in PR 2 Files
Remaining syclGpuHWThreadsPerEU uses A per-EU thread getter; getDeviceHWThreads returns the total for the device. Read props->gpu_hw_threads_per_eu in GroupNorm, Transpose, and Distance; retain surrounding calculations. 3
syclMaxWorkItemsPerEU A per-EU work-item capacity getter. Use getDeviceMaxSubGroupSize(device) * props->gpu_hw_threads_per_eu in BatchNorm. 1
syclHasFloat64 A dedicated FP64 getter in XPUContext.h; the property already exists. Read props->has_fp64 in UnaryGamma. 1
syclPrefVectorWidth An upstream equivalent for the old fixed 16-byte vector-width policy. This helper does not query device properties. Fold the calculation into preferred_vector_width in MemoryAccess.h: return 16, 8, 4, or 2 for element sizes 1, 2, 4, or 8; retain fallback 1. 1

C. Remove definitions and header dependencies once consumers are migrated.

Item Change in PR 2 Files
syclMaxComputeUnitSize Remove definition and update the one remaining comment reference; its max_compute_units field remains in the preserved DSS calculation. 1 comment consumer
syclGpuEuCount and helpers migrated in PR 1 Remove definitions with the header; their consumer migrations are already complete. 0 remaining consumers
syclGpuEuSimdWidth, syclMaxNumSubGroups, syclGlobalMemSize, syclNativeVectorWidth Remove unused definitions; no replacement is needed. 0 consumers
Direct DeviceProperties.h includes Remove or replace with explicit dependencies, including in SYCLContext.h. Preserve required syclext/syclexp aliases and resolve dependencies on using namespace xpu::sycl. 15 include sites
src/comm/DeviceProperties.h Delete the file. 1 deletion

Activity

  1. added this to the PT2.15 milestone on Sep 8, 2026
  2. self-assigned this
    on Sep 8, 2026
  3. added theissue type on Sep 8, 2026
  4. modified the milestones: PT2.15, PT2.16 on Sep 16, 2026
  5. Stonepia commented on Sep 16, 2026

    @Stonepia
    ContributorAuthor

    Move to PT2.16

  6. added a commit that references this issue on Oct 21, 2026
  7. added
    module: rfcRFC / design proposal / tracking-only feature request
    test: utUnit-test failure surface
    on Nov 10, 2026
  8. daisyden commented on Nov 10, 2026

    @daisyden
    Contributor
    label-issue: #5245

    Root cause: Not a defect; refactor RFC to replace src/comm/DeviceProperties.h helpers (11 including files in src/) with at::xpu APIs from XPUContext.h per pytorch/pytorch#195146.

    axis value reason
    type Task Native Type Task (human-set, preserved).
    test test: ut No e2e/oob signal; default surface (no test failure involved).
    module module: rfc Title [RFC]; staged design proposal for API migration of src/comm/DeviceProperties.h.
    priority Medium Native Priority Medium (human-set, preserved).

    Applied to this issue. Generated by a local label-issue run.

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

Metadata

Metadata

Assignees

Labels

module: rfcRFC / design proposal / tracking-only feature requesttest: utUnit-test failure surface

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions