[UP][release/2.13] Guard native BMM outer-product launches against the HIP work-item limit - #3596
Open
naromero77amd wants to merge 1 commit into
Open
[UP][release/2.13] Guard native BMM outer-product launches against the HIP work-item limit#3596naromero77amd wants to merge 1 commit into
naromero77amd wants to merge 1 commit into
Conversation
naromero77amd
requested review from
jeffdaily,
jithunnair-amd and
pruthvistony
August 24, 2026 17:46
naromero77amd
marked this pull request as draft
August 25, 2026 21:23
…tem limit (pytorch#194131) - decline the eager native outer-product BMM specialization when its launch would exceed HIP's work-item limit, and let ATen handle the operation instead - share the launch configuration between the guard and the launch, and pin `num_warps`, so the checked and launched grids cannot drift - add a ROCm regression that pins the boundary from both sides HIP rejects a launch once `gridDim.x * blockDim.x` reaches `2^32`. The eager outer-product kernel launches a 1D grid with one program per (batch, M tile, N tile) using a fixed configuration and, unlike Inductor, cannot grow its tiles to shrink the grid, so it declines the specialization and falls back to ATen. The limit is on total work items, so the boundary moves with the wave size and the guard reads it from the device. For `M = N = 1` that is `B = 16,777,216` on wave64 (CDNA) and `B = 33,554,432` on wave32 (RDNA). The guard is also restricted to CUDA/HIP tensors, since the override is registered for the XPU dispatch key as well, where querying CUDA device properties raises. On gfx90a the rejected launch does not fail cleanly. Triton reports `RuntimeError: Triton Error [HIP]: Code: 1, Messsage: invalid argument`, which its knobs machinery then mangles into a `SystemError`, and the HIP context is left unusable — the next allocation fails with `AcceleratorError: CUDA error: invalid argument`. Measured by calling the launcher directly, bypassing the guard: | B (M = N = 1) | work items | guard | unguarded launch | |---|---|---|---| | 16,777,215 | 4,294,967,040 | accept | succeeds, results correct | | 16,777,216 | 4,294,967,296 (2^32) | decline | fails, HIP context left unusable | The guard declines exactly the launches that fail and accepts every launch that works. ```bash PYTHONPATH="$PWD" LD_LIBRARY_PATH="$PWD/build/lib:${LD_LIBRARY_PATH:-}" python test/test_bmm_outer_product.py PYTHONPATH="$PWD" LD_LIBRARY_PATH="$PWD/build/lib:${LD_LIBRARY_PATH:-}" python test/test_bmm_outer_product.py -k hip_grid_limit_fallback lintrunner test/test_bmm_outer_product.py torch/_native/ops/bmm_outer_product/triton_impl.py torch/_native/ops/bmm_outer_product/triton_kernels.py ``` 26 tests pass on gfx90a (12 skipped: single-GPU and non-ROCm paths). Verified on wave64 hardware only; the wave32 boundary is arithmetic. The Inductor changes previously in this PR have been dropped per @slayton58's review, so `torch/_inductor/runtime/triton_heuristics.py` and `torch/utils/_triton.py` are no longer touched. Made with [Cursor](https://cursor.com) Pull Request resolved: pytorch#194131 Approved by: https://github.com/jansel Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit 58a938a)
naromero77amd
force-pushed
the
release/2.13-native-triton-fix
branch
from
August 31, 2026 16:01
e3a498a to
f270754
Compare
naromero77amd
marked this pull request as ready for review
August 31, 2026 17:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: https://amd-hub.atlassian.net/browse/ROCM-29320. Request is from a high-priority customer.
Backport of landed pytorch/pytorch#194131 to
release/2.13as a singlecherry-pick -xof upstream commit58a938a.Summary
exceed HIP's work-item limit, and fall back to ATen
num_warps, so the checked and launched grids cannot driftHIP rejects a launch once
gridDim.x * blockDim.xreaches2^32. The eagerouter-product kernel launches a 1D grid with one program per (batch, M tile, N
tile) using a fixed configuration and, unlike Inductor, cannot grow its tiles to
shrink the grid, so it declines the specialization and falls back to ATen.
The limit is on total work items, so the boundary moves with the wave size and
the guard reads it from the device. For
M = N = 1that isB = 16,777,216onwave64 (CDNA) and
B = 33,554,432on wave32 (RDNA).At these sizes ATen can also fail on some architectures, but it raises a clean,
catchable
AcceleratorError; the rejected Triton launch can leave the HIPcontext unusable.
Why this needs a guard
On gfx90a the rejected launch does not fail cleanly. Triton reports
RuntimeError: Triton Error [HIP]: Code: 1, Messsage: invalid argument, whichits knobs machinery then mangles into a
SystemError, and the HIP context isleft unusable—the next allocation fails with
AcceleratorError: CUDA error: invalid argument.Boundary verification (gfx90a, wave64)
Measured by calling the launcher directly, bypassing the guard:
The guard declines exactly the launches that fail and accepts every launch that
works.
Test Plan
The upstream PR passed its full BMM outer-product suite and its ROCm regression
ran successfully on MI350 (gfx950, wave64).
The release backport's adapted files pass targeted lint:
release/2.13predates the upstream branch's device-generic test harness andCOW/instrumentation refactors. Conflict resolution preserves the release
branch's existing behavior while applying the landed launch guard, shared
configuration, explicit warp count, and regression test.
Made with Cursor
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben