Repository navigation
[Inductor][ROCm] Flush L2 + Infinity Cache with a read in InductorBenchmarker - #203681
jananisriram wants to merge 10 commits into
Conversation
[ghstack-poisoned]
PR Status: in progressPlease 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:
Findings (9): Reviewed commit: 🔗 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 SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 12 New Failures, 6 Unrelated FailuresAs of commit 9e4ebe3 with merge base 4976eb3 ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: 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:
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. |
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
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
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]>
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]>
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]>
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]
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
[ghstack-poisoned]
@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. |
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]
…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 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
… per partition) [ghstack-poisoned]
…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 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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
… if the Triton read flush fails [ghstack-poisoned]
…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 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
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.
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) > 0, or at least using one pass when the MALL is 0.
pytorch/test/inductor/test_benchmarking.py
Line 911 in f799e2f
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").
pytorch/test/inductor/test_benchmarking.py
Line 856 in f799e2f
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 |
There was a problem hiding this comment.
🔴 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.
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
| "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 |
There was a problem hiding this comment.
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 equivalentIn _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),There was a problem hiding this comment.
I've a question: What stops us from uniformly flushing 2G data, which also avoids leaking of cache information unnecessarily. @naromero77amd
There was a problem hiding this comment.
[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 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…ct from the arch [ghstack-poisoned]
…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 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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]>
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
left a comment
There was a problem hiding this comment.
LGTM, thanks for all your hard work.
Stack from ghstack (oldest at bottom):
On ROCm,
InductorBenchmarkerflushes onlyL2_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 largerzero_()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
sumover a 128 MiB operand after each flush.zero_()flush: 57.8 usAutotune 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.
do_benchThe 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:
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