Skip to content

fix(backends): make capability gating sound on ROCm, add arch gate - #1683

Open
nilapate wants to merge 1 commit into
linkedin:mainfrom
AMD-Ecosystem:nilapate/rocm-capability-dispatch
Open

nilapate wants to merge 1 commit into
linkedin:mainfrom
AMD-Ecosystem:nilapate/rocm-capability-dispatch

Conversation

@nilapate

Copy link
Copy Markdown

Summary

On ROCm, torch.cuda.get_device_capability() returns the AMD GPU ISA version (gfx942 → (9, 4), gfx90a → (9, 0), same as an H100), so Capability(min_cc=...) can pass on AMD hardware. On an MI300A, Capability(min_cc=(9, 0)).is_satisfied() is True on main.

  • min_cc / max_cc are now CUDA-only (unsatisfied on a ROCm build).
  • New archs gate on the existing infer_device_arch(); exclusive with min_cc / max_cc.
  • The available_impls memo key includes the device arch.
  • Tests that simulate NVIDIA devices pin a non-ROCm build.

Same guard as PyTorch (IS_SM90, torch/testing/_internal/common_cuda.py) and xformers.

Testing Done

  • Hardware Type: AMD Instinct MI300A (gfx942)
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

make test and make test-convergence were not run in full: no kernel or op code changed.

main   : pytest test/backends -> 71 passed, 16 skipped
branch : pytest test/backends -> 86 passed, 16 skipped
branch : pytest test/ops/test_layer_norm.py test/ops/test_rms_norm.py -> 106 passed

`Capability` gated impls on `torch.cuda.get_device_capability()`. On a
ROCm build that is not a CUDA compute capability — it is the AMD GPU ISA
version, derived positionally from the gfx target (clr
`hipamd/src/hip_device.cpp`: `major = isa.versionMajor()`, and
`gcnArch = major*100 + minor*10 + stepping`, so 9*100+4*10+2 = gfx942).

Those values collide with NVIDIA sm numbers. On an MI300A:

    gcnArchName           = gfx942:sramecc+:xnack-
    get_device_capability = (9, 4)
    Capability(min_cc=(9,0)).is_satisfied() -> True   # a Hopper gate

21 AMD targets report a tuple identical to an NVIDIA generation (8 report
sm_90, 7 sm_103, 2 sm_120). Nothing is mis-dispatched today only because
every cc-gated impl also needs an NVIDIA-only module that fails to import
on AMD, but the gate is unsound and blocks registering any rocm-* impl.

- cc gates are CUDA-only: unsatisfied on a ROCm build, with a reason.
  Same guard as PyTorch's `IS_SM90` (testing/_internal/common_cuda.py)
  and xformers `AttentionOpBase` (v0.0.28.post3 ops/fmha/common.py:371).
- Add `archs`, gating on the existing `infer_device_arch()`, which
  already returns cdna3/hopper/ascend910/pvc but was wired to nothing.
  Evaluated outside the CUDA block so NPU/XPU impls can gate themselves.
- `archs` and `min_cc`/`max_cc` are mutually exclusive, rejected at
  construction: the combination is unsatisfiable on every device.
- A CPU device selector no longer resolves to accelerator 0.
- Include the device arch in the `available_impls` memo key; it is not
  derivable from (device, cc).

Tests simulated NVIDIA devices by mocking the capability but never the
platform, so several asserted NVIDIA semantics while passing on AMD for
the wrong reason; they now pin a non-ROCm build. New tests cover the ROCm
cc gate, the arch gate, device selectors, the exclusivity check, and
dispatch-level filtering and memo keys.

Signed-off-by: Patel, Nilaykumar K <NilaykumarKantibhai.Patel@amd.com>

This branch has not been deployed

No deployments
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