Skip to content

Fuse the CUDA decode step and LayerNorm kernels - #11

Merged
praveenperera merged 4 commits into
masterfrom
fuse-kernels
Oct 29, 2026
Merged

praveenperera merged 4 commits into
masterfrom
fuse-kernels

Conversation

@praveenperera

@praveenperera praveenperera commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Closes #3.

Changes

  • Decode step: 15 launches down to 5.
    • A step now runs the joint GEMM, decode_decide, one decode_lstm per predictor layer, and decode_project.
    • decode_lstm computes a layer's gates and cell update in one launch. The first layer reads its embedding row directly.
    • decode_project writes the predictor projection and the next step's joint input. It also pre-fills the logits with the joint bias, which the next GEMM accumulates onto with beta = 1.
    • Both kernels keep a block's weights in registers and reuse them across 8 batch rows per pass, so long-form batches of 16 stay fast.
  • decode_decide: each thread keeps its class logits in registers, and warp 0 finds the best duration. Results are the same as before.
  • LayerNorm:
    • Each thread reads its part of the row once and keeps it in registers. The summation order is unchanged, so the output is bit-identical.
    • A layer's last norm also writes the next layer's first norm. This removes one launch and one device copy per layer.

Results

RTX 5090, TF32, Parakeet v3. Each build was measured on the same GPU.

Before After
LibriSpeech test-clean, best of 2 952.8x 1108.3x (+16 %)
LibriSpeech WER 1.925 % 1.925 % (0 of 2620 transcripts differ)
Earnings-21, 44 calls, best of 2 2508x 2528x
Earnings-21 pooled WER 8.24 % 8.24 %

just gpu-parity passes 17/17. FP32 output still matches NeMo token for token, and the encoder's FP32 errors against NeMo are unchanged to every printed digit.

Kernel time, LibriSpeech (nsys, graph nodes)

Kernel Before After
encoder TF32 GEMMs (cutlass) 8.57 s 8.58 s
decode LSTM + projection (5 cuBLAS GEMVs, cell, embed, joint input, bias fill) ~4.15 s 1.84 s (decode_lstm 1.55 s + decode_project 0.29 s)
LayerNorm 1.08 s 0.92 s
joint GEMV 0.68 s 0.68 s
decode_decide 0.60 s 0.52 s
total kernel time 16.8 s 14.3 s

On one long call (4360674.wav, batch 16), decode_lstm takes 20 µs per layer and decode_project 6.4 µs per step.

Tried and not kept

  • Fusing the first subsampling convolution into the first depthwise convolution. The first feature map is no longer stored, which saves about 1.2 GB per long-form shape. But each depthwise output recomputes nine first-stage taps, so subsampling got slower:

    • LibriSpeech: 273 ms → 368 ms
    • long call: 67 ms → 85 ms

    LibriSpeech fell to 1056x. Reverted.

  • A first version of decode_lstm and decode_project that handled batch rows one at a time. It took LibriSpeech to 1047x but slowed Earnings-21 to 2045x (79 µs per LSTM layer at batch 16). Replaced by the batched version above.

Each LayerNorm thread now reads its share of the row from memory once
and keeps it in registers for the mean, the variance and the output,
with the same summation order, so the results are bit-identical.

A layer's last norm also writes the next layer's first norm, which
drops one launch per layer and the device copy after it. On an RTX 5090
the encoder's LayerNorm time on LibriSpeech test-clean falls from
1.08 s to 0.92 s.
A greedy decode step ran 15 launches: cuBLAS GEMVs for each LSTM gate
product and the predictor projection, plus small kernels for the
embedding, the cell update, the joint input and the bias fill. Batch 1
decode is bound by launch latency, so the step now runs the joint GEMM,
decode_decide, one decode_lstm per predictor layer and decode_project.

decode_lstm computes a layer's gates and its cell update in one launch,
reading the embedding row directly for the first layer. decode_project
writes the predictor projection, the next step's joint input and the
joint bias the next GEMM accumulates onto. Both keep a block's weights
in registers and reuse them across 8 batch rows per pass, so long-form
batches of 16 do not walk their rows one at a time.

decode_decide keeps each thread's class logits in registers instead of
rereading them for every pass, with the same results.

On an RTX 5090 with TF32, LibriSpeech test-clean goes from 953x to
1108x real time and Earnings-21 from 2508x to 2528x, with unchanged
transcripts and WER.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2fdbef39-1d52-40fc-adb4-7f9ef96a5e18
Commits

Reviewing files that changed from the base of the PR and between 3f1e058 and f18ebe7.

Files selected for processing: 8
  • README.md
  • crates/scriptrs-cuda-kernels/src/decode.rs
  • crates/scriptrs-cuda-kernels/src/encoder.rs
  • src/cuda/decoder.rs
  • src/cuda/encoder.rs
  • src/cuda/kernels.rs
  • src/cuda/ptx/decode.sm75.ptx
  • src/cuda/ptx/encoder.sm75.ptx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the earlier predictor test-coverage concern addressed.

Summary

The PR combines CUDA predictor updates and consecutive LayerNorm operations to reduce GPU launches.

  • Each CUDA decode step updates predictor state and prepares its next input in fewer launches.
  • The decode decision kernel keeps class logits in registers while it picks a token and duration.
  • Encoder LayerNorm reuses row values and prepares the next layer’s normalized input.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Joint GEMM"] --> B["decode_decide"]
  B --> C["decode_lstm per layer"]
  C --> D["decode_project"]
  D --> E["Next joint input, bias-filled logits, saved state"]
  E --> A
Loading

Reviews (2) · Last reviewed commit: "Test the predictor step against a host r..." · Reviewed by Greptile

decode_lstm and decode_project carry 8 batch rows per pass and leave
rows that do not emit untouched, which the NeMo parity tests at batch 1
and 8 never reach. The test runs two steps on 17 rows with different
rows emitting each step and holds the state, projection, joint input
and logits to a host predictor.
@praveenperera

Copy link
Copy Markdown
Member Author

@greptileai review

@praveenperera
praveenperera merged commit 5a7f738 into master Oct 29, 2026
2 checks passed
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.

Fuse small CUDA kernels and speed up the decode decision

1 participant