Skip to content

[Codegen] A reduction over rows too few for the lanes budgets its R0_BLOCK over every lane - #391

Merged
YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
reduction-on-lanes
Oct 19, 2026
Merged

YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
reduction-on-lanes

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the R0_BLOCK side of #386.

Cause. fixed_config_for sizes a reduction's R0_BLOCK against one lane's budget (reduction_block_for: spad / 2 / 12 → 8192 f32). When a reduction's rows fill fewer lanes than the machine has, the compiler lays its reduced axis across the lanes, so each lane held 64 elements a trip: sum 4096x4096 walked 2048 trips of 16 KiB, DMA-bound at ~667 GB/s (#386 comments).

Change. Such a reduction — any kind — takes R0_BLOCK from every lane's budget over its rows (tiling.lane_axis_reduction_block), the budget pointwise_block and kept_axis_contiguous_blocks already use, covering the extent and capped at Triton's block limit. It reaches the pinned blocks and the persistence decision alike. Rows that fill the lanes keep today's block. No reduction-kind test is needed: the compiler lays every reduction's axis on the lanes in that case.

kernel before after
sum / max 4096x4096 (XBLOCK 1) 8192 1048576
sum 96x128 8192 16384
softmax 8x16384 (XBLOCK 8) 8192 16384
softmax 1024x1024, row sum 4096x1024 unchanged unchanged

Compiler side (all needed before the pin can carry this):

The compiler pin (#392, PTB main d0553bd) has all three. With an older compiler a block the compiler cannot lay across the lanes is refused as over budget and the retry halves it (checked locally with a pre-fold compiler image: 1M → 65536).

Checked: tests/system/test_reduction_tiling.py (the blocks for full, few-row and wide reductions). Measured on PTB: pending, after the pin.

@student-Jungmin

Copy link
Copy Markdown
Collaborator

Measured locally with the same blocks (lanes × per-lane budget, capped at 1M) on PTB main 83dc6b5, TOGSim tpuv6e with the XLU timing: sum 1.343 → 0.997 and max 1.320 → 1.115 (±20%: 20 → 31 and 19 → 30). Two costs to expect in the PTB report:

  • A 1M block over 1.5M elements gives a masked tail trip, and Inductor's r < N mask is then built on every trip: max 1536x1024 1.206 → 2.156, sum 1536x1024 1.195 → 1.529. A PTB change that peels the last trip, so the full trips run unmasked, is in progress; it brings max 1536x1024 to about 5.6 µs (from 10.8).
  • Five 4–24 MB sums become faster than the v6e: sum 2048x1024 0.84, 3072x1024 0.75, 3072x2048 0.89, 4096x2048 0.87, 6144x2048 0.85. XLA reads these in one 4 MB DMA, or 2 MB blocks with no overlap, while the loop overlaps its trips.

@YWHyuk YWHyuk changed the title [Codegen] A fold over rows too few for the lanes budgets its R0_BLOCK over every lane [Codegen] A reduction over rows too few for the lanes budgets its R0_BLOCK over every lane Oct 19, 2026
@YWHyuk
YWHyuk force-pushed the reduction-on-lanes branch 3 times, most recently from 83c3a7d to 44dae30 Compare October 19, 2026 16:37
@YWHyuk
YWHyuk marked this pull request as ready for review October 19, 2026 16:37
…BLOCK over every lane

A full reduction (XBLOCK 1) took R0_BLOCK from one lane's budget, 8192 f32, while the compiler lays
a reduction whose rows fill fewer lanes than the machine has with its reduced axis across the lanes
(PTB anchorReduce: a fold since f951912 and #201, any reduction since #203): each lane then held 64
elements a trip, and sum and max walked 2048 trips of 16 KiB for 4096x4096 (#386). Such a reduction
now takes R0_BLOCK from the budget of every lane over its rows, as pointwise_block and
kept_axis_contiguous_blocks already do, covering the extent: 1M for 4096x4096, 16384 for 96x128,
16384 for softmax 8x16384. Rows that fill the lanes keep today's block.
@YWHyuk
YWHyuk force-pushed the reduction-on-lanes branch from 44dae30 to 6b15aa0 Compare October 19, 2026 16:41
@YWHyuk
YWHyuk merged commit b6a18ad into pytorchsim-triton-backend Oct 19, 2026
@YWHyuk
YWHyuk deleted the reduction-on-lanes branch October 19, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants