Skip to content

perf(cake_gated_act_mxfp8): band-path program for the SM107 forward both entry below 2^20 - #8023

Merged
yyihuang merged 1 commit into
flashinfer-ai:mainfrom
yyihuang:cake-gated-act-mxfp8-sm107-fwd-both-band
Oct 30, 2026
Merged

yyihuang merged 1 commit into
flashinfer-ai:mainfrom
yyihuang:cake-gated-act-mxfp8-sm107-fwd-both-band

Conversation

@yyihuang

@yyihuang yyihuang commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

The Cake fused SwiGLU + MXFP8 quantization kernel computes silu(gate) * up from a BF16 input [M, 2K] and quantizes the result to MXFP8. It stores one E8M0 scale (RCEIL rounding) per 32 E4M3 values, in the swizzled 128 x 4 layout. The kernel has one data type and six forms. The forward form is flashinfer.silu_and_mul_mxfp8_quantize and the backward form is flashinfer.silu_and_mul_mxfp8_quantize_backward. Each can write rowwise, colwise or both outputs. flashinfer.cake_gated_act_mxfp8_backend runs one program per call and picks it by M * K for each architecture. This PR changes program selection for one forward entry on sm_107a (R200). When M * K is below 2^20, forward both now runs the called band path at 4 CTAs per SM. From 2^20 up to 2^23, the previous program still runs, with no band-path or occupancy setting. Sizes above that are unchanged. The sm_100a and sm_103a programs are unchanged. The package goes from 74 to 75 per-arch programs across 62 records. One record is new and applies to sm_107a only, and one existing record now starts at 2^20 on sm_107a. The other libraries keep the same machine code.

The baseline is the previous Cake version of this kernel, which is the package on FlashInfer main from #7880. With block-scaled inputs the changed owner row is faster: 128 x 128 forward both is 1.076x (2.36 us -> 2.20 us). The same entry also covers 256 x 256 and 512 x 512 forward both. Measured outside the owner list, these are 1.085x and 1.081x with block-scaled inputs. With unit-normal inputs the changed rows tie within the run-to-run spread (128 x 128 forward both is 1.004x). Every other row runs the same machine code as before and stays within run-to-run noise. Over all 30 rows, unit normals range from 0.998x to 1.004x and block-scaled inputs from 0.999x to 1.076x.

The table covers the owner rows on NVIDIA R200 (sm_107a, 216 SMs) with CUDA 13.4: 5 shapes x 6 passes, 30 rows. Both versions run in the same process on the same GPU, in 8 alternating paired rounds, with a cold L2 before every launch. Latency is the mean over pairs of each sample's median CUPTI kernel time, in microseconds. Speedup is the previous latency divided by this PR's latency, so a value above 1 means this PR is faster. Block-scaled inputs are normals with per-32-block scales spread over a wide exponent range. Outputs are byte-identical to the previous version, and the public API is unchanged.

NVIDIA R200 (sm_107a, 216 SMs), CUDA 13.4

M x K Pass Unit normals: previous Cake (µs) This PR (µs) Speedup Block-scaled: previous Cake (µs) This PR (µs) Speedup
128 x 128 fwd rowwise 1.87 1.87 0.998x 2.01 2.01 0.999x
128 x 128 fwd colwise 2.03 2.03 0.998x 2.17 2.17 1.001x
128 x 128 fwd both 2.10 2.09 1.004x 2.36 2.20 1.076x
128 x 128 bwd rowwise 2.13 2.12 1.000x 2.31 2.31 1.000x
128 x 128 bwd colwise 2.23 2.23 1.001x 2.28 2.28 1.000x
128 x 128 bwd both 2.35 2.35 1.000x 2.45 2.45 0.999x
4096 x 2048 fwd rowwise 7.12 7.13 1.000x 8.12 8.11 1.001x
4096 x 2048 fwd colwise 7.18 7.18 1.000x 8.69 8.70 1.000x
4096 x 2048 fwd both 8.51 8.51 1.000x 10.07 10.07 1.000x
4096 x 2048 bwd rowwise 10.10 10.10 1.000x 10.35 10.35 1.000x
4096 x 2048 bwd colwise 10.63 10.63 1.000x 11.24 11.25 1.000x
4096 x 2048 bwd both 12.67 12.66 1.000x 13.31 13.29 1.002x
4096 x 7168 fwd rowwise 17.75 17.75 1.000x 19.17 19.17 1.000x
4096 x 7168 fwd colwise 18.04 18.04 1.000x 20.95 20.94 1.000x
4096 x 7168 fwd both 21.02 21.02 1.000x 25.41 25.40 1.000x
4096 x 7168 bwd rowwise 27.05 27.05 1.000x 27.71 27.72 1.000x
4096 x 7168 bwd colwise 27.51 27.51 1.000x 29.19 29.20 1.000x
4096 x 7168 bwd both 33.91 33.90 1.000x 34.94 34.86 1.002x
16384 x 7168 fwd rowwise 56.92 56.93 1.000x 64.34 64.30 1.001x
16384 x 7168 fwd colwise 57.79 57.78 1.000x 67.11 67.11 1.000x
16384 x 7168 fwd both 70.39 70.39 1.000x 75.77 75.74 1.000x
16384 x 7168 bwd rowwise 92.87 92.86 1.000x 96.73 96.77 1.000x
16384 x 7168 bwd colwise 93.98 93.98 1.000x 103.08 103.05 1.000x
16384 x 7168 bwd both 123.56 123.55 1.000x 125.56 125.50 1.000x
131072 x 8192 fwd rowwise 462.66 462.66 1.000x 515.03 514.74 1.001x
131072 x 8192 fwd colwise 483.20 483.20 1.000x 539.91 539.75 1.000x
131072 x 8192 fwd both 610.50 610.56 1.000x 621.14 621.18 1.000x
131072 x 8192 bwd rowwise 796.30 796.29 1.000x 829.40 829.42 1.000x
131072 x 8192 bwd colwise 810.45 810.46 1.000x 869.06 869.34 1.000x
131072 x 8192 bwd both 1095.04 1095.07 1.000x 1109.63 1109.66 1.000x

Cake has no other variants of this kernel beyond these six BF16-to-MXFP8 forms with the swizzled scale layout, and the family ships on sm_100a (B200), sm_103a (GB300) and sm_107a (R200).

Summary by CodeRabbit

  • New Features
    • Added support for gated-activation MXFP8 processing on a new GPU architecture.
    • Added an optimized processing path for compatible workloads, with performance routing based on workload size.
    • This support requires CUDA 13.4.

…oth entry below 2^20

- SM107 forward both, M * K below 2^20: the plain program with the call
  band path at 4 CTAs per SM (new record).
- From 2^20 up to 2^23 the previous plain program still runs; its record
  now starts at 2^20 on SM107. Larger sizes and SM100 / SM103 are unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
@flashinfer-bot flashinfer-bot added the op: misc norm, activation, sampling, RoPE, quantization, etc. label Oct 30, 2026
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
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: c4bd0845-1b2b-4597-a904-5ac7cc05c7c2
Commits

Reviewing files that changed from the base of the PR and between 85be8d0 and c11c8c7.

Files selected for processing: 4
  • flashinfer/cake_gated_act_mxfp8_backend/build.json
  • flashinfer/cake_gated_act_mxfp8_backend/cake_jit.py
  • flashinfer/cake_gated_act_mxfp8_backend/csrc/cake_gated_act_mxfp8_e62d5f6dda3083f31950_binding.cu
  • flashinfer/cake_gated_act_mxfp8_backend/csrc/cake_gated_act_mxfp8_e62d5f6dda3083f31950_kernel.cu

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Walkthrough

The change adds a gated-activation MXFP8 CUDA kernel and its TVM-FFI binding for sm_107a. It registers the library in the build manifest and updates fwd_both dispatch to use the new fallback below the configured selection threshold.

Changes: sm_107a MXFP8 backend

Layer / File(s) Summary
Gated activation kernel
flashinfer/cake_gated_act_mxfp8_backend/csrc/cake_gated_act_mxfp8_e62d5f6dda3083f31950_kernel.cu
Adds BF16 gated-activation computation, including a fast path and an alternate path that recomputes pairs with zero gate factors.
Row and column quantization
flashinfer/cake_gated_act_mxfp8_backend/csrc/cake_gated_act_mxfp8_e62d5f6dda3083f31950_kernel.cu
Computes row and column maxima and scales, converts values to saturated E4M3, and writes both output layouts.
Kernel binding and launch
flashinfer/cake_gated_act_mxfp8_backend/csrc/cake_gated_act_mxfp8_e62d5f6dda3083f31950_binding.cu
Validates tensor and grid properties, obtains the device stream, launches the kernel, and reports validation or launch errors.
Library registration and dispatch
flashinfer/cake_gated_act_mxfp8_backend/build.json, flashinfer/cake_gated_act_mxfp8_backend/cake_jit.py
Adds the sm_107a build manifest entry and updates fwd_both routing. The new fallback handles calls below the threshold-selected record.

Priority: Low

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant fwd_both
  participant run
  participant kernel_cake_gated_act_mxfp8_e62d5f6dda3083f31950
  participant row_output
  participant col_output
  fwd_both->>run: selects and invokes the library entry
  run->>kernel_cake_gated_act_mxfp8_e62d5f6dda3083f31950: launches on the device stream
  kernel_cake_gated_act_mxfp8_e62d5f6dda3083f31950->>row_output: writes row-oriented E4M3 data and scales
  kernel_cake_gated_act_mxfp8_e62d5f6dda3083f31950->>col_output: writes column-oriented E4M3 data and scales
Loading

Suggested labels: op: misc

Suggested reviewers: aleozlx, sricketts

Merge Risk: Minimal · up to c11c8

This change adds a new program selection for sm_107a forward-both calls below 2^20 elements and moves one existing selection bound. No concrete merge-blocking risk was found in the supplied changes. Hardware validation on R200 remains with the author's reported measurements.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description gives a detailed change summary, scope, benchmark setup, and performance results. However, it omits the required template sections and checklist, including related issues, pre-commit s… Add the required template headings and checklist. State related issues or indicate none, report pre-commit and test results, declare whether full-scope CI is required with a reason, complete the experimental-track section when applicable, a…
Docstring Coverage Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the performance change: adding a band-path program for SM107 forward-both calls below 2^20.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description gives a detailed change summary, scope, benchmark setup, and performance results. However, it omits the required template sections and checklist, including related issues, pre-commit status, explicit test status, CI scope, and reviewer notes.

Resolution

Add the required template headings and checklist. State related issues or indicate none, report pre-commit and test results, declare whether full-scope CI is required with a reason, complete the experimental-track section when applicable, and add reviewer notes or indicate none.

Full details: Docstring Coverage

Explanation

Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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.

@yyihuang

Copy link
Copy Markdown
Collaborator Author

@flashinfer-bot run tests/utils/test_cake_gated_act_mxfp8.py tests/utils/test_cake_gated_act_mxfp8_api.py

@yyihuang
yyihuang merged commit 78515ec into flashinfer-ai:main Oct 30, 2026
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

op: misc norm, activation, sampling, RoPE, quantization, etc. run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants