Skip to content

[cutedsl] Seed the thread counts that tile a resident row of no power of two - #4819

Merged
choijon5 merged 1 commit into
mainfrom
choijon5/cute-norm-bwd/9
Nov 29, 2026
Merged

choijon5 merged 1 commit into
mainfrom
choijon5/cute-norm-bwd/9

Conversation

@choijon5

@choijon5 choijon5 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:


[cutedsl] Seed the thread counts that tile a resident row of no power of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:

  • 7680 features: 95.4 us -> 85.6 us
  • 10752: 233.3 us -> 105.4 us
  • 12800: 310.0 us -> 138.2 us
  • 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.

  • Generated code, rendered on CPU for the B200 target: all 1,298 configs
    that main renders for 145 attention cases generate the same source with
    the stack, and no seed list changes. The cases are the kernels of
    examples/attention.py (forward and backward), flex_attention.py,
    blackwell_attention.py and fp8_attention.py, and of
    benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
    are each case's default and every compiler seed.
  • The same with the attention stack ([testing] Time the long-kernel probe test against the traced call itself #4797 to [cutedsl] Run the plain causal flash pair in the persistent work-item loop #4810) under both sides: 759
    forward and 626 backward and attention-gym configs (defaults, seeds,
    pinned configs), 7,493 more configs that the search reaches on 12
    forward cases (one knob changed at a time, random draws) and 3,861 with
    random draws on the backward and attention-gym kernels generate the same
    source with and without this stack, and the 11 kernels compiled on the
    GPU (the eight forward shapes below and three fp8 attention inputs) have
    the same MLIR bytecode.
  • Time: the eight forward shapes of examples/attention.py (dense and
    causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
    configs, with and without this stack, interleaved, a new process for
    every reading, 4 to 8 rounds a shape. The best readings with the stack
    are 0.994 to 1.007 times those without. On this power-capped GPU every
    implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
    apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts. A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between. The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us). "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

features 256 threads 512 threads 16 features a thread
2560 23.5 staged x4 33.1 staged 33.2 staged (160 threads)
6144 48.7 staged x2 - 52.4 staged (384)
7680 63.0 staged 63.4 staged 65.3 staged (480)
9216 71.0 staged - 73.8 staged (576)
10752 81.5 staged 84.3 staged 131.8 staged (672)
12800 121.1 unstaged 150.0 unstaged 151.7 unstaged (800)
14336 150.3 unstaged 152.9 unstaged -
15872 222.0 unstaged 200.2 unstaged 198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM. The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster. At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

  • _tiled_threads: the whole-warp thread counts that tile the row nearest
    to 256 and to 512.
  • _tiled_entries: for each of them a seed with the widest of 4-, 2- and
    1-wide vectors that tiles a thread's features. The first count leads
    with the largest staged row group of four and two rows that the stage
    holds (four-row groups ran 2560 features 28% faster than single rows,
    two-row groups 6144 features 7%), then each count is seeded staged with
    single rows and unstaged. No count is seeded staged when the stage does
    not hold two rows, so that the primary seed is not one whose stage the
    shared memory refuses. That holds for the estimate's reading of a row:
    the kernel's row tensors are as wide as the row and each is loaded once.
    It is no promise that the seed renders: the lowering stages only the
    loads it proves aligned to 16 bytes, and refuses a staged seed when it
    proves that of none.
  • _staged_rows: an estimate of the rows of features that the target's
    shared memory stages, from the tensors the kernel loads whose last dim
    is the row's length. The shared memory is what a block of the device
    opts in to and, below sm_90, no more than the 48 KiB of static
    allocations that the per-block check holds a stage to there (the bottom
    commit of the stack). It shapes the seeds only: the lowering charges each
    config's stage exactly and refuses the one that exceeds the shared
    memory.
  • The entries lead the family's list for such a row, before the lattice's,
    and get the occupancy twins that the lattice's entries get. A twin's row
    group is at most the rows its CTA runs, as the 8-wide entries' is (256
    rows on 148 SMs are two rows a CTA: a group of two, where four would
    stage masked rows). A row that is a power of two keeps its seeds:
    _tiled_entries returns none for it.

Compatibility: CuTe only, autotuner seeds only. The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: scripts/run_tests.py --backend cute --lane cpu, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: scripts/run_tests.py --backend cute --gpus 4,5,6,7, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. ./lint.sh check passes.

autoreview passed: claude, codex

… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 8a2b6a5 to b0c11e2 Compare November 28, 2026 17:16
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from 9109f36 to 682935f Compare November 28, 2026 17:16
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 28, 2026
@choijon5
choijon5 marked this pull request as draft November 28, 2026 20:36
@choijon5
choijon5 changed the base branch from choijon5/cute-norm-bwd/8 to main November 28, 2026 20:36
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from b0c11e2 to d78af46 Compare November 28, 2026 20:37
@choijon5
choijon5 changed the base branch from main to choijon5/cute-norm-bwd/8 November 28, 2026 20:37
@choijon5
choijon5 marked this pull request as ready for review November 28, 2026 20:38
@choijon5
choijon5 marked this pull request as draft November 29, 2026 18:14
@choijon5
choijon5 changed the base branch from choijon5/cute-norm-bwd/8 to main November 29, 2026 18:14
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from d78af46 to 7cd3f91 Compare November 29, 2026 18:15
@choijon5
choijon5 changed the base branch from main to choijon5/cute-norm-bwd/8 November 29, 2026 18:15
@choijon5
choijon5 marked this pull request as ready for review November 29, 2026 18:15
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from dfb545e to dd749aa Compare November 29, 2026 20:07
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 7cd3f91 to 107f7c1 Compare November 29, 2026 20:07
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from dd749aa to f65f982 Compare November 29, 2026 20:08
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 107f7c1 to a44123f Compare November 29, 2026 20:08
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from f65f982 to 50ef0a5 Compare November 29, 2026 20:09
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from a44123f to 3c6bf20 Compare November 29, 2026 20:09
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from 50ef0a5 to 7e38ef7 Compare November 29, 2026 20:10
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 3c6bf20 to f93cb80 Compare November 29, 2026 20:10
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from 7e38ef7 to ff6357a Compare November 29, 2026 20:11
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from f93cb80 to 5624eeb Compare November 29, 2026 20:11
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/8 branch from ff6357a to 3a1c245 Compare November 29, 2026 20:12
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 5624eeb to 72e201c Compare November 29, 2026 20:12
choijon5 added a commit that referenced this pull request Nov 29, 2026
… of two

For the norm backward kernels (layer_norm_bwd in examples/layer_norm.py and
rms_norm_bwd in examples/rms_norm.py, which TritonBench runs as
layer_norm-bwd and rms_norm-bwd): part of their hillclimb on the CuTe
backend.

Kernels: the same rows as the commit below this one
(examples/layer_norm.py::layer_norm_bwd and
examples/rms_norm.py::rms_norm_bwd at row lengths that are no power of
two): the search now starts from the thread counts that measure fastest,
where it started from a lattice of powers of two. TritonBench's
layer_norm-bwd on a B200 (4096 rows, fp32, one cold full autotune per
input, the time the search measured for its winner), the commit below ->
this commit:
- 7680 features: 95.4 us -> 85.6 us
- 10752: 233.3 us -> 105.4 us
- 12800: 310.0 us -> 138.2 us
- 15872: 611.4 us -> 223.4 us

Regression check for attention, which was hillclimbed before this stack:
the 12 pull requests of this stack together (#4811 to #4822) against plain
main (74ac871), on a B200.
- Generated code, rendered on CPU for the B200 target: all 1,298 configs
  that main renders for 145 attention cases generate the same source with
  the stack, and no seed list changes. The cases are the kernels of
  examples/attention.py (forward and backward), flex_attention.py,
  blackwell_attention.py and fp8_attention.py, and of
  benchmarks/cute/attnbwd_kernels.py and attngym_kernels.py; the configs
  are each case's default and every compiler seed.
- The same with the attention stack (#4797 to #4810) under both sides: 759
  forward and 626 backward and attention-gym configs (defaults, seeds,
  pinned configs), 7,493 more configs that the search reaches on 12
  forward cases (one knob changed at a time, random draws) and 3,861 with
  random draws on the backward and attention-gym kernels generate the same
  source with and without this stack, and the 11 kernels compiled on the
  GPU (the eight forward shapes below and three fp8 attention inputs) have
  the same MLIR bytecode.
- Time: the eight forward shapes of examples/attention.py (dense and
  causal, B2 H32 S1024 D64 fp16 to B8 H32 S8192 D128 bf16) at pinned
  configs, with and without this stack, interleaved, a new process for
  every reading, 4 to 8 rounds a shape. The best readings with the stack
  are 0.994 to 1.007 times those without. On this power-capped GPU every
  implementation, cuDNN SDPA included, reads one of two levels 3 to 5%
  apart from process to process; both sides read the same two levels.

2560, 6144, 9216 and 14336 features end where they did (37.4, 69.2, 91.2
and 167.9 us against 37.5, 68.6, 91.3 and 173.1).

The resident reduction seeds come from a lattice of power-of-two thread
counts.  A row whose length is no power of two gets an awkward share per
thread from them, or none: 7680 features are 60 a thread over 128 threads and
tile neither 256 nor 512 threads in 8-wide vectors, and 9216 over 128
threads are 72 a thread, whose carries and row values leave the registers.
The search's thread counts are powers of two as well, so no neighbor of a
lattice seed reaches the counts in between.  The previous commit lets such
rows run on the resident schedules; this one seeds them.

Pinned layouts of examples/layer_norm.py::layer_norm_bwd on a B200 (4096
rows, fp32, kernel time in us).  "staged" is the pipelined schedule, x2 and
x4 its row groups, and the last column the count that gives a thread 16
features:

  features  256 threads      512 threads      16 features a thread
      2560  23.5 staged x4   33.1 staged      33.2 staged   (160 threads)
      6144  48.7 staged x2   -                52.4 staged   (384)
      7680  63.0 staged      63.4 staged      65.3 staged   (480)
      9216  71.0 staged      -                73.8 staged   (576)
     10752  81.5 staged      84.3 staged      131.8 staged  (672)
     12800  121.1 unstaged   150.0 unstaged   151.7 unstaged (800)
     14336  150.3 unstaged   152.9 unstaged   -
     15872  222.0 unstaged   200.2 unstaged   198.4 unstaged (992)

256 threads are the fastest count up to 10752 features: each thread then
has the 255 registers a thread can address, and the block the whole
register file of its SM.  The staged schedule wins while the registers hold
a thread's values; from 12800 features on they do not (50 features a thread,
five values each), and the unstaged schedule is faster.  At 15872 features
the stage does not fit two rows, and half the features a thread run 10%
faster.

- `_tiled_threads`: the whole-warp thread counts that tile the row nearest
  to 256 and to 512.
- `_tiled_entries`: for each of them a seed with the widest of 4-, 2- and
  1-wide vectors that tiles a thread's features.  The first count leads
  with the largest staged row group of four and two rows that the stage
  holds (four-row groups ran 2560 features 28% faster than single rows,
  two-row groups 6144 features 7%), then each count is seeded staged with
  single rows and unstaged.  No count is seeded staged when the stage does
  not hold two rows, so that the primary seed is not one whose stage the
  shared memory refuses.  That holds for the estimate's reading of a row:
  the kernel's row tensors are as wide as the row and each is loaded once.
  It is no promise that the seed renders: the lowering stages only the
  loads it proves aligned to 16 bytes, and refuses a staged seed when it
  proves that of none.
- `_staged_rows`: an estimate of the rows of features that the target's
  shared memory stages, from the tensors the kernel loads whose last dim
  is the row's length.  The shared memory is what a block of the device
  opts in to and, below sm_90, no more than the 48 KiB of static
  allocations that the per-block check holds a stage to there (the bottom
  commit of the stack).  It shapes the seeds only: the lowering charges each
  config's stage exactly and refuses the one that exceeds the shared
  memory.
- The entries lead the family's list for such a row, before the lattice's,
  and get the occupancy twins that the lattice's entries get.  A twin's row
  group is at most the rows its CTA runs, as the 8-wide entries' is (256
  rows on 148 SMs are two rows a CTA: a group of two, where four would
  stage masked rows).  A row that is a power of two keeps its seeds:
  `_tiled_entries` returns none for it.

Compatibility: CuTe only, autotuner seeds only.  The compiler seed list of
a resident reduction kernel whose rows are no power of two changes, and with
it the fingerprint of its autotune cache entry.

Tests (test/test_cute_resident_row_widths.py, CPU): the thread counts of
six row lengths, among them one that 256 and 512 threads do not tile and one
that no whole warps tile; the entries for stages of eleven, four, three and
one rows and for an unknown stage; the staged-row estimate of layer_norm_bwd
at three fp32 widths and one bf16 width, and for a model of an sm_80
target, which stages two rows of 2560 fp32 features where sm_100 stages
eleven, and whose primary seed is then the one-row stage and renders; the
seeds of layer_norm_bwd at 2560 features; the row group of an occupancy twin
at 256 rows; and at 15872 features a render of the primary seed, whose
staged twin the lowering refuses and renders with the shared memory doubled.

Testing: B200, CUDA 13.2, torch 2.15.0+cu132, on origin/main 74ac871. At
this commit: `scripts/run_tests.py --backend cute --lane cpu`, 27376 passed,
684 skipped, 1 failed
(test/test_cute_fragment_assertion.py::test_assertions_in_binary_cross_entropy_decomposition,
which needs the nightly's decomposition: it fails on torch 2.15.0 at
origin/main as well); test_cute_resident_row_widths.py,
test_cute_resident_reductions.py, test_cute_resident_reduction_runtime.py
and test_cute_resident_reductions_codegen.py on both lanes with GPU 4, GPU
lane 10 passed, CPU lane 1294 passed. The seeds are read on a device by the
tests of the GPU lane, which ran at the tip of the stack, which holds this
commit: `scripts/run_tests.py --backend cute --gpus 4,5,6,7`, GPU lane 16010
passed, 2374 skipped; CPU lane 27408 passed, 684 skipped and the same 1
failed. The cold autotunes of the lead ran with this commit on origin/main
f615a9b, before #4763 to #4767 landed and before the estimate took the
static limit below sm_90; none of these changes a seed of these inputs on
this device (at the tip of the stack, the compiler seeds, the default config
and 40 random configs of each of the 15 TritonBench inputs (1023 configs)
render the same code, or are refused alike, before and after the rebase
onto #4766 and the one onto #4767). The lanes ran before the last review of
the stack's bottom commit changed two of that commit's tests
(test_cute_smem_footprint.py, test_cute_resident_reductions_codegen.py); the
two modules ran again at this commit, 63 passed. `./lint.sh check` passes.

autoreview passed: claude, codex

stack-info: PR: #4819, branch: choijon5/cute-norm-bwd/9
@choijon5
choijon5 force-pushed the choijon5/cute-norm-bwd/9 branch from 72e201c to ef64a3b Compare November 29, 2026 20:13
@choijon5
choijon5 changed the base branch from choijon5/cute-norm-bwd/8 to main November 29, 2026 20:13
@choijon5
choijon5 merged commit ec0a76c into main Nov 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants