Skip to content

[Common] Swizzle MXFP8 scaling factors with one CTA per scale tile - #3658

Merged
vthumbe1503 merged 5 commits into
NVIDIA:mainfrom
sraman-rgb:sraman/mxfp8-swizzle-tile-ctas
Oct 11, 2026
Merged

vthumbe1503 merged 5 commits into
NVIDIA:mainfrom
sraman-rgb:sraman/mxfp8-swizzle-tile-ctas

Conversation

@sraman-rgb

Copy link
Copy Markdown
Collaborator

The MXFP8 scale swizzle is latency bound. The narrow-K and narrow-M kernels put up to 32 128x4 scale tiles in one 1024-thread CTA, so the scaling factors of a 4096-row activation are swizzled by a single CTA.

Give every 128-row M-tile (row-wise) or 128-column x 32-row block (column-wise) its own CTA, which moves a contiguous chunk with coalesced 16-byte loads and stores through shared memory. Multi-tensor launches group tiles per CTA only when the grid would otherwise be very large. The existing kernels remain for NVFP4, unaligned buffers, and row-wise scales too wide for 48 KB of shared memory.

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

The MXFP8 scale swizzle is latency bound. The narrow-K and narrow-M
kernels put up to 32 128x4 scale tiles in one 1024-thread CTA, so the
scaling factors of a 4096-row activation are swizzled by a single CTA.

Give every 128-row M-tile (row-wise) or 128-column x 32-row block
(column-wise) its own CTA, which moves a contiguous chunk with coalesced
16-byte loads and stores through shared memory. Multi-tensor launches
group tiles per CTA only when the grid would otherwise be very large.
The existing kernels remain for NVFP4, unaligned buffers, and row-wise
scales too wide for 48 KB of shared memory.

Signed-off-by: Siddhartha Raman S <sraman@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

Adds optional MXFP8 scale-swizzle kernels that give small tiles separate thread blocks to reduce latency.

  • NVTE_MXFP8_PER_TILE_SWIZZLE defaults to off.
  • Large grids group tiles, while unsupported inputs keep the existing kernels.
  • Tests cover both flag settings, multiple launches, grouped tiles, and clipped chunks.
  • The earlier unnumbered coverage comment is addressed by {20, 4224, 2048, false}, which checks a full 128-row chunk and a final four-row chunk.
  • No new actionable issues were found. CUDA tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Swizzle scales] --> B{Per-tile flag enabled?}
  B -->|No| C[Existing kernels]
  B -->|Yes| D{Supported MXFP8 input?}
  D -->|No| C
  D -->|Yes| E{Single tensor with small grid?}
  E -->|Yes| F[One tile per thread block]
  E -->|No| G[Multi-tensor launch with bounded tile grouping]
Loading

Reviews (5) · Last reviewed commit: "Merge branch 'main' into sraman/mxfp8-sw..." · Reviewed by Greptile

The column-wise multi-tensor case that selects 128-row chunks had only
four scale rows. Add one with 132 scale rows per tensor: a full 128-row
chunk and a clipped last chunk.

Signed-off-by: Siddhartha Raman S <sraman@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vthumbe1503 vthumbe1503 self-assigned this Oct 8, 2026
Resolve the conflicts in swizzle.cu with NVIDIA#3600, which replaced the
file-local get_max_dynamic_smem() with
cuda::max_shared_memory_per_block_optin(): keep the tile-kernel
dispatch, and take the new shared-memory check in the narrow-K and
narrow-M branches it falls back to.

Signed-off-by: Siddhartha Raman S <sraman@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sraman-rgb

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 pytorch

Select the per-tile MXFP8 scale-swizzle kernels with
NVTE_MXFP8_PER_TILE_SWIZZLE=1; by default, the existing kernels run as
before. Give the per-tile code descriptive names (for example
TileSwizzleDesc -> PerTileSwizzleTensor, tpc -> tiles_per_block,
k4_magic -> words_per_row_magic), document the variable, and run the
single- and multi-tensor swizzle tests with it unset and set.

Signed-off-by: Siddhartha Raman S <sraman@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sraman-rgb

Copy link
Copy Markdown
Collaborator Author

│ Scaling factors of │ Row-wise: existing → per-tile │ Column-wise: existing → per-tile │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [4096, 7168] │ 2.63 → 2.27 │ 4.39 → 1.59 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [4096, 2048] │ 1.80 → 1.27 │ 4.41 → 1.44 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [4096, 1536] │ 11.62 → 1.51 │ 10.36 → 1.43 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [4096, 512] │ 3.45 → 1.15 │ 4.46 → 1.59 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [7168, 4096] │ 2.20 → 1.62 │ 4.29 → 1.58 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ [2048, 7168] │ 2.60 → 2.26 │ 2.97 → 1.47 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ 8 x [4096, 7168] │ 5.12 → 3.20 │ 5.02 → 3.23 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ 8 x [4096, 2048] │ 3.35 → 1.78 │ 4.95 → 2.10 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ 8 x [7168, 4096] │ 5.77 → 2.40 │ 4.95 → 3.27 │
├────────────────────┼───────────────────────────────┼──────────────────────────────────┤
│ 32 x [1024, 7168] │ 6.04 → 3.75 │ 7.50 → 5.16 │

@sraman-rgb

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 pytorch

@sraman-rgb

Copy link
Copy Markdown
Collaborator Author

/te-ci L1 pytorch

1 similar comment
@vthumbe1503

Copy link
Copy Markdown
Collaborator

/te-ci L1 pytorch

@vthumbe1503

Copy link
Copy Markdown
Collaborator

LGTM. Perf is definitely better compared to the existing kernels for DSV3 sizes of weights/activations. However, currently the kernels are gated by env variable, since we want to make sure the perf is consistent across the board for all sizes. The variable will be removed once that is verified.

@vthumbe1503
vthumbe1503 merged commit 33e7ff3 into NVIDIA:main Oct 11, 2026
12 of 14 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.

2 participants