Skip to content

[Inductor][ROCm] Flush L2 + Infinity Cache with a read in InductorBenchmarker - #203681

Open
jananisriram wants to merge 10 commits into
gh/jananisriram/125/basefrom
gh/jananisriram/125/head
Open

jananisriram wants to merge 10 commits into
gh/jananisriram/125/basefrom
gh/jananisriram/125/head

Conversation

@jananisriram

@jananisriram jananisriram commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

On ROCm, InductorBenchmarker flushes only L2_cache_size, the 4 MB per-XCD L2 on MI300X/MI350X. Operands stay warm in the 256 MB Infinity Cache (MALL), which misranks autotune choices. A larger zero_() flush does not fix this: it leaves the flush buffer dirty in the caches, and the timed call pays the write-back.

On ROCm, this change flushes L2 + MALL by summing a float32 buffer. The MALL size comes from the gfx target: 0 on MI100/MI200, and 256 MB for unknown archs. CUDA and the other benchmarkers are unchanged.

Agent details

Drafted with an AI assistant (Claude); pending author review.

Eviction on MI350X: device time of a sum over a 128 MiB operand after each flush.

  • warm: 37.7 us
  • fresh operands: 39.5 us
  • 260 MB read flush: 39.5 us
  • 260 MB zero_() flush: 57.8 us

Autotune accuracy on MI350X: 62 GEMM shapes x 2 repeats. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush.

benchmarker picks within 2% of best picks stable across repeats benchmark time per choice
this change 75/124 56/62 79 ms
current 4 MB flush 67/124 52/62 65 ms
legacy do_bench 66/124 53/62 191 ms

The flush buffer is 260 MB, the same size as do_bench's.

On 36 IG HIM graphs (prod interpreter, read-flushed device time), this is -2.7 ms/step vs legacy, against a 1.6 ms/step A/A floor. Compile time is about 60% lower than legacy.

Test Plan:

python test/inductor/test_benchmarking.py -k flush
python test/inductor/test_benchmarking.py

41/41 pass on MI350X. The new tests fail on the base revision.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben

Differential Revision: D131834106

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: inductor module: rocm AMD GPU support for Pytorch labels Nov 5, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

PR Status: in progress

Please address review feedback on your PR either with a code/PR description change. If a review comment is irrelevant, react with 👎 on that specific comment to reject it, and leave a short reply explaining why. The change must pass any running CI and existing failures must be classified as unrelated (see status below in this comment).

Passing automated review does not guarantee that this PR will be merged. It still requires maintainer review and may be closed if its design or direction does not align with the project.

To minimize iteration time, feel free to run the pr-review skill from the repo locally. To trigger a fresh automated review, make a new push or comment @pytorchbot review. To bypass automated review, please add the "no automated review" label.

🟡 AUTOMATED REVIEW - Changes requested:

On ROCm, this PR makes InductorBenchmarker flush both the L2 and the Infinity
Cache (MALL) by reading a float32 buffer twice with a Triton kernel. It gets the
MALL size per device from HSA and falls back to a gfx-target table. The
recommendation is Request Changes because jeffdaily's change request is still
not addressed: the description is stale, no numbers have been measured at HEAD,
and no size-source agreement with # 203965 is recorded. All other points are
non-blocking.

Findings (9):

[major] torch/_inductor/runtime/benchmarking.py:919
Blocking (continuing): jeffdaily's Nov 13 CHANGES_REQUESTED review is still not
addressed. The code-side points are done; these remain open:
- Stale description: the body still says ROCm flushes "by summing a float32
buffer" and that unknown archs get "256 MB". At HEAD the flush is a two-pass
Triton read, HSA is queried first (:710), and unlisted targets get 0 (:717).
- Every figure in the body was measured on the removed sum() flush (eviction
list, autotune table, 79 vs 65 ms, HIM-graph, compile time, 41/41 tests). The
promised MI350X/MI300X numbers have not been posted, and the body has no MI300X
eviction data.
- No one-pass Triton figure backs the "Read it twice" comment (:922-924). The
only one-pass number in the thread (10-44%) is for sum().
- No recorded agreement with @​ Qubitium / # 203965 on a single source of truth
for the size. This PR still carries its own ctypes HSA reader (:640-696).
To fix: rewrite the body to describe HEAD, post fresh MI350X/MI300X numbers that
include a one-pass Triton figure, and record the size-source decision with #
203965.

[minor] torch/_inductor/runtime/benchmarking.py:629
Non-blocking: the gfx1250 entry doesn't fit the table's comments and may
double-count. gfx1250 is CDNA5 / MI450. Its row sits between the CDNA and RDNA
rows, and its comment is '# GL2, the MALL equivalent', while every other CDNA
row names its product. The header (:620-622) and the
_rocm_mall_size/get_flush_size docstrings all describe an Infinity Cache.
get_flush_size adds the table value to props.L2_cache_size, so if HIP's
L2_cache_size on gfx1250 already reports the 192 MB GL2, each flush becomes
about 384 MB, read twice. That costs extra flush time, but results stay correct.
The test pins L2 at 4 MiB, so it cannot catch this. Please confirm what
torch.cuda.get_device_properties(0).L2_cache_size reports on gfx1250, and adjust
the entry and its comment (e.g. '# MI450 (CDNA5): GL2; HSA reports nothing
beyond L2').

[minor] torch/_inductor/runtime/benchmarking.py:717
Non-blocking: the '-strict' handling exists only here. No other code in the repo
strips '-strict'. get_compute_capability (torch/_dynamo/device_interface.py:446)
only splits off ':feature', and so do is_gfx1250_arch
(torch/_inductor/utils.py:2653-2655, which feeds the TDM gate), rocm_gfx_arch()
(used in heuristics/template/triton.py) and the 320 KB shared-memory branch in
torch/cuda/_utils.py. If gcnArchName really is 'gfx1250-strict', all of those
gates miss it and only this table matches. Put the normalization in
rocm_gfx_arch / get_compute_capability, or file a follow-up, rather than
handling it in this one lookup.

[minor] torch/_inductor/runtime/benchmarking.py:780
Non-blocking: xinyazhang's Nov 20 question (thread on benchmarking.py:637) is
unanswered. They asked why the PR doesn't flush a uniform 2 GB everywhere. The
question was addressed to @​ naromero77amd, and it is a design question for this
PR, so the author or naromero77amd should answer it in the thread. The likely
answer is flush cost per choice and OOM risk on consumer GPUs.

[minor] torch/_inductor/runtime/benchmarking.py:939
Earlier non-blocking finding, still open: when the Triton flush fails, the
fallback zeroes the ~260 MB float32 buffer on every iteration and logs a warning
with a traceback on every call (:938-942).

(4 more not shown, see the review run)

Reviewed commit: 9e4ebe3

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203681

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 12 New Failures, 6 Unrelated Failures

As of commit 9e4ebe3 with merge base 4976eb3 (image):

🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:

  • Triviality
    • Changes how InductorBenchmarker.benchmark_gpu times autotune choices on ROCm: bigger flush, new Triton read kernel, fewer warmup flushes
    • Adds a hand-kept gfx-to-MALL table _ROCM_MALL_SIZE that defaults to 256 MB for unknown archs; that is a tuning decision, not a mechanical edit
  • Evidence for the shipped code
    • Both tests patch out _rocm_read_flush, so no test runs the _rocm_read_kernel Triton kernel itself
    • Per the author's comment, the MI350X numbers and the 41/41 test result come from the earlier buffer.sum() version, not this commit
  • Robustness
    • _rocm_read_kernel imports triton with no guard, unlike the except ImportError handling at benchmarking.py:564-565

reason: not_trivial
Reviewed commit: 086ff5f (NOT the current head 9e4ebe3)

Inference job

🐛 Report a wrong verdict

NEW FAILURES - The following jobs have failed:

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following jobs failed, but the AI CI Advisor judged the failures not to be evidence against this change:

  • BC Lint / bc_linter (gh)
    ##[error]API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 3C80:160214:7E72DB:1918D56:6B04A138 and timestamp 2026-11-23 20:25:28 UTC. For more on scraping GitHub and how it may affect your rights, please review our Terms of Service (https://docs.github.com/en/site-policy/github-terms/github-terms-of-service) - https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api#rate-limiting

    AI verdict: AI verdict: infra issue

    BC Lint failed while checking out the pytorch/test-infra repo, before any lint ran. The cause was a GitHub "API rate limit exceeded for installation" error. The suspect commit only changes inductor benchmarking code and its test, and touches no CI machinery.

    Full reasoning on HUD →

  • trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable) (gh)
    inductor/test_max_autotune

    AI verdict: AI verdict: not related

    test_max_autotune.py failed while being imported. The redis package (redis-8.2.0, installed because requirements-ci.txt only pins redis>=4.0.0) builds a frozenset of str and bytes, and the test runs under python -bb, which turns the resulting BytesWarning into an error. The suspect only adds a gfx1250 entry to the ROCm cache-size (MALL) fallback table and strips a -strict suffix, so it cannot cause this. The same BytesWarning shows up in trunk jobs on main commits that don't include the suspect.

    Full reasoning on HUD →

  • trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable) (gh)
    inductor/test_kernel_benchmark

    AI verdict: AI verdict: not related

    test_kernel_benchmark fails at import because redis 8.2.0 (pulled in by the unpinned redis>=4.0.0 requirement) raises BytesWarning under python -bb at redis/connection.py:2080. The suspect commit only adds a ROCm MALL fallback entry and strips '-strict' from the arch string at runtime, so there is no causal path to this failure.

    Full reasoning on HUD →

  • trunk / macos-py3-arm64 / test (default, 3, 3, macos-m1-stable) (gh)
    inductor/test_triton_kernels

    AI verdict: AI verdict: not related

    inductor/test_triton_kernels fails while it is being imported. The cause is a BytesWarning raised inside the third-party redis 8.2.0 package because tests run with python -bb. The same error appears hundreds of times in trunk jobs for be6a467 and 8142b84, which don't contain the suspect. The suspect only changes the ROCm fallback-size lookup in benchmarking.py, which isn't on this path.

    Full reasoning on HUD →

  • trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-26) (gh)
    test/nn/test_convolution.py::TestConvolutionNN::test_conv_shapecheck_meta_kernel_larger_than_input

    AI verdict: AI verdict: not related

    The suspect test fails because torch.compile imports the third-party redis package, and redis/connection.py:2080 raises BytesWarning: Comparison between bytes and string, which becomes an error under -bb. Main-branch commits from before the suspect (eb52ce7, be6a467, 8142b84) fail on the same MPS job with the same redis BytesWarning, so the cause is an outside dependency change and not this commit's two-line ROCm fallback-table edit.

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@jananisriram
jananisriram marked this pull request as ready for review November 5, 2026 23:42
@jananisriram jananisriram added the topic: not user facing topic category label Nov 5, 2026
@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Nov 5, 2026
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 6, 2026
github-actions[bot]

This comment was marked as outdated.

@warrendeng warrendeng added the ciflow/inductor-rocm-mi350 Trigger "inductor" config CI on ROCm MI350 label Nov 6, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/inductor-rocm-mi350.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/gb300
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/native-aot
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/periodic-rocm-mi350
  • ciflow/periodic-strict
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-nightly
  • ciflow/rocm-preview
  • ciflow/rocm-rx7900
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@warrendeng warrendeng added ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 and removed ciflow/inductor-rocm-mi350 Trigger "inductor" config CI on ROCm MI350 labels Nov 6, 2026
Comment thread torch/_inductor/runtime/benchmarking.py Resolved
jananisriram added a commit that referenced this pull request Nov 7, 2026
On MI350X (gfx950), decompose_k beats hipBLASLt and the Triton mm template on many large-K GEMMs, but it is off on ROCm. This turns it on by default on gfx950 only (`num_decompose_k_splits=-1`, the new ROCm default, resolves to 10 splits there and 0 elsewhere).

With the default, decompose_k is offered when:
- K >= 8 * max(M, N)
- 8192 <= K <= 2M
- the unsplit GEMM has fewer than 32 output tiles of 256x256

Splits are pruned to at least 32 output tiles of 64x64 and at most 64 MiB of FP32 workspace. The bounds are in `config.rocm.decompose_k_*`.

CUDA, other ROCm archs, and any explicit `TORCHINDUCTOR_NUM_DECOMPOSE_K_SPLITS` keep today's behavior.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 (needs its k_split prune) and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 241 shapes that pass the arch-gated rule before the K and tile caps. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681). The rule above is re-scored from those measurements:
- geomean dk-on / dk-off pick: 0.967; 60 shapes >3% faster
- 5 shapes >3% slower beyond the re-timing noise of aten itself (3-15%, all autotune misranks between aten and decompose_k)
- 0 degraded shapes where Triton was the dk-off pick (Triton won 1 shape; +1.8% with dk on, within noise)
- fp32 within 4e-6 of aten
- compile time on offered GEMMs about 1.9x

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
Pending on MI350X (waiting for a free GPU). Lint is clean, and a CPU check of the gating shows that CUDA, gfx942 and explicit split counts are unchanged.


ghstack-source-id: 40147a2
Pull-Request: #203875
Qubitium added a commit to Qubitium/pytorch-rocm that referenced this pull request Nov 8, 2026
Cherry-pick the read-flush implementation and initial test from
Janani Sriram's pytorch#203681. Keep float32 reduction outside
event timing so repeated buffer writes do not leave dirty cache lines
whose writeback can affect the timed callable.

Retain only the flushing changes from the source commit. Omit its
architecture table, no-argument cache, additive sizing helper and their
tests; the preceding commit supplies hardware-reported cache sizing.
Restrict the behavior to ROCm's cuda device interface, retain writes
for CUDA/XPU, release the bound method with its buffer, and expand the
test to check device selection and ordering around timing events.

Adaptation prepared with Codex at Qubitium's direction.

Test Plan:
24 focused tests pass, including four read/write dispatch and event-order
cases. Two real R9700 runs of the complete main/PR benchmarker modules
complete with 100 positive timing samples each and identical reductions.
The test environment overlays source modules and a compiled property
binding onto the installed ROCm wheel; no full wheel rebuild is claimed.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_integrated_tests.py
HIP_VISIBLE_DEVICES=2 /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/benchmark_integrated.py
```

(cherry picked from commit c25d837)
Co-authored-by: Qubitium <[email protected]>
Qubitium added a commit to Qubitium/pytorch-rocm that referenced this pull request Nov 8, 2026
Cherry-pick the read-flush implementation and initial test from
Janani Sriram's pytorch#203681. Keep float32 reduction outside
event timing so repeated buffer writes do not leave dirty cache lines
whose writeback can affect the timed callable.

Retain only the flushing changes from the source commit. Omit its
architecture table, no-argument cache, additive sizing helper and their
tests; the preceding commit supplies hardware-reported cache sizing.
Restrict the behavior to ROCm's cuda device interface, retain writes
for CUDA/XPU, release the bound method with its buffer, and expand the
test to check device selection and ordering around timing events.

Adaptation prepared with Codex at Qubitium's direction.

Test Plan:
24 focused tests pass, including four read/write dispatch and event-order
cases. Two real R9700 runs of the complete main/PR benchmarker modules
complete with 100 positive timing samples each and identical reductions.
The test environment overlays source modules and a compiled property
binding onto the installed ROCm wheel; no full wheel rebuild is claimed.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_integrated_tests.py
HIP_VISIBLE_DEVICES=2 /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/benchmark_integrated.py
```

(cherry picked from commit c25d837)
Co-authored-by: Qubitium <[email protected]>
Qubitium added a commit to Qubitium/pytorch-rocm that referenced this pull request Nov 8, 2026
Cherry-pick the read-flush implementation and initial test from
Janani Sriram's pytorch#203681. Keep float32 reduction outside
event timing so repeated buffer writes do not leave dirty cache lines
whose writeback can affect the timed callable.

Retain only the flushing changes from the source commit. Omit its
architecture table, no-argument cache, additive sizing helper and their
tests; the preceding commit supplies hardware-reported cache sizing.
Restrict the behavior to ROCm's cuda device interface, retain writes
for CUDA/XPU, release the bound method with its buffer, and expand the
test to check device selection and ordering around timing events.

Adaptation prepared with Codex at Qubitium's direction.

Test Plan:
26 focused tests pass, including four read/write dispatch and event-order
cases. Two real R9700 runs of the complete main/PR benchmarker modules
complete with 100 positive timing samples each and identical reductions.
The test environment overlays source modules and a compiled property
binding onto the installed ROCm wheel; no full wheel rebuild is claimed.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_all_focus.py
HIP_VISIBLE_DEVICES=2 /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/benchmark_integrated.py
```

(cherry picked from commit c25d837)
Co-authored-by: Qubitium <[email protected]>
Qubitium added a commit to Qubitium/pytorch-rocm that referenced this pull request Nov 8, 2026
Cherry-pick the read-flush implementation and initial test from
Janani Sriram's pytorch#203681. Keep float32 reduction outside
event timing so repeated buffer writes do not leave dirty cache lines
whose writeback can affect the timed callable.

Retain only the flushing changes from the source commit. Omit its
architecture table, no-argument cache, additive sizing helper and their
tests; the preceding commit supplies hardware-reported cache sizing.
Restrict the behavior to ROCm's cuda device interface, retain writes
for CUDA/XPU, release the bound method with its buffer, and expand the
test to check device selection and ordering around timing events.

Adaptation prepared with MultiDex at Qubitium's direction.

Test Plan:
26 focused tests pass, including four read/write dispatch and event-order
cases. Two real R9700 runs of the complete main/PR benchmarker modules
complete with 100 positive timing samples each and identical reductions.
The test environment overlays source modules and a compiled property
binding onto the installed ROCm wheel; no full wheel rebuild is claimed.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_all_focus.py
HIP_VISIBLE_DEVICES=2 /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/benchmark_integrated.py
```

(cherry picked from commit c25d837)
Co-authored-by: Qubitium <[email protected]>
[ghstack-poisoned]
jananisriram added a commit that referenced this pull request Nov 9, 2026
On MI350X (gfx950), decompose_k beats hipBLASLt and the Triton mm template on many large-K GEMMs, but it is off on ROCm. This turns it on by default on gfx950 only (`num_decompose_k_splits=-1`, the new ROCm default, resolves to 10 splits there and 0 elsewhere).

With the default, decompose_k is offered when:
- K >= 8 * max(M, N)
- 8192 <= K <= 2M
- the unsplit GEMM has fewer than 32 output tiles of 256x256

Splits are pruned to at least 32 output tiles of 64x64 and at most 64 MiB of FP32 workspace. The bounds are in `config.rocm.decompose_k_*`.

CUDA, other ROCm archs, and any explicit `TORCHINDUCTOR_NUM_DECOMPOSE_K_SPLITS` keep today's behavior.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 (needs its k_split prune) and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 241 shapes that pass the arch-gated rule before the K and tile caps. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681). The rule above is re-scored from those measurements:
- geomean dk-on / dk-off pick: 0.967; 60 shapes >3% faster
- 5 shapes >3% slower beyond the re-timing noise of aten itself (3-15%, all autotune misranks between aten and decompose_k)
- 0 degraded shapes where Triton was the dk-off pick (Triton won 1 shape; +1.8% with dk on, within noise)
- fp32 within 4e-6 of aten
- compile time on offered GEMMs about 1.9x

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
Pending on MI350X (waiting for a free GPU). Lint is clean, and a CPU check of the gating shows that CUDA, gfx942 and explicit split counts are unchanged.


ghstack-source-id: 71885d3
Pull-Request: #203875
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

@Qubitium

Copy link
Copy Markdown
Contributor
  1. Please agree with @Qubitium on one source of truth: read the size from the device when it is available, and keep the table only as a fallback that covers the gfx10/11/12 targets instead of defaulting them to 256 MB.

@jeffdaily @jananisriram This PR's fixed hw table for mall/l3 cache caching is the correct method to use, until my related prs has integrated l3 exposure to hip/rcom.

@Qubitium

Copy link
Copy Markdown
Contributor

@Qubitium for #203965: this keeps the two-pass Triton flush, since a single sum() evicted only 10-44% of a just-reused operand on MI350X.

Got it. Is the two pass triton flush gated to only CDNA4 or is the two-pass default for all arch?

jananisriram added a commit that referenced this pull request Nov 19, 2026
decompose_k was off by default on ROCm pending perf validation (#169948). On MI350X it beats hipBLASLt and the Triton mm template on many large-K GEMMs, so this uses the same default as CUDA (`num_decompose_k_splits=10`).

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 172 GEMMs that pass the default `decompose_k_threshold` (K >= 32 * max(M, N)). Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681):
- geomean dk-on / dk-off pick: 0.971; 58 shapes >3% faster
- 7 shapes >3% slower beyond the re-timing noise of aten itself (all autotune misranks between aten and decompose_k)
- fp32 within 4e-6 of aten

These were measured with splits pruned to at least 32 output tiles of 64x64 and at most 64 MiB of workspace, which #195939's split bound applies on gfx950; other ROCm archs are not pruned. Other ROCm archs (MI300/gfx942, gfx90a, RDNA) are not measured.

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
`test_max_autotune_decompose_k_envvars` gains a default-splits case that checks decompose_k is offered.

ghstack-source-id: 570fd87
Pull-Request: #203875
…o_() flushes L2 only; HSA 0 falls back to the gfx table

[ghstack-poisoned]
jananisriram added a commit that referenced this pull request Nov 19, 2026
…chmarker

On ROCm, `InductorBenchmarker` flushes only `L2_cache_size`, the 4 MB per-XCD L2 on MI300X/MI350X. Operands stay warm in the 256 MB Infinity Cache (MALL), which misranks autotune choices. A larger `zero_()` flush does not fix this: it leaves the flush buffer dirty in the caches, and the timed call pays the write-back.

On ROCm, this change flushes L2 + MALL by reading a float32 buffer twice with a Triton kernel (ATen's `sum()` uses nontemporal loads on MI300, which skip the MALL). A single pass does not evict operands that were just reused from the MALL. The memory warm-up runs half as many flushes, so its total reads are unchanged. The MALL size comes from the gfx target: 0 on MI100/MI200, and 256 MB for unknown archs. CUDA and the other benchmarkers are unchanged.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Eviction on MI350X: device time of a `sum` over a 128 MiB operand after each flush.
- warm: 37.7 us
- fresh operands: 39.5 us
- 260 MB read flush: 39.5 us
- 260 MB `zero_()` flush: 57.8 us

With the operand re-warmed twice before each flush, one 260 MB read pass moves a 64 MiB operand only 13-18% of the way from warm to cold timing, and two passes move it all the way (1.04-1.14; a single `zero_()` behaves like one pass).

Autotune accuracy on MI350X (measured with a single read pass): 62 GEMM shapes x 2 repeats. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush.

| benchmarker | picks within 2% of best | picks stable across repeats | benchmark time per choice |
|---|---|---|---|
| this change | 75/124 | 56/62 | 79 ms |
| current 4 MB flush | 67/124 | 52/62 | 65 ms |
| legacy `do_bench` | 66/124 | 53/62 | 191 ms |

The flush buffer is 260 MB, the same size as `do_bench`'s.

On 36 IG HIM graphs (prod interpreter, read-flushed device time), this is -2.7 ms/step vs legacy, against a 1.6 ms/step A/A floor. Compile time is about 60% lower than legacy.

Test Plan:
```
python test/inductor/test_benchmarking.py -k flush
python test/inductor/test_benchmarking.py
```
41/41 pass on MI350X. The new tests fail on the base revision.

ghstack-source-id: 2ffd349
Pull-Request: #203681
@jananisriram

Copy link
Copy Markdown
Contributor Author

@jananisriram has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

github-actions[bot]

This comment was marked as outdated.

jananisriram added a commit that referenced this pull request Nov 19, 2026
…chmarker

On ROCm, `InductorBenchmarker` flushes only `L2_cache_size`, the 4 MB per-XCD L2 on MI300X/MI350X. Operands stay warm in the 256 MB Infinity Cache (MALL), which misranks autotune choices. A larger `zero_()` flush does not fix this: it leaves the flush buffer dirty in the caches, and the timed call pays the write-back.

On ROCm, this change flushes L2 + MALL by reading a float32 buffer twice with a Triton kernel (ATen's `sum()` uses nontemporal loads on MI300, which skip the MALL). A single pass does not evict operands that were just reused from the MALL. The memory warm-up runs half as many flushes, so its total reads are unchanged. The MALL size comes from the gfx target: 0 on MI100/MI200, and 256 MB for unknown archs. CUDA and the other benchmarkers are unchanged.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Eviction on MI350X: device time of a `sum` over a 128 MiB operand after each flush.
- warm: 37.7 us
- fresh operands: 39.5 us
- 260 MB read flush: 39.5 us
- 260 MB `zero_()` flush: 57.8 us

With the operand re-warmed twice before each flush, one 260 MB read pass moves a 64 MiB operand only 13-18% of the way from warm to cold timing, and two passes move it all the way (1.04-1.14; a single `zero_()` behaves like one pass).

Autotune accuracy on MI350X (measured with a single read pass): 62 GEMM shapes x 2 repeats. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush.

| benchmarker | picks within 2% of best | picks stable across repeats | benchmark time per choice |
|---|---|---|---|
| this change | 75/124 | 56/62 | 79 ms |
| current 4 MB flush | 67/124 | 52/62 | 65 ms |
| legacy `do_bench` | 66/124 | 53/62 | 191 ms |

The flush buffer is 260 MB, the same size as `do_bench`'s.

On 36 IG HIM graphs (prod interpreter, read-flushed device time), this is -2.7 ms/step vs legacy, against a 1.6 ms/step A/A floor. Compile time is about 60% lower than legacy.

Test Plan:
```
python test/inductor/test_benchmarking.py -k flush
python test/inductor/test_benchmarking.py
```
41/41 pass on MI350X. The new tests fail on the base revision.

ghstack-source-id: caf1021
Pull-Request: #203681
@jananisriram

Copy link
Copy Markdown
Contributor Author

@jananisriram has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

github-actions[bot]

This comment was marked as outdated.

jananisriram added a commit that referenced this pull request Nov 19, 2026
jananisriram added a commit that referenced this pull request Nov 19, 2026
decompose_k was off by default on ROCm pending perf validation (#169948). On MI350X it beats hipBLASLt and the Triton mm template on many large-K GEMMs, so this uses the same default as CUDA (`num_decompose_k_splits=10`).

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 172 GEMMs that pass the default `decompose_k_threshold` (K >= 32 * max(M, N)). Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681):
- geomean dk-on / dk-off pick: 0.971; 58 shapes >3% faster
- 7 shapes >3% slower beyond the re-timing noise of aten itself (all autotune misranks between aten and decompose_k)
- fp32 within 4e-6 of aten

These were measured with splits pruned to at least 32 output tiles of 64x64 and at most 64 MiB of workspace, which #195939's split bound applies on gfx950; other ROCm archs are not pruned. Other ROCm archs (MI300/gfx942, gfx90a, RDNA) are not measured.

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
`test_max_autotune_decompose_k_envvars` gains a default-splits case that checks decompose_k is offered.

ghstack-source-id: e11cf66
Pull-Request: #203875
jananisriram added a commit that referenced this pull request Nov 19, 2026
… if the Triton read flush fails

[ghstack-poisoned]
jananisriram added a commit that referenced this pull request Nov 19, 2026
…chmarker

On ROCm, `InductorBenchmarker` flushes only `L2_cache_size`, the 4 MB per-XCD L2 on MI300X/MI350X. Operands stay warm in the 256 MB Infinity Cache (MALL), which misranks autotune choices. A larger `zero_()` flush does not fix this: it leaves the flush buffer dirty in the caches, and the timed call pays the write-back.

On ROCm, this change flushes L2 + MALL by reading a float32 buffer twice with a Triton kernel (ATen's `sum()` uses nontemporal loads on MI300, which skip the MALL). A single pass does not evict operands that were just reused from the MALL. The memory warm-up runs half as many flushes, so its total reads are unchanged. The MALL size comes from the gfx target: 0 on MI100/MI200, and 256 MB for unknown archs. CUDA and the other benchmarkers are unchanged.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Eviction on MI350X: device time of a `sum` over a 128 MiB operand after each flush.
- warm: 37.7 us
- fresh operands: 39.5 us
- 260 MB read flush: 39.5 us
- 260 MB `zero_()` flush: 57.8 us

With the operand re-warmed twice before each flush, one 260 MB read pass moves a 64 MiB operand only 13-18% of the way from warm to cold timing, and two passes move it all the way (1.04-1.14; a single `zero_()` behaves like one pass).

Autotune accuracy on MI350X (measured with a single read pass): 62 GEMM shapes x 2 repeats. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush.

| benchmarker | picks within 2% of best | picks stable across repeats | benchmark time per choice |
|---|---|---|---|
| this change | 75/124 | 56/62 | 79 ms |
| current 4 MB flush | 67/124 | 52/62 | 65 ms |
| legacy `do_bench` | 66/124 | 53/62 | 191 ms |

The flush buffer is 260 MB, the same size as `do_bench`'s.

On 36 IG HIM graphs (prod interpreter, read-flushed device time), this is -2.7 ms/step vs legacy, against a 1.6 ms/step A/A floor. Compile time is about 60% lower than legacy.

Test Plan:
```
python test/inductor/test_benchmarking.py -k flush
python test/inductor/test_benchmarking.py
```
41/41 pass on MI350X. The new tests fail on the base revision.

ghstack-source-id: b954cd9
Pull-Request: #203681
@jananisriram

Copy link
Copy Markdown
Contributor Author

@jananisriram has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of f799e2f: changes requested before human review.

On ROCm, this PR makes InductorBenchmarker flush L2 plus the Infinity Cache (MALL) with a two-pass Triton read. The MALL size comes from HSA, with a gfx-target table as fallback. Recommendation: Request Changes, because jeffdaily's change request is still not addressed: the PR body describes the removed sum() flush, no numbers were measured at HEAD, there is no one-pass Triton figure, and no agreement with # 203965 is recorded. All other points are non-blocking.

🔴 1 blocking finding is attached to the code below.

⚪ 6 non-blocking findings

Non-blocking: the Triton-failure fallback performs worse than having no Triton, retries on every call, and makes the docstring wrong. buffer is allocated before the try as float32 at get_flush_size() (L2+MALL, ~260 MB on MI300/MI350), so flush = buffer.zero_ zeroes ~260 MB every iteration. The no-Triton path zeroes an L2-only int buffer instead. The PR's own data shows a 260 MB zero_() inflates the timed call (57.8 vs 39.5 s). The comments at :905/:923 don't describe this path. Nothing records the failure: functools.cache on rocm_read_kernel caches only the jit object, so every benchmark_gpu call recompiles and logs a warning with exc_info, one traceback per autotune choice. Compare the warn-once helper at :173-191. The message also doesn't say the Infinity Cache stays warm. The memory_warmup_iters docstring (:844-846) claims halving, but on failure nothing is halved. Fix: decide read_flush once per device, before allocating, with a cached check that compiles and launches the kernel. On failure, take the L2-sized int zero() path, warn once, and state the cost.


read_flush = _is_rocm_device(device_type) and has_triton()

Non-blocking: MI100/MI200 now do two read passes for no benefit. read_flush depends only on ROCm plus has_triton(). So gfx906/gfx908/gfx90a and unlisted archs (MALL 0) also switch from an int zero_() to a two-pass Triton read with half the warmup, on the same L2-sized buffer. The second pass is justified only by Infinity Cache reuse (:921-923), so on L2-only GPUs it is pure extra cost, and nothing measured it there. Consider gating on _rocm_mall_size(dev) &gt; 0, or at least using one pass when the MALL is 0.


if triton == "broken":

Non-blocking: the "broken" case raises at the wrong point and doesn't check the warning. It raises from the _rocm_read_flush factory, but a real Triton compile/launch error comes from the returned flush() (kernel[grid], benchmarking.py:751). So moving the eager flush() at benchmarking.py:936 out of the try and into the else: block still passes all four parametrizations. The fallback warning is also not asserted. Fix: have the fake return a callable that raises on its first call, and wrap the call in assertLogs(_bench.log, "WARNING").


Non-blocking: test_rocm_mall_size_queries_hsa still passes when HSA is broken. The equality check sits under if hsa_size:. On gfx942/gfx950 the 256 MiB table fallback satisfies 0 < size <= 256 MiB. assertIsNone(_hsa_cache_beyond_l2(b"f" * 16)) also passes when HSA can't be loaded. The new RTLD_NOLOAD path returns None whenever libhsa isn't already loaded under that exact soname, which makes this silent pass more likely. Fix: add assertIsNotNone(hsa_size) on gfx942/gfx950, plus a realistic lower bound.


Non-blocking: flush cost is not counted against max_benchmark_duration (:963-967). benchmark_iters is computed from estimated_timing alone, though the docstring (:849-853) says the warmup is accounted for. Each flush now reads about 2 260 MB on MI300/MI350, plus the new eager check flush on every call.


Non-blocking: TorchProfilerBenchmarker (:1064-1074) still flushes ROCm with a 256 MB int32 zero_(). By the body's own data, that inflates the timed call.

Please address the findings and push; a new commit normally gets a fresh automated review.

Disagree with a finding? Reply with your reasoning, then comment @pytorchbot review to request a re-review. This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

# (CUDA). On ROCm, flush by reading the buffer instead: zero_() leaves it
# dirty in the L2 / Infinity Cache and the timed call then pays the
# write-back. Read it with a Triton kernel, since ATen's loads skip the
# Infinity Cache on MI300 (see _rocm_read_flush). Read it twice: one pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Blocking: jeffdaily's Nov 13 CHANGES_REQUESTED review is not fully addressed. (1) The PR body describes the old code: it says ROCm flushes by summing a float32 buffer and that unknown archs get 256 MB. At HEAD the flush is a two-pass Triton read (:719-753, :931-945), HSA is queried first (:709), and unlisted targets get 0 (:716). (2) Every number in the body was measured on the sum() version (eviction list, autotune table, 79 vs 65 ms, HIM-graph, compile time, 41/41 pass). The MI350X/MI300X numbers promised on Nov 14 have not been posted. (3) The body has no MI300X eviction data. (4) No one-pass Triton number backs the comment at :921-923 ("Read it twice: one pass does not evict"); every one-pass figure is for sum(). (5) No agreement with @ Qubitium / # 203965 on the cache-size source is recorded, and the PR still has its own ctypes HSA reader (:641). Fix: rewrite the body to describe HEAD, add fresh MI350X/MI300X numbers including a one-pass Triton figure, and record the size-source decision with # 203965.

Report this finding

jananisriram added a commit that referenced this pull request Nov 19, 2026
jananisriram added a commit that referenced this pull request Nov 19, 2026
decompose_k was off by default on ROCm pending perf validation (#169948). On MI350X it beats hipBLASLt and the Triton mm template on many large-K GEMMs, so this uses the same default as CUDA (`num_decompose_k_splits=10`).

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 172 GEMMs that pass the default `decompose_k_threshold` (K >= 32 * max(M, N)). Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681):
- geomean dk-on / dk-off pick: 0.971; 58 shapes >3% faster
- 7 shapes >3% slower beyond the re-timing noise of aten itself (all autotune misranks between aten and decompose_k)
- fp32 within 4e-6 of aten

These were measured with splits pruned to at least 32 output tiles of 64x64 and at most 64 MiB of workspace, which #195939's split bound applies on gfx950; other ROCm archs are not pruned. Other ROCm archs (MI300/gfx942, gfx90a, RDNA) are not measured.

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
`test_max_autotune_decompose_k_envvars` gains a default-splits case that checks decompose_k is offered.

ghstack-source-id: f917151
Pull-Request: #203875
jananisriram added a commit that referenced this pull request Nov 19, 2026
"gfx1102": 32 * 1024 * 1024, # RX 7600
"gfx1151": 32 * 1024 * 1024, # Ryzen AI Max (Strix Halo)
"gfx1200": 32 * 1024 * 1024, # RX 9060
"gfx1201": 64 * 1024 * 1024, # RX 9070, Radeon AI PRO R9700

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On gfx1250 and gfx1250-strict, we need to flush the GL2, which is the equivalent of the MALL (192 MB). HSA currently reports no cache beyond L2 on gfx1250-strict, so _rocm_mall_size falls back to this table. get_compute_capability() also returns gfx1250-strict with the stepping suffix, so the lookup needs to map it onto gfx1250.

Table entry:

    "gfx1250": 192 * 1024 * 1024,  # GL2, the MALL equivalent

In _rocm_mall_size:

    arch = get_interface_for_device("cuda").get_compute_capability(device)
    return _ROCM_MALL_SIZE_FALLBACK.get(str(arch).removesuffix("-strict"), 0)

Test cases for test_inductor_benchmarker_flush_size_adds_rocm_mall:

            ("gfx1250", 0, 192),
            ("gfx1250-strict", 0, 192),

@xinyazhang xinyazhang Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've a question: What stops us from uniformly flushing 2G data, which also avoids leaking of cache information unnecessarily. @naromero77amd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[from my agent]
Thanks @naromero77amd. I added gfx1250 (192 MiB) and the -strict stripping, with your test cases (9e4ebe3).

@xinyazhang I timed it on MI350X. One 2 GiB read pass takes 365 us, vs 99 us for this PR's flush (L2 + MALL, two passes). With the flush size fixed at 2 GiB, benchmark_gpu went from 17-38 ms to 88-127 ms per call on three GEMMs, and the kernel timings were within a few percent. So a fixed size adds autotune time without changing results. On the cache information: the size comes from HSA, which any process can already query, so this doesn't expose anything new.

@jananisriram

Copy link
Copy Markdown
Contributor Author

@jananisriram has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

jananisriram added a commit that referenced this pull request Nov 23, 2026
…chmarker

On ROCm, `InductorBenchmarker` flushes only `L2_cache_size`, the 4 MB per-XCD L2 on MI300X/MI350X. Operands stay warm in the 256 MB Infinity Cache (MALL), which misranks autotune choices. A larger `zero_()` flush does not fix this: it leaves the flush buffer dirty in the caches, and the timed call pays the write-back.

On ROCm, this change flushes L2 + MALL by reading a float32 buffer twice with a Triton kernel (ATen's `sum()` uses nontemporal loads on MI300, which skip the MALL). A single pass does not evict operands that were just reused from the MALL. The memory warm-up runs half as many flushes, so its total reads are unchanged. The MALL size comes from the gfx target: 0 on MI100/MI200, and 256 MB for unknown archs. CUDA and the other benchmarkers are unchanged.

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Eviction on MI350X: device time of a `sum` over a 128 MiB operand after each flush.
- warm: 37.7 us
- fresh operands: 39.5 us
- 260 MB read flush: 39.5 us
- 260 MB `zero_()` flush: 57.8 us

With the operand re-warmed twice before each flush, one 260 MB read pass moves a 64 MiB operand only 13-18% of the way from warm to cold timing, and two passes move it all the way (1.04-1.14; a single `zero_()` behaves like one pass).

Autotune accuracy on MI350X (measured with a single read pass): 62 GEMM shapes x 2 repeats. Ground truth is the median over 8 input allocations of summed device kernel time after a read flush.

| benchmarker | picks within 2% of best | picks stable across repeats | benchmark time per choice |
|---|---|---|---|
| this change | 75/124 | 56/62 | 79 ms |
| current 4 MB flush | 67/124 | 52/62 | 65 ms |
| legacy `do_bench` | 66/124 | 53/62 | 191 ms |

The flush buffer is 260 MB, the same size as `do_bench`'s.

On 36 IG HIM graphs (prod interpreter, read-flushed device time), this is -2.7 ms/step vs legacy, against a 1.6 ms/step A/A floor. Compile time is about 60% lower than legacy.

Test Plan:
```
python test/inductor/test_benchmarking.py -k flush
python test/inductor/test_benchmarking.py
```
41/41 pass on MI350X. The new tests fail on the base revision.

ghstack-source-id: 391d86f
Pull-Request: #203681
@jananisriram

Copy link
Copy Markdown
Contributor Author

@jananisriram has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Qubitium added a commit to Qubitium/pytorch-rocm that referenced this pull request Nov 24, 2026
Cherry-pick the read-flush implementation and initial test from
Janani Sriram's pytorch#203681. Keep float32 reduction outside
event timing so repeated buffer writes do not leave dirty cache lines
whose writeback can affect the timed callable.

Retain only the flushing changes from the source commit. Omit its
architecture table, no-argument cache, additive sizing helper and their
tests; the preceding commit supplies hardware-reported cache sizing.
Restrict the behavior to ROCm's cuda device interface, retain writes
for CUDA/XPU, release the bound method with its buffer, and expand the
test to check device selection and ordering around timing events.

Adaptation prepared with MultiDex at Qubitium's direction.

Test Plan:
26 focused tests pass, including four read/write dispatch and event-order
cases. Two real R9700 runs of the complete main/PR benchmarker modules
complete with 100 positive timing samples each and identical reductions.
The test environment overlays source modules and a compiled property
binding onto the installed ROCm wheel; no full wheel rebuild is claimed.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_all_focus.py
HIP_VISIBLE_DEVICES=2 /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/benchmark_integrated.py
```

(cherry picked from commit c25d837)
Co-authored-by: Qubitium <[email protected]>
jananisriram added a commit that referenced this pull request Dec 1, 2026
decompose_k was off by default on ROCm pending perf validation (#169948). On MI350X it beats hipBLASLt and the Triton mm template on many large-K GEMMs, so this uses the same default as CUDA (`num_decompose_k_splits=10`).

## Agent details
Drafted with an AI assistant (Claude); pending author review.

Stacked on #195939 and #203681 (the read-flush benchmarker the numbers below were measured with).

MI350X, 172 GEMMs that pass the default `decompose_k_threshold` (K >= 32 * max(M, N)). Ground truth is the median over 8 input allocations of summed device kernel time after a read flush (#203681):
- geomean dk-on / dk-off pick: 0.971; 58 shapes >3% faster
- 7 shapes >3% slower beyond the re-timing noise of aten itself (all autotune misranks between aten and decompose_k)
- fp32 within 4e-6 of aten

These were measured with splits pruned to at least 32 output tiles of 64x64 and at most 64 MiB of workspace, which #195939's split bound applies on gfx950; other ROCm archs are not pruned. Other ROCm archs (MI300/gfx942, gfx90a, RDNA) are not measured.

Test Plan:
```
python test/inductor/test_max_autotune.py -k decompose
```
`test_max_autotune_decompose_k_envvars` gains a default-splits case that checks decompose_k is offered.

ghstack-source-id: 60f9963
Pull-Request: #203875

@naromero77amd naromero77amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks for all your hard work.

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

ciflow/inductor ciflow/inductor-rocm-mi300 Trigger "inductor" config CI on ROCm MI300/MI325 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes in progress PR is being worked on by the author, until the automated review accepts it module: inductor module: rocm AMD GPU support for Pytorch topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants