Skip to content

v6e GEMM: 23 of 62 shapes are more than 20% off the TPU -- find the cause of each region #347

Closed

Description

@student-Jungmin

Summary

torch.matmul(a, b) (a: M x K, b: K x N, fp16) simulated on the tpuv6e config is compared with the same op measured on a real TPU v6e through torch_xla. After the fixes listed below the two agree on large shapes, but 23 of 62 representative shapes are still more than 20% off, and the misses are not random: they sit in three regions of the table. This issue asks for the cause of each region. It is written so that someone with no context from the earlier work can pick it up.

Mean absolute percentage error over the 62 shapes is 20.4% (it was 59.6% before the fixes); 44 of 62 are within 25%.

What is compared

  • TPU side: tpu-perf-archive/data/v6e/gemm/torchxla.csv, column latency_ns (per-step median, torch_xla, cross-program prefetch ON, the default). 230 shapes; the 62 used here are 7 layers (K x N) times every M the table has.
  • Simulator side: one torch.matmul through torch.npu.launch_model, config systolic_ws_256x256_c1_simple_noc_tpuv6e_timing_only.yml with l2d_type: nocache as the only change (v6e has no L2 data cache). sim_ns = total cycles / 3.502 (core at 3502 MHz).
  • The number below is sim_ns / TPU latency_ns. 1.00 is a match, below 1 the simulator is faster than the TPU.

Stack that produced the table

piece commit note
PyTorchSim (this repo) ee5f8a4, branch shared-load-tag = pytorchsim-triton-backend c9a279b + #346 (open)
PyTorchSim-Triton-Backend 9252bab, branch dma-live-extent = main 6942cfc + PyTorchSim-Triton-Backend#57 (open)
gem5 / Spike vcix-accelerator 7586e23 (gem5 vcix-v0.3.2, Spike 751354f)

Already merged and therefore in the table: PyTorchSim-Triton-Backend#54 (a stream walks only the live subtiles of a masked block), #341 (systolic_array_split on by default, unit table from gem5), #342 (a 1 x K row times a matrix runs as vector work), #343 (the mm tile budget counts C as the kernel holds it).

Result: sim / TPU

M 384x1152 768x768 768x3072 2048x2048 2048x3072 3072x768 4096x4096
1 1.05 0.82 1.25 0.72 1.13 1.44 1.91
32 0.37 0.36 0.72 0.77 0.90 0.58 0.96
128 0.44 0.42 0.71 0.84 0.91 0.63 0.97
256 0.53 0.50 0.70 0.79 0.86 0.69 n/a
512 0.63 0.57 0.89 0.83 0.87 0.89 0.91
1024 0.76 0.72 0.98 0.81 0.87 0.88 0.97
2048 0.96 0.81 1.11 0.94 1.01 0.99 0.98
4096 1.07 0.96 1.25 1.03 1.11 0.99 1.05
8192 1.19 1.01 1.19 1.01 1.05 0.83 1.03

Bold = more than 20% off. 256x4096x4096 is n/a because its TPU row is not status == ok.

range shapes MAPE median sim/TPU within 25%
M = 1 7 32.0% 1.13 4
M = 32..256 20 31.7% 0.70 8
M = 512..1024 14 17.3% 0.87 11
M >= 2048 21 7.9% 1.01 21

19 shapes are below 0.8, 4 are above 1.2.

The 23 shapes more than 20% off

TPU columns are from the profiler breakdown in the same CSV (ns): compute_us, prefetch_wait_us, other_ops_us, module_gap_us.

M x K x N sim cycles sim ns TPU ns sim/TPU TPU compute TPU prefetch wait TPU other ops TPU gap path
32 x 384 x 1152 3925 1121 2995 0.37 1349 1290 0 313 mxu
128 x 384 x 1152 5090 1453 3324 0.44 1705 1287 0 313 mxu
256 x 384 x 1152 7091 2025 3853 0.53 2230 1286 0 313 mxu
512 x 384 x 1152 10508 3001 4744 0.63 3139 1284 0 301 mxu
1024 x 384 x 1152 17279 4934 6506 0.76 4911 1284 -0 299 mxu
32 x 768 x 768 4128 1179 3235 0.36 1411 1467 0 315 mxu
128 x 768 x 768 5272 1505 3574 0.42 1755 1477 0 313 mxu
256 x 768 x 768 7010 2002 4006 0.50 2230 1470 0 289 mxu
512 x 768 x 768 9976 2849 4986 0.57 3210 1467 -0 299 mxu
1024 x 768 x 768 16850 4812 6686 0.72 4640 1738 0 291 mxu
1 x 768 x 3072 31305 8939 7152 1.25 5788 0 1039 322 vpu_reduce
32 x 768 x 3072 15274 4362 6071 0.72 1990 3733 -0 315 mxu
128 x 768 x 3072 17123 4889 6924 0.71 2869 3727 0 295 mxu
256 x 768 x 3072 20303 5798 8246 0.70 4213 3733 -0 296 mxu
4096 x 768 x 3072 159917 45664 36560 1.25 31524 4731 0 306 mxu
1 x 3072 x 768 31258 8926 6216 1.44 4816 0 1050 322 vpu_reduce
32 x 3072 x 768 12498 3569 6155 0.58 2068 3745 0 319 mxu
128 x 3072 x 768 15245 4353 6931 0.63 2889 3737 -0 290 mxu
256 x 3072 x 768 20195 5767 8334 0.69 4277 3736 -0 315 mxu
1 x 2048 x 2048 20163 5758 8031 0.72 6614 0 1061 321 vpu_reduce
32 x 2048 x 2048 24340 6950 9005 0.77 2619 6058 0 316 mxu
256 x 2048 x 2048 33022 9429 11864 0.79 5502 6046 -0 315 mxu
1 x 4096 x 4096 160883 45940 24096 1.91 22644 0 1100 319 vpu_reduce

The three regions

A. Small M on the MXU path: the simulator is too fast (19 shapes, 0.36 .. 0.79). Worst on the small layers (384x1152, 768x768) and getting better as M grows. Also the whole 3072x768 and 768x3072 columns for M <= 256.

B. M = 1 (vector path): mixed. 1x4096x4096 is 1.91, 1x3072x768 is 1.44, 1x768x3072 is 1.25, but 1x2048x2048 is 0.72.

C. 768x3072 at large M: the simulator is too slow (4096: 1.25, and 2048 / 8192 at 1.11 / 1.19 just under the line).

What is already known

These are measured facts; the interpretation after each is marked as such.

  1. Per-row cost matches, the constant does not (region A). Fitting latency against M for M = 32..512:

    layer ns per row of M intercept at M = 0
    384x1152 TPU 3.67 2878 ns
    simulator (before Conv Bias fined grained DMA #57 / [TOGSim] A load of what a buffer already holds is not read again #346) 3.84 1164 ns
    768x768 TPU 3.65 3104 ns
    simulator (before Conv Bias fined grained DMA #57 / [TOGSim] A load of what a buffer already holds is not read again #346) 3.24 1182 ns

    Adding a constant 1.5 us to every MXU shape of that earlier sweep took the small-layer MAPE from 44% to 8%. Interpretation: a fixed per-op cost of roughly 1.7 .. 1.9 us is missing. The fit has not been redone on the current stack.

  2. What one TPU step looks like in the raw trace (32x768x768, steady-state step, ns from step start):

    event start duration
    lead-in, no event 0 313 constant over M
    copy-start 313 12 starts the prefetch of W (1.18 MB)
    copy-done 326 1441 blocks until W has landed
    fusion (convolution fusion) 1769 1531 the only event that grows with M
    • The compute is one trace event; nothing inside it is visible. Its memory_access_breakdown shows it reads x from HBM, takes the prefetched W and writes y back, so the TPU's "compute time" includes moving the input and the output.
    • fusion starts 1.1 ns after copy-done ends, in every step: the prefetch does not overlap the compute.
    • Every op has a floor of about 0.44 .. 0.57 us (a reshape of 1.5 KB takes 435 ns).
    • The optimized HLO carries estimated_cycles for the fusion: 4821 / 5452 / 6580 for M = 32 / 128 / 256 on 768x768, about 4600 at M = 0. The compiler itself predicts the fixed part.
    • TPU compute intercept by layer, in cycles at 3502 MHz: 4441 (384x1152), 4809 (768x768), 6306 (768x3072), 6444 (3072x768), 6935 (2048x2048), 8450 (2048x3072), 15344 (4096x4096). That is about 4500 + 42 per 256x256 weight subtile, so it is not one array traversal (511 cycles) per subtile.
    • The trace states no clock, core count or number of MXUs.
  3. Which operand the TPU prefetches (all 237 traces): never more than one. On the MXU path it is the larger of x and W in 198 of 210 traces; the 12 exceptions all have a 128 MB operand, which is not prefetched. M = 1 has no prefetch at all.

  4. Prefetch off makes the TPU faster on most shapes. An earlier JAX run (2026-09-28, --xla_msa_max_cross_program_prefetches=0) measured 43 shapes with prefetch on and off: 34 are faster with it off, typically 7 .. 20%, up to 31% (512x4096x4096). Against that off table the current simulator has a median ratio of 1.01 on the 23 shapes that overlap, MAPE 21.6%. Which of the two TPU tables is the right reference is not settled; the request from the user is to compare against prefetch off, and the off table does not cover the small layers where region A is worst.

  5. Region C, read from a TOGSim trace of 8192x768x3072 before Conv Bias fined grained DMA #57 / [TOGSim] A load of what a buffer already holds is not read again #346. The four M tiles each re-read all of W, and the array sat idle 54,000 of 320,825 cycles waiting for the third tile's copy of W, which shared the DRAM with the second tile's 12.6 MB store. [TOGSim] A load of what a buffer already holds is not read again #346 removed the re-read (309,622 -> 269,075 cycles). What is left of the gap on this column has not been broken down again.

  6. Region B, 1x4096x4096. The reduce node is 1081 cycles while the vector unit is busy 11% of the run and Issue 1.6%: most of the node is neither unit working. Interpretation, not checked in the IR: the sum over K is lowered as a serial chain of dependent adds, so it is latency bound. 1x2048x2048 being fast (0.72) looks like region A's missing constant: the TPU spends 1.0 us in two extra ops (reduce + reshape) plus a 0.3 us lead-in.

  7. systolic_array_split and small layers. With the split on, a node whose rows exceed 256 is shortened as if it ran on both arrays. The TPU's compute slope per row per weight subtile is 1.25 .. 1.27 cycles on the two small layers and falls to 0.58 on 4096x4096. Turning the split off moves 1024x768x768 from 0.72 to 0.85 and leaves 32x768x768 at 0.36, so it explains part of region A at mid M and none of it at small M. The trace cannot confirm how many MXUs a small op uses.

Tried and dropped

  • Cutting A, B and C into one transfer per 256 subtile and tracing the stream as stretches that each wait for their own pieces. Functionally fine (Spike matches), but on the shapes that finished the error rose (prefetch-on MAPE 32.7% -> 39.6% over 52 shapes): small shapes got faster still, and wide-weight shapes got much slower for a reason that was not found (32x4096x4096: 97,345 -> 162,136 cycles with the same bytes moved and the same DMA-active cycles). Reverted; nothing of it is on any branch.
  • Trying more autotune block candidates (14 instead of 4): at most 5% better on one shape, nothing on the others.
  • Lifting Triton's power-of-two block constraint: not possible below the Python check, TTGIR linear layouts cannot express a dimension like 384.

What to find out

  1. Region A: what the fixed ~1.8 us on the TPU physically is, and whether the simulator should model it (and where: per kernel launch, per DMA, per compute). Start from the lead-in (0.3 us), the prefetch's fixed part (~0.73 us at zero bytes) and the fusion's intercept (~1.28 us). Lay the simulator's own timeline of 32x768x768 next to the TPU's table above, phase by phase, before proposing a constant.
  2. Region A, mid M: whether a small op should be split over both arrays at all (item 7).
  3. Region B: confirm or refute the serial-chain reading of the M = 1 reduce in 09-custom.mlir, and explain why 768x3072 / 3072x768 / 4096x4096 are slow while 2048x2048 is fast.
  4. Region C: re-break down 4096x768x3072 and 8192x768x3072 on the current stack. This layer's output (N = 3072) is large and its block is padded to 4096.
  5. Reference: decide between the prefetch-on and prefetch-off TPU tables. If off, the 62 shapes need a TPU re-measurement with --xla_msa_max_cross_program_prefetches=0.

Please report each cause with the measurement that shows it, and say so when something is an inference.

How to reproduce

On the measurement machine (/opt/torchsim-local):

cd /opt/torchsim-local/run/sim_v6e_hw
source /opt/torchsim-local/run/fe-main-env.sh      # frontend clone run/fe-split + PTB checkout + gem5/Spike of vcix 7586e23
# one shape, keeps its dump:
TOGSIM_CONFIG=$PWD/configs/tpuv6e_default_nocache.yml python sim_gemm.py 32 768 768
# the 62 shapes (10 in parallel, resumable, results_<tag>.csv):
python run_all.py --tag <tag> --jobs 10 --config configs/tpuv6e_default_nocache.yml \
    --kn 384x1152,768x768,768x3072,3072x768,2048x2048,2048x3072,4096x4096
  • Launch long sweeps with (setsid nohup ... &); a plain background job dies with the session.
  • A TOGSim timeline of one kernel: run TOGSim/build/bin/Simulator --config <yml> --trace_so <launch dir>/trace.so --cycle_table .../trace_cycles.tsv --unit_table .../trace_units.tsv --log_level trace on the launch-* directory a run leaves in its dump.
  • run/fe-split and the PTB checkout must sit on the commits in the stack table, with TOGSim rebuilt (cd TOGSim/build && make).

Where the data is (measurement machine)

what path
this table's simulator results run/sim_v6e_hw/results_t43_shared_c9a279b_57.csv, logs in out_t43_shared_c9a279b_57/
the sweep before #57 / #346 run/sim_v6e_hw/results_t42_77b3a87_29470ec.csv
TPU table (prefetch on) tpu-perf-archive/data/v6e/gemm/torchxla.csv, columns in data/v6e/gemm/README.md
TPU raw traces tpuv6e-gemm-torchxla/profiles/tb.tar.xz
trace analysis already done run/tpu_trace_probe/ (timelines.txt, more.txt, est_cycles.csv, scripts/)
TPU prefetch on / off (JAX) /workspace/tpuv6e_validation/data/JM_20260928_gemm_nocpp/shard_0/{on,off}/xla.csv, flag in flag.txt
per-shape sim / TPU breakdown script run/sim_v6e_hw/probe/t42_break.py (edit the results file name)

Conventions used so far

  • The comparison is judged on these 62 shapes, not the full 230.
  • Latency is the per-step median.
  • Error is the mean of |sim - TPU| / TPU.

Activity

  1. student-Jungmin commented on Oct 12, 2026

    @student-Jungmin
    CollaboratorAuthor

    Update: both open PRs the table depends on are merged.

    piece now
    PyTorchSim pytorchsim-triton-backend aaa3ee8 (#346 merged; same tree as shared-load-tag ee5f8a4)
    PyTorchSim-Triton-Backend main a9fa3ea (PyTorchSim-Triton-Backend#57 merged; same tree as dma-live-extent 9252bab)

    So the table reproduces from the two default branches. PyTorchSim-Triton-Backend#60 (open) moves that repository's third_party/PyTorchSim pin to aaa3ee8; it only matters for the compiler's own tests, the frontend runs use this repository's TOGSim.

  2. student-Jungmin commented on Oct 12, 2026

    @student-Jungmin
    CollaboratorAuthor

    Region A: why the simulator is fast at small M -- cause found

    In one line: the simulator charges nothing for starting a kernel, a DMA or a compute node; the TPU pays about 2.4 us of such costs per op. Moving bytes and pushing rows are not faster in the simulator -- they are slightly slower. At large M the work is tens of us and the 2.4 us is buried; at small M the work is ~1 us and the 2.4 us is the whole gap. The ratio climbing from 0.36 (M = 32) to 0.76 (M = 1024) is that dilution, not the model getting better.

    Phase by phase, 32x768x768 (TPU 3235 ns, simulator 1179 ns)

    TPU side from the profiler trace (step 484; the device trace holds exactly four events in the step: dependency-wait 0.1 ns at 1.3 ns, copy-start 12 ns at 313 ns, copy-done 1441 ns, fusion 1531 ns; nothing is nested inside any of them). Simulator side from a TOGSim --log_level trace replay of the kernel (block (32, 512, 1024), two programs; run/sim_v6e_hw/probe/why_32x768x768/).

    phase TPU simulator why the simulator is shorter
    start 313 ns, no event 1 ns TOGSim schedules the tile at cycle 1 and issues the first instruction at cycle 2; there is no launch
    fetch W (per 768 KB) 732 + 486 = 1218 ns 626 ns bytes move at about the same rate (TPU 1.58 TB/s, simulator 1.23 TB/s); the difference is the TPU's 732 ns per copy op, while the simulator issues a DMA in one cycle and sees the first response 145 cycles (41 ns) later
    compute (32 rows x 8 subtiles) 1391 + 99 + 105 = ~1600 ns 846 ns (both programs) per row the simulator is slower (3.7 vs 3.3 ns/row); the difference is the TPU's ~1.4 us per compute op, while the simulator's node starts the cycle after its barrier releases and its length is gem5's measurement of the kernel body alone
    store inside the fusion 27 ns
    total 3235 1179

    Take the TPU's three start costs out (313 + 732 + 1391 = 2436 ns) and about 800 ns of work remains -- less than the simulator's 1179 ns.

    The same thing over the whole small-layer region

    Fit over M = 32..1024 on the current stack (ns = slope x M + intercept):

    layer ns per row intercept at M = 0
    384x1152 TPU 3.54 2903
    simulator 3.86 1001
    768x768 TPU 3.49 3133
    simulator 3.66 1042

    Slopes agree within 5-9% (simulator slower); intercepts differ by 1.9-2.1 us for every M. TPU - simulator over the 20 shapes with M <= 256 is 1.83-2.07 us on the two small layers and 0.9-2.6 us on the wide ones (there the simulator's higher per-row cost offsets part of it).

    What the TPU's cost is, and what it is not

    Checked against the alternatives, because "a constant" is the shape of the evidence, not a mechanism:

    1. Not a bandwidth ramp on small transfers, not per-tile / per-descriptor cost. Over all 186 MXU traces, prefetch_wait = 732 ns + bytes / 1.58 TB/s, residuals within +-15 ns from 0.28 MB to 70 MB; adding the operand's rows and columns as regressors gives coefficients of 0.001-0.002 ns.
    2. Not weight size. The compute intercept over 24 layers is 1391 ns + 11.0 ns per 256x256 weight subtile (the 11 ns/subtile is 128 KB at ~12 TB/s, i.e. VMEM-to-MXU weight streaming -- an inference). For a 9-subtile layer that part is 99 ns; the 1.39 us remains.
    3. Not memory latency. With cross-program prefetch off (JAX run of 2026-09-28), the W copy folds into the fusion and the total drops by only 0.47-0.72 us on the 8 MB-weight shapes at M <= 256, while the copy had been 6.0 us: the bytes still cost 5.3 us inside the fusion and what disappears is the 732 ns copy op. So it is the cost of dispatching and synchronising an op, not of moving its bytes.
    4. Every HLO op has such a floor. On the M = 1 path a 1.5 KB reshape takes 435 ns and a reduce 569 ns. The MXU fusion's 1.39 us is that per-op floor plus ~0.9 us more that only the MXU op has (pipeline fill, weight latch, result drain -- not separable in the trace).
    5. The XLA compiler's own estimated_cycles on the fusion extrapolates to ~4600 cycles at M = 0, so the compiler's cost model carries the same fixed part.

    So the precise statement is: per HLO op about 0.5 us, per MXU op about 1.4 us, per separate async copy op about 0.73 us (with prefetch on), plus 0.31 us per step before the first op -- all paid once per op regardless of size. In TOGSim all four are zero: the kernel issues at cycle 2, a DMA costs one issue cycle plus 10 icnt cycles and the DRAM latency, a compute node starts the cycle after its barrier, and the gem5 sample measures the kernel body only. There is no config knob for any of them (icnt_latency_cycles and the DRAM latency are the only latencies in the yaml).

    What this does and does not settle

    • It settles the cause of region A. Adding one constant of 1.8-2.0 us to every MXU shape would take M = 32..256 from 31.7% to 4-5% MAPE and M = 512..1024 from 17.3% to 5%; the 62-shape MAPE would go from 20.4% to about 12%.
    • It does not settle how to model it: per kernel, per DMA op, per compute node, or per HLO-op-equivalent -- and whether a different NPU should pay these costs at all is a design question, not something the trace can answer. Whether they are hardware or XLA runtime is also not separable in the trace.
    • With that constant in, the M >= 2048 shapes get worse (7.9% -> ~11%): they are near 1.0 today because the simulator's higher per-row cost on wide layers (768x3072: 10.7 vs 8.8 ns/row) cancels the missing start costs. That per-row excess is region C's problem and stays separate.
    • One more thing the prefetch-off data shows, relevant if the off table becomes the reference: for large W (3072x3072, 4096x4096) turning prefetch off saves 2-15 us, far more than the 0.73 us copy op -- the TPU then overlaps reading W with computing. The simulator waits for all of W before its matmul node starts, so structurally it resembles the prefetch-on TPU; matching the off table would need that overlap modelled (the subtile-transfer attempt listed under "tried and dropped" was aiming at it).

    Reproduce

    cd /opt/torchsim-local/run/sim_v6e_hw && source /opt/torchsim-local/run/fe-main-env.sh
    ./probe/why_run.sh 32 768 768          # keeps the dump under probe/why_32x768x768/
    # TOGSim timeline of the kernel it left:
    L=$(ls -d probe/why_32x768x768/dump/triton_*/launch-* | head -1)
    /opt/torchsim-local/run/fe-split/TOGSim/build/bin/Simulator --config $PWD/configs/tpuv6e_default_nocache.yml \
      --trace_so $L/trace.so --cycle_table $L/trace_cycles.tsv --unit_table $L/trace_units.tsv --log_level trace
    # the TPU step's events: run/tpu_trace_probe/timelines.txt (32x768x768, step 484) or the raw trace under run/tpu_trace_probe/x/
    
  3. student-Jungmin commented on Oct 12, 2026

    @student-Jungmin
    CollaboratorAuthor

    Decision on item 5: the reference is the prefetch-ON table

    The torch_xla table (tpu-perf-archive/data/v6e/gemm/torchxla.csv, cross-program prefetch on, the default) stays the reference. No TPU re-measurement with prefetch off, and the prefetch-off comparison above is informational only.

    Items 3 (M = 1) and 4 (768x3072 at large M) are being worked on next; item 2 (split on small layers) waits on how item 1's start costs get modelled.

  4. student-Jungmin commented on Oct 12, 2026

    @student-Jungmin
    CollaboratorAuthor

    Items 3 and 4: causes found

    Method for both: run the shape with its dump kept (run/sim_v6e_hw/probe/why_run.sh M K N), replay the kernel in TOGSim with --log_level trace, extract per-work-item phases (probe/tile_phases.py <timeline> <raw log>), and replay the same trace on dram_type: simple (configs/tpuv6e_default_nocache_simpledram.yml) to separate the DRAM model from the rest. Logs under run/npot_probe/why_*.

    Item 3: M = 1 (vector path)

    The kernel after #342 is Inductor's reduce kernel: XBLOCK = 256 columns of N per program, R0_BLOCK = K (whole K at once), N / 256 programs. Per program: a load of x as a [256, K] tile with stride 0 on the lane axis (256 copies of the 8-16 KB row, 2 MB for K = 4096; skipped after the first program by #346), the W column block [256 cols x K rows] (fp16: 512 B contiguous per K row, rows 2N bytes apart), then K / 128 chunk nodes of 24 + 46 cycles (convert, multiply, accumulate into a 128-wide vector carried through the loop), a final 128 -> 1 reduce node (517 .. 1081 cycles), and a 512 B store. The accumulate loop is a serial chain through the loop-carried accumulator (confirmed in 09-custom.mlir: affine.for ... iter_args with arith.addf on the carried value).

    shape sim/TPU total cycles on simple DRAM DMA active per-program compute (serialized)
    1x4096x4096 1.91 160,883 66,472 41% 16 x 3,321 = 53k
    1x3072x768 1.44 31,258 30,540 39% 3 x 8,730 = 26.2k
    1x768x3072 1.25 31,305 30,521 39% 12 x 2,437 = 29.2k
    1x2048x2048 0.72 20,163 16,919 81% 8 x 1,764 = 14.1k

    (a) 1x4096x4096 is slow because ramulator serves the strided W-block read at half rate. All 32 channels are active, but each channel returns 1,472 reads per 200-cycle interval (825 GB/s total) against 2,928 (1,641 GB/s, the peak) for 1x2048x2048. The W block is 512 B chunks at 8 KB stride (4 KB for 2048). The same trace on the simple DRAM model takes 66,472 cycles (sim/TPU would be 0.79). Changing the address mapper does not help (MOP4CLXOR: 164,377; ChRaBaRoCo: 2,932,834), so it is not the mapper choice; what inside the HBM3 model halves the per-channel rate at this stride was not pinned down. The TPU never issues this pattern: its W is stored tiled (T(8,128)), so a 256-column block is contiguous.

    (b) 1x3072x768 and 1x768x3072 are bound by the serial reduce chain, not by DRAM. Simple DRAM changes them by 2%. Computes run one at a time per core, programs after each other, so the serialized compute alone (26.2k / 29.2k cycles) exceeds the TPU's whole op (21.7k / 25.0k cycles at 3502 MHz). Per MAC that is 81-90 MACs/cycle against the TPU's ~140 (2.36 M MACs in 4.8 us of compute); the vector unit is busy only 23% of the run, the rest of each node is latency (spad load, convert, mul, add on the carried value), i.e. the chain is latency bound as suspected.

    (c) 1x2048x2048 at 0.72 is region A: it runs at DRAM peak (DMA active 81%, 1,641 GB/s), and the gap is the TPU's start costs (three ops at ~0.5 us each plus the 0.3 us lead-in).

    Secondary, measured but small: the broadcast x load is materialized as a [256, K] DRAM read (2 MB for 8 KB of data, 4,650 cycles once per kernel on 4096); and one work-item is dispatched last instead of in order (block 3 of 12 on 1x768x3072; subgraphs 1 and 3 of 16 on 1x4096x4096), so its load and compute run alone at the end (about one program's time). Where TOGSim reorders it was not found in TileGraph::allocate_subgraph / refill.

    Item 4: 768x3072 at large M (4096: 1.25, 8192: 1.19)

    Block (2048, 4096, 1024), one M tile per 2048 rows (2 / 4 tiles). Per tile: A 3 MB; W 4.7 MB once (shared by #346); matmul node sampled at 80,381 cycles, 43,517 under the split; vector nodes 3,912 (accumulator init) + 6,549 (fp32 -> fp16 convert); store of C 2048 x 3072 fp16 = 12.6 MB.

    Timeline of 4096x768x3072 (159,917 cycles = 45.7 us; TPU 36.6 us = 128k cycles, of which compute 110k, prefetch 16.5k):

    cycles what note
    0 - 24k A0, W, A1 loads queue on the one DMA engine; array idle TPU's prefetch is 16.5k
    24k - 74k tile 0: matmul 43.5k + vector 10.5k
    74k - 124k tile 1: the same; tile 0's store overlaps it
    124k - 160k tile 1's store, 12.6 MB, nothing else runs; the kernel ends when DRAM finishes the writes 36k cycles = 10 us

    Our compute (108k) equals the TPU's (110k, which includes writing y). The excess is structural:

    1. The last M tile's output store is fully exposed (36k of 160k cycles, 22%; 36k of 269k on 8192). The TPU writes y inside the fusion, overlapped with the MXU.
    2. Per tile 10.5k cycles of vector prologue / epilogue run serialized with the matmul (one compute at a time): 21k on 4096, 42k on 8192 = 19% of our compute; on 8192 our compute is 216k against the TPU's 194k.
    3. Both operands are loaded whole, and both tiles' A loads queue ahead of the first compute (24k vs the TPU's 16.5k prefetch of one operand).
    4. The DRAM model adds 8-12%: simple DRAM gives 140,389 (4096) and 248,445 (8192).

    Nothing here is specific to N = 3072; the same structure is in every layer, it just weighs most where the output is large (N = 3072 at 2 bytes, padded block 4096) and the per-tile compute is short relative to it. 8192x3072x768 (same work, output 4x smaller) is at 0.83 for the same reason in reverse.

    Status of the issue's list

    item status
    1 region A cause found (start costs), modelling undecided
    2 split on small layers waits on 1
    3 M = 1 cause found: (a) ramulator half rate on the strided W block, (b) serial reduce chain, (c) region A
    4 768x3072 large M cause found: exposed final store, serialized vector pro/epilogue, whole-operand loads, DRAM model
    5 reference prefetch-on table (decided)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions