Skip to content

[ROCm] Expose last-level cache size and use read-based benchmark flushing - #203965

Open
Qubitium wants to merge 2 commits into
pytorch:mainfrom
Qubitium:feat/llc-size-upstream
Open

Qubitium wants to merge 2 commits into
pytorch:mainfrom
Qubitium:feat/llc-size-upstream

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Fixes #203964

Ready for triage; no maintainer preapproval claimed.

BC-breaking?

No.

Summary (human written only)

bad timing can cause the wrong kernel to be selected

Agent details (AI-generated with MultiDex)

ROCm properties omit R9700's 64 MiB LLC, so Inductor uses its 8 MiB L2 for cache sizing. Expose last_level_cache_size, size cache flushes for L2 plus a distinct outer cache, and read the ROCm benchmark flush buffer instead of repeatedly writing it. L2_cache_size is unchanged and was never wrong. Equal values still describe one cache, so CUDA, XPU, and the L2 fallback are not counted twice.

ROCm queries HSA's byte-valued cache array through the existing dynamic loader, matches HIP's UUID, and caches results under a mutex. CUDA and unavailable queries return L2. No new link dependency, architecture table, or speculative HIP version gate.

Attribution: the read-flush implementation and initial test are selectively cherry-picked from @jananisriram's #203681, commit c25d83792ca47fdc81d4b0dd901a050b6eb54738. The second commit preserves the original authorship and source SHA. Only flushing is retained; the architecture lookup and additive sizing are omitted. The adaptation also guards the device type and tests event ordering.

Main vs PR

Metric Main behavior* This PR*
L2_cache_size, bytes 8388608 8388608
last_level_cache_size, bytes missing 67108864
Inductor cache-size hint, bytes 8388608 75497472
ROCm benchmark preparation Write buffer Read float32 buffer
Focused Inductor regression suite 21 pass, 5 fail 26 pass

*Base: cba4a42aa487a7222d612ea4f402e857c028d607. Tests load complete main/PR Python modules onto 2.16.0.dev20261025+rocm10.1; properties use that wheel versus a compiled binding of this implementation. These are not full main/PR wheel builds. All four R9700s report the same capacities.

The hint is 72 MiB because the 64 MiB MALL sits behind the 8 MiB L2; evicting only 64 MiB leaves L2 residents. max(L2, LLC) was wrong for this case and is not used.

Timing evidence, not a throughput claim

Same 32 MiB reduction on R9700, run through the complete main/PR benchmarker modules: two trials with reversed implementation order, 100 timed samples each, 10 estimation and 50 preparation iterations. Preparation is outside event timing.

Median kernel timing Main: write 8 MiB PR: read 72 MiB
Trial 1 41.20 us 68.18 us
Trial 2 39.40 us 68.10 us

Interleaved diagnostics on the same GPU, 100 samples per condition per trial: reads of 72 MiB reported 76.04/76.02 us, matching 512 MiB reads at 75.68/75.52 us, while 64 MiB reads reported only 53.62/45.64 us. That gap is why the size is the sum rather than the maximum. Rotating fresh inputs reported 111.4/110.9 us, so a 72 MiB flush is still not guaranteed cold. No end-to-end speedup is claimed.

Relationship to #203681

Comparison against its head c25d83792ca47fdc81d4b0dd901a050b6eb54738:

Concern #203681 This PR
Capacity discovery gfx table; unknown targets use 256 MiB HSA-reported outermost GPU cache beyond L2
Device identity No-argument cached current-device lookup UUID-keyed cache; reordered/mixed devices tested
Missing/ambiguous information Architecture fallback Falls back to L2; does not invent a capacity
Public LLC property Not added Added, with stub and documentation
Consumers Benchmark flush Benchmark sizing and graph input-pool sizing
Flush operation Read via sum() Same read method, credited above; device-type guard added
Hardware evidence Author reports MI350X tuning tests R9700 capacity/preparation checks; no tuning-speedup claim

Our approach makes capacity discovery more robust across heterogeneous or unlisted GPUs while reusing their flush method. Combining their additive helper with this hint would add a 256 MiB table estimate on R9700; this integration uses the reported 72 MiB, with no extra table term.

Validation

  • 26 focused Inductor tests and the public-property test pass. Unmodified main fails five: both larger-LLC cache-size cases, the two pool-size cases that need the sum, and the ROCm read-flush case. Restoring writes alone fails that flush test. Smaller/equal/zero/unknown LLC, overrides, non-ROCm dispatch and timing-event ordering are covered.
  • The compiled binding reports 72 MiB on all four R9700s. 13 new mocked C++ tests plus the existing device test pass: identity/partition ambiguity, failures, units, L4 preference, lifetime, concurrent and repeated reads. Production C++ and its tests are byte-identical to the previously compiled validation inputs.
  • Four R9700s, visibility remapping, 1000 repeated reads and forced library failure checked. HIP/CUDA Module.cpp syntax checks passed. Ruff passes; full spin/lintrunner unavailable locally. No full wheel build or Halo/MI300/MI350 hardware validation.

Related ROCm API work: issue #393, PR #15303. This patch works without that API addition.

@pytorch-bot

pytorch-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

PR Status: missing actionable issue

Auto PR Triage did not find either of the following when it checked this PR:

  • a linked issue labeled actionable (Fixes #<issue> or Part of #<issue>); or
  • a maintainer named in the description who agreed to the change (Supported by @<maintainer>).

Such PRs are a low priority for maintainers to review and might not get a response given the very high volume of PRs we receive. Please focus on actionable issues to ensure a maintainer will be available to review your PR.

If one of these applies, add the matching line to the PR description. If there is no actionable issue for this change yet, you can open one (or comment on an existing one) and wait for a maintainer to label it actionable. Adding actionable to an already-linked issue automatically requests re-triage of open, non-draft PRs with open source and missing actionable issue, unless automated triage is disabled. Adding a valid actionable-issue link or Supported by line to the description also requests re-triage automatically. Marking the PR ready, reopening it, or re-enabling automated triage rechecks existing links and support. If re-triage is still needed, comment @pytorchbot triage to run Auto PR Triage again.

🔗 Helpful Links

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

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:

⚠️ 4 Awaiting Approval

As of commit 3cd61cb with merge base 0d8b367 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@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 8, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Qubitium / name: Qubitium (19a9236, 0dcda88)
  • ✅ login: jananisriram / name: Janani Sriram (19a9236)

@pytorch-bot

pytorch-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

1 similar comment
@pytorch-bot

pytorch-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/inductor
  • ciflow/torchtitan

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@Qubitium
Qubitium marked this pull request as ready for review November 8, 2026 09:57
@Qubitium
Qubitium force-pushed the feat/llc-size-upstream branch from f7e7b7c to 19a9236 Compare November 8, 2026 10:01

Qubitium commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: rocm"

@pytorch-bot pytorch-bot Bot added the release notes: rocm mandatorylabel label Nov 8, 2026
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 8, 2026
Qubitium added a commit to Qubitium/GPTQModel that referenced this pull request Nov 8, 2026
HIP reports no last-level cache: hipDeviceProp_t carries only l2CacheSize and
hipDeviceGetAttribute has no LLC enum. On RDNA3/RDNA4 the 8 MiB L2 figure is
correct but incomplete, because a 64 MiB memory-side cache (Infinity Cache,
aka MALL) sits behind it. Anything that sizes a cache-flush buffer from
L2_cache_size therefore flushes 8 MiB against a 64 MiB cache and measures a
warm cache -- Inductor does exactly that.

Back-port the Python half of pytorch/pytorch#203965:

  * _CudaDeviceProperties.last_level_cache_size -- queries HSA's byte-valued
    cache array through the runtime HIP already loaded (ctypes, no new link
    dependency), keyed by the 16 hex characters HIP stores in hipUUID::bytes,
    cached under a lock, falling back to L2. L2_cache_size is untouched.
  * InductorBenchmarker.get_device_cache_size -- max(L2, LLC), so the flush
    buffer actually covers the outermost cache.
  * BenchmarkRequest/GPUDeviceBenchmarkMixin.do_bench_with_cudagraphs --
    same max() when sizing the rotated CUDA-graph input pool. Located by
    content because the public method on the request classes is an abstract
    stub and the body lives on the mixin.

Applied from gptqmodel/__init__.py immediately after the allocator env vars and
before any other Torch use, so no device property or benchmarker size hint is
cached before the patch exists. Costs ~370 ms on a 5.7 s import; set
GPTQMODEL_NO_ROCM_LLC=1 to skip.

Every patch is idempotent and fails closed: a torch that moved the targeted
expression is left alone rather than rewritten. The PR's read-based ROCm flush
is not back-ported -- the installed Triton path already flushes 256 MiB on
ROCm, and that change only affects reported timing, not kernel selection.
Qubitium added a commit to ModelCloud/GPTQModel that referenced this pull request Nov 8, 2026
…DNA4 HIP decode (#3573)

* feat(nf12_ad): lossless 12-bit BF16 quantization with AlpinDale NF12 kernels + RDNA4 HIP decode

Add NF12-AD as a first-class GPT-QModel method/format (`nf12_ad`), built on
Together AI's NyoomFloat12 lossless 12-bit BF16 format and AlpinDale's
dphnAI/nf12 tiles, CUDA decode and MMA kernels (Apache-2.0, vendored under
gptqmodel_ext/nf12 with the original attribution headers).

Storage and loading
* Weights persist as `qweight` (uint8 [N, K*3/2]) plus `nf12_escapes` and
  `nf12_exp_base`, so checkpoints are never misread as dense BF16 weights.
* No dense weight is retained after a forward; decode scratch is local.

Builds
* libnf12_ad.so and libnf12_ad_torch.so are always JIT-built from the vendored
  sources into a source-hashed cache. No precompiled .so ships in the repo or
  the wheel; MANIFEST.in lists sources only.

RDNA4 (gfx1200/gfx1201/gfx1250)
* New gptqmodel_ext/nf12_hip decodes the identical byte stream to exact BF16
  and runs rocBLAS (SPEC 6.5), since RDNA4 has no mma.sync/wgmma/tcgen05/TMA.
* Re-derived ISA details: v_perm_b32 selector order is reversed vs __byte_perm,
  and hipified .hip TUs only know __hip_bfloat16.
* Sources are staged into the JIT cache before compiling, because torch's ROCm
  loader writes hipify output next to the original sources and would otherwise
  mutate a read-only installed tree.
* Bias is folded with addmm; adding it after the BF16 matmul double-rounds
  (0.0017 rms_rel, 80% exact -> 2e-5, 99.99% exact).

Validation (scripts/validate_nf12_ad.py, full metric tables)
* RTX 4090, RTX 5090, Radeon AI PRO R9700: decode(encode(w)) bit-exact on all
  40 cases per device; fused linear within 1 ULP of the output scale, zero
  violations of |got-ref| <= 2e-3 + 2e-3*|ref|.
* Accuracy is gated on that elementwise bound plus rms_rel and max_rel over
  significant elements; max_rel over all elements diverges near zero and is
  reported but not a gate.
* The harness derives the effective cache size from a residency curve because
  L2_cache_size under-reports RDNA4's Infinity Cache (8 MiB reported, 64 MiB
  real), which otherwise produced >170% of "measured bandwidth" unexplained.

* style(nf12_ad): fix ruff import ordering

Ruff I001 flagged the NF12ADConfig entry in gptqmodel/quantization/__init__.py
and the local imports in tests/test_nf12_ad_codec.py. Pure import-order fix,
no behavior change.

* perf(nf12_ad_hip): fused small-M decode+GEMM for RDNA4

The HIP linear path was decode-then-GEMM only: it materialised a dense BF16
weight on every call and won 0/24 benchmark shapes against BF16 torch.matmul
(best 0.87x, worst 0.39x).

Root cause is traffic, not tuning. For a 4096x4096 matrix decode-then-GEMM
moves 24 MiB packed + 32 MiB dense write + 32 MiB dense read = 88 MiB, while a
BF16 GEMM needs 32 MiB. Decoding the weight once and re-reading it from memory
cannot beat a GEMM that touches a third of the bytes, so no amount of tuning
that route reaches parity.

This adds nf12_ad_linear_fused for m <= 16. Each CTA owns one 16-row output
block and splits K across its eight warps; the decoded super-atom stays in
registers and is reduced against the activation tile with v_dot2_f32_bf16, and
the per-warp partials are summed in fixed warp order in shared memory. Every
token reuses the same decoded super-atom, so the packed weight is read once per
launch and the dense matrix is never built.

Above m = 16 the weight is decoded in row slices sized to at least 1024 rows
(SPEC 6.5; escape indices are absolute so each slice uses the full table).
Smaller slices made the GEMM launch-bound and were measurably worse.

Measured on gfx1201 (R9700), 24 shapes: wins 0/24 -> 13/24, best 0.87x -> 3.10x.
Accuracy is unchanged and now matches the CUDA path: 40/40 codec bit-exact,
0 tolerance violations, worst rms_rel 1.02e-4 (was 1.71e-3).

Two bugs found while validating, both documented in the port README:
- __builtin_amdgcn_fdot2 is FP16, not BF16. It compiles, runs, and returns
  silently wrong values on BF16 data; the BF16 packed dot is
  __builtin_amdgcn_fdot2_f32_bf16 (v_dot2_f32_bf16).
- Bias was added to the already-rounded BF16 result, double-rounding to 1.00
  ULP / 1.7e-3 RMS relative. Folding it into the FP32 accumulator gives
  0.64 ULP and fixes the 1.71e-3 -> 1.02e-4 rms_rel above.

Also fixes an empty-K-slice read that produced NaN when K is short, and an
off-by-grid launch (blocks divided by kWarpsPerBlock), each caught by
per-shape one-hot and multi-CTA tests.

The CUDA path is untouched: RTX 4090 still 19/24, best 3.77x.

* feat(nf12_ad_hip): native HIP encode kernel (byte-identical, 572x faster)

The HIP port only decoded: quantization still called the pure-Torch
`nf12_codec.encode`, so a 4096x4096 weight spent ~665 ms of CPU time in a
GPU-quantization pipeline. Port the CUDA encoder to RDNA4 and route the
quantizer through it.

The CUDA pipeline uses three CUB block primitives and the ROCm SDK here
ships no thrust/CUB, so `scan_kernel` is replaced by a hand-written
block-wide exclusive scan with the same semantics (tile read into
registers before any in-place write, zero padding preserving the sum,
carry advanced by the tile aggregate so `v[n]` is exact). analyze /
count / write port 1:1.

Byte-exactness is the contract: the same `exp_base` (minimum escapes,
ties to the smallest base, matching Python's `choose_exp_base`), the
same packed bytes, and the same escape order (flat group id, atom-major
then lane). Verified against the Torch oracle on 30 shapes x value
classes including 2M-escape worst cases (zeros / extremes):

  shapes   16x64 .. 4096x4096     30/30 exact
  failures                          0

Throughput (R9700 gfx1201, median of 20, end-to-end through
`quantize_nf12_ad_weight`, identical bytes every time):

  shape          CPU codec    HIP encode    speedup
  1024x1024        636.5 ms        0.3 ms    1868x
  4096x4096        809.3 ms        1.4 ms     572x
  11008x4096      1309.0 ms       21.4 ms      61x
  4096x11008      1518.5 ms       20.7 ms      73x

The 11008-row cases are dominated by the 14 ms device-to-host copy of
the packed bytes, not the kernel (which is <1 ms).

The quantizer now prefers the native encoder on any supported device,
including when the weight still lives on the host (staging it is ~1 ms
against ~665 ms of codec work). A forced `exp_base` stays on the codec
because the kernels choose the base themselves, and every failure falls
back to the codec, so results never depend on which route ran.

Also check in the new source: `.gitignore` tracks hand-written `.hip`
files explicitly so hipify output stays untracked, and libnf12_ad.so
continues to be JIT-built from src only (0 tracked .so).

Test suite unchanged: 218 passed, 1 skipped.

* feat(nf12_ad_hip): RDNA4 matrix-core fused path for m=17..128

The decode-then-GEMM route materialises the dense weight, so it moves 88 MiB
for a 4096x4096 matrix where a plain BF16 GEMM moves 32 MiB and the packed
form is 24 MiB. That route lands at 0.36-0.59x of BF16 across the mid-M band.

Add nf12_ad_wmma.hip: each warp decodes one 16x64 super-atom into shared
memory and feeds v_wmma_f32_16x16x16_bf16_w32_gfx12 for every token tile in
flight, so the packed bytes are read exactly once and the dense weight never
exists. Decode is the same bit-exact NF12 decode as nf12_ad_decode, and
accumulation is FP32 in the matrix core, so the route adds no new numerics.

  * kMt (token tiles per CTA) is a template parameter chosen from M, so M=32
    runs a 2-tile kernel instead of paying for 8 tiles of matrix-core work.
    A runtime n_tiles loop defeated unrolling and measured 3-5x slower.
  * Split-K over grid.z uses disjoint K slices and separate FP32 partial
    planes; a reduce kernel sums them and rounds to BF16 exactly once.
    Atomics measured 2.6-3.8x slower. The partial workspace is cached per
    process because per-call hipMalloc/hipFree cost +110 us at m=32.
  * Split count is picked from the CTA count, not M: splitting pays only
    below ~1.2 waves (32 CTAs on 32 CUs) and loses at N=11008 (86 CTAs).

Accuracy: 0 violations over 21 shapes, rms_rel ~1.66e-3 (the BF16 rounding
floor) against an FP64 oracle, gate |err| <= 2e-3 + 2e-3*|ref|.

gfx1250 has no wmma-128b-insts, so the file compiles to an empty translation
unit there and the dispatcher keeps the decode-then-GEMM route. The arch test
is a runtime gcnArchName check: __gfx1201__ is defined only during the device
pass, so a host-side guard on it silently reported "unsupported".

Credit: format and spec from Together AI ("NyoomFloat12"); reference CUDA
kernels, tiled layout and escape coding from dphnAI/nf12 by AlpinDale
(Apache-2.0). The HIP port is a reimplementation for AMD, not a transliteration.

* test(nf12_ad): validate the native HIP encoder instead of reusing CPU bytes

The HIP branch of the accuracy table fed the Torch codec's packed bytes into
the GPU decoder and hard-coded bytes_match/escapes_match to True, so the
native analyze/scan/write encoder was never checked by the validator. Call
hip.encode() and compare packed bytes, escapes and the decode round-trip
against the reference codec, matching what the CUDA branch already does.

* perf(nf12_ad_wmma): double-buffer the decoded super-atom

Decoding into the idle shared buffer while the busy one is consumed removes
the barrier between the store and the first matrix-core read, so the decode
ALU overlaps the wmma issue instead of serialising with it.

Bit-identical output (verified by checksum against the single-buffer kernel
on gfx1201 at m=17/32/64 for N=4096 and N=11008) and 1-4% faster: 60.2 ->
57.9 us at 4096x4096/m=64, 120.2 -> 118.8 us at 11008x4096/m=64.

Two 2 KiB buffers per warp is 32 KiB per CTA, which still admits four CTAs
per 128 KiB CU on this part.

* perf(nf12_ad_wmma): gate double buffering on tile count

The second shared buffer is not free. It raised VGPR use from 67-167 to a
flat 169-188 and LDS from 16 KiB to 32 KiB per CTA, which halved the resident
CTA count per CU. At kMt=8 that made m=128 at N=11008 regress 184 -> 289 us.

Make kDbl a template parameter and enable it only for kMt <= 6, where the
extra parallelism still pays. Each tile count instantiates exactly one
variant, so the kernel count is unchanged (24).

Measured on gfx1201, standalone kernel, bit-identical checksums at every
shape (m=17..128, N=4096 and N=11008):

  4096x4096:   m=17 49.1->48.4  m=32 52.0->51.2  m=64 59.6->57.6
               m=96 72.4->68.3  m=128 82.1->82.1 (single-buffer path)
  11008x4096:  m=17 111.7->111.2  m=64 119.9->117.5  m=96 140.8->138.5
               m=128 182.9->181.4

* feat(rocm): expose the AMD last-level cache to torch at import time

HIP reports no last-level cache: hipDeviceProp_t carries only l2CacheSize and
hipDeviceGetAttribute has no LLC enum. On RDNA3/RDNA4 the 8 MiB L2 figure is
correct but incomplete, because a 64 MiB memory-side cache (Infinity Cache,
aka MALL) sits behind it. Anything that sizes a cache-flush buffer from
L2_cache_size therefore flushes 8 MiB against a 64 MiB cache and measures a
warm cache -- Inductor does exactly that.

Back-port the Python half of pytorch/pytorch#203965:

  * _CudaDeviceProperties.last_level_cache_size -- queries HSA's byte-valued
    cache array through the runtime HIP already loaded (ctypes, no new link
    dependency), keyed by the 16 hex characters HIP stores in hipUUID::bytes,
    cached under a lock, falling back to L2. L2_cache_size is untouched.
  * InductorBenchmarker.get_device_cache_size -- max(L2, LLC), so the flush
    buffer actually covers the outermost cache.
  * BenchmarkRequest/GPUDeviceBenchmarkMixin.do_bench_with_cudagraphs --
    same max() when sizing the rotated CUDA-graph input pool. Located by
    content because the public method on the request classes is an abstract
    stub and the body lives on the mixin.

Applied from gptqmodel/__init__.py immediately after the allocator env vars and
before any other Torch use, so no device property or benchmarker size hint is
cached before the patch exists. Costs ~370 ms on a 5.7 s import; set
GPTQMODEL_NO_ROCM_LLC=1 to skip.

Every patch is idempotent and fails closed: a torch that moved the targeted
expression is left alone rather than rewritten. The PR's read-based ROCm flush
is not back-ported -- the installed Triton path already flushes 256 MiB on
ROCm, and that change only affects reported timing, not kernel selection.

* docs(nf12_ad_hip): document the matrix-core route and the LLC regime

The README still said the wmma path "is not implemented here", described only
two routes, and quoted a 0.36-0.59x range without saying which cache regime it
came from.

Rewrite it around the three routes that actually exist, add the encoder, and
record the measured fragment map, the kMt/split-K/double-buffer rationale, and
both performance regimes with the cache geometry that explains them:

  * 11008x4096 wins 1.30-1.44x warm and 1.16-1.18x cold for m=17..96, at
    ~640 GB/s against a measured 633 GB/s HBM read ceiling.
  * 4096x4096 loses warm because the 32 MiB BF16 weight is LLC-resident at
    ~1.4 TB/s, so a 1.33x traffic saving cannot pay for the decode.
  * m=128 loses because the CTA already covers 128 tokens and the kernel turns
    matrix-core bound; nf12_ad_wmma_max_m() hands larger M to rocBLAS.

Also note that torch's 8 MiB L2_cache_size is correct (not a bug) and that the
64 MiB outermost cache is now exposed by gptqmodel.rocm_llc.
@Qubitium
Qubitium force-pushed the feat/llc-size-upstream branch 3 times, most recently from 55c5a4e to acdc68f Compare November 8, 2026 11:54
Qubitium and others added 2 commits November 24, 2026 03:21
ROCm device properties omit cache levels beyond L2, leaving both Inductor
sizing paths at 8 MiB on R9700 despite its 64 MiB memory-side cache.
Expose last_level_cache_size through an optional UUID-matched HSA query,
fall back to L2, and size cache flushes for both L2 and a distinct outer
cache. The existing L2 value and semantics remain unchanged.

Authored with MultiDex at the contributor's direction.

Test Plan:
Focused tests load full source modules onto the installed ROCm wheel;
the property test loads a compiled binding, not a full rebuilt wheel.
21 Inductor cases and the public property test pass, and the compiled
binding reports the expected 72 MiB hint on R9700.

```sh
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/run_focus.py
PYTHONPATH=/root/llc-torch/agent_space/test_deps /opt/venvs/rocm101t/bin/python /root/llc-torch-upstream/agent_space/check_72.py
```

The 13 new C++ tests and existing device test pass. Production C++ and
test sources are identical to the previously syntax-checked and compiled
inputs. Ruff passes; lintrunner is unavailable in this environment.
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]>
@Qubitium
Qubitium force-pushed the feat/llc-size-upstream branch from acdc68f to 3cd61cb Compare November 24, 2026 03:37

This branch was previously deployed

1 inactive (outdated) deployment
bedrock — f7e7b7cc Deployed Nov 8, 2026 by pytorchbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests missing actionable issue A PR without a linked actionable issue or maintainer sponsor module: inductor module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ROCm] Missing last-level cache property leaves Inductor sizing at L2 on R9700

3 participants