Repository navigation
Conversation
…astest grid index The kernel launched a (row blocks, column blocks) grid, so programs that run together covered one 256-column stripe of many rows. On gfx1201 that loses bandwidth at every row pitch and collapses it at large power-of-two pitches: N = 8192 ran at 138 GB/s. A 1-D grid with the column block varying fastest lets concurrent programs stream along rows: 584-597 GB/s for every shape measured at M = 16384. Outputs are unchanged. Signed-off-by: Sylvan Liu <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
There was a problem hiding this comment.
🔵 Needs a closer look
The launch-order change affects all supported GPUs, but timing evidence covers only gfx1201, leaving gfx942/gfx950 performance for a maintainer to confirm before a final decision.
No open issues 🎉
What changed in this PR
This PR changes the launch order of AITER’s Triton fused_indexed_gated_residual kernel to improve memory access on gfx1201. The public API, computation, tile sizes, and tuning configuration remain unchanged.
Changes:
- Replace the two-dimensional launch grid with a one-dimensional grid.
- Derive tile coordinates so column blocks vary fastest, avoiding the secondary grid-axis size limit.
| File | Description |
|---|---|
aiter/ops/triton/fusions/fused_indexed_gated_residual.py |
Launch all row and column tiles on one grid axis. |
aiter/ops/triton/_triton_kernels/fusions/fused_indexed_gated_residual.py |
Map each program ID to tile coordinates with column blocks varying fastest. |
Review effort: Balanced
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
The failed I can't re-run jobs. Could a maintainer re-run the failed ones? On the Copilot note about gfx942/gfx950: I have no MI hardware, so I could not time it there. Only the program-to-tile mapping changes; tile sizes, configs and the per-tile instructions stay the same. On MI the old order may already have been fine. If someone can run |
Summary
fused_indexed_gated_residual(Triton, merged in #6416) now launches a 1-D grid in which the column block varies fastest. Before, row blocks varied fastest. On gfx1201 this raises the kernel from 138–575 GB/s to 584–597 GB/s at M = 16384, depending on the row width. Outputs are bit-identical, and the kernel's math, tiles and config are unchanged.Motivation
Found while comparing this kernel with the HIP version of the op in the same op test (#6417, review comment #6417 (comment)). The Triton kernel was much slower than HIP at some row widths, for example 5.8 ms against 1.3 ms at 16384 x 8192.
The grid was
(cdiv(M, BLOCK_M), cdiv(N, BLOCK_N))with the row block inprogram_id(0). Programs that run together therefore covered one 256-column stripe of 16 x (number of resident programs) rows, instead of walking along rows. On gfx1201 this costs bandwidth at every row width and collapses it when the row pitch is a large power of two (N = 8192: 138 GB/s; N = 4096: 275 GB/s).Swapping the grid order is the whole fix. In the same comparison, a variant with the same kernel body and only the grid axes swapped ran at 572–594 GB/s on every case, while row-wise tiles (1 x 1024) and narrower row blocks (4 x 512) recovered only part of it. The ISA confirms that the slow N = 8192 case is not an instruction-width problem: its loads and stores are 128-bit, exactly as at N = 5376.
Changes
_fused_indexed_gated_residual_kernel: derive the row block and column block from a 1-Dprogram_id(0), column block fastest.fused_indexed_gated_residual: launchcdiv(M, BLOCK_M) * cdiv(N, BLOCK_N)programs on one grid axis. A 1-D grid also stays clear of the 65535 limit on grid axes 1 and 2.Performance (if applicable)
Radeon AI PRO R9700 (gfx1201), bf16, G = 9, run-of-index indices,
round_intermediate=True. Median of 5 rounds of 30 calls (torch.cuda.Event), mean of two processes each for before and after, run in the order before, after, after, before. Effective bandwidth counts 3 x M x N x 2 bytes.27 cases were measured at M = 1024, 16384 and 113102. The only regression is the cache-resident M = 16384, N = 320 case (+2.5%, 0.7 us); at M = 1024 and M = 113102 the same N is 0.99x and 0.95x.
Testing
No test is added: the existing
op_tests/triton_tests/fusions/test_fused_indexed_gated_residual.pyalready covers tails along both M and N, single rows and narrow N, and strided rows. It passes unchanged (34 passed on gfx1201). Every timed case above was also checked bit-identical to the eager expression before and after the change.Documentation
The interface and results are unchanged.
Dependencies
Breaking Changes
None.
AI assistance: this change was developed with the help of an AI coding assistant (GitHub Copilot). All tests and timings above were run on the listed hardware.
PR Self-Review
Reviewed revision
a72fabe
Behavior and intent
Only the launch order of the programs changes: the same [BLOCK_M, BLOCK_N] tiles are computed with the same instructions, now with column blocks varying fastest across the grid. Before, the order spread concurrent programs over one column stripe of many rows, which lost bandwidth at every row width and up to 4.9x time at power-of-two row pitches on gfx1201 (M = 113102, N = 8192: 45.0 ms before, 9.2 ms after). Results are bit-identical.
Validation and unverified scope
rocm/pytorch:rocm10.1.0_ubuntu24.04_py3.12_pytorch_release_2.14.0(torch 2.14.0, Triton 3.8.0),AITER_TRITON_ONLY=1:python3 -m pytest -q op_tests/triton_tests/fusions/test_fused_indexed_gated_residual.py: 34 passed at a72fabe (on main 3486e43).torch.equalagainstresidual + gate[indices] * x.PR-specific question
The automated self-review posted no question for this path, so here is the invariant I checked. Every call of the Triton
fused_indexed_gated_residualon every architecture takes the changed launch. The grid iscdiv(M, BLOCK_M) * cdiv(N, BLOCK_N)programs on axis 0, and programpidcomputes tile(pid // col_blocks, pid % col_blocks). So each(row block, column block)pair is computed exactly once, with the same masks as before. Axis 0 allows up to 2^31 - 1 programs, so the 1-D grid has no new size limit; the old grid's axis 1 was capped at 65535 column blocks. The 34 existing tests compare against the eager reference withtorch.equal.Changed op tests
None.