Skip to content

[Common] Optimized kernels for swizzling and remove obsolete narrow scaled kernels - #3682

Merged
vthumbe1503 merged 1 commit into
NVIDIA:mainfrom
vthumbe1503:swizzle-per-tile-default
Oct 28, 2026
Merged

vthumbe1503 merged 1 commit into
NVIDIA:mainfrom
vthumbe1503:swizzle-per-tile-default

Conversation

@vthumbe1503

@vthumbe1503 vthumbe1503 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR introduced rowwise/colwise swizzling kernels targeted at narrow scale width use-cases. The scope of this PR is to

  • Colwise Swizzling: Enable the colwise swizzling optimized kernel(swizzle_columnwise_chunk_kernel) for both narrow scale-width and wide scale-width use-cases. And completely removes the previously existing kernel for narrow scale width kernel. The previously existing kernel for wide scale-width is retained since that is still used for grouped swizzling. Using the kernel in grouped swizzling will be a follow up PR.
  • Rowwise swizzling: Enable rowwise swizzling optimized kernel(swizzle_rowwise_full_width_kernel) for narrow scale-width use-cases. For wide scale-width, we fall back to our previosuly existing rowwise scaling kernel which operates on 128128N tile where N is vectorization's bit width. Fall back is implemented through shared memory heuristics
    • If scale is sufficiently narrow (smem ~= 128*padded_k <= 17KB), new kernel is better
    • For roughly 17–30 KiB of shared memory, use the full-width kernel for at most 16 row tiles or when the total row tiles exceed the current GPU’s SM count. The SM-count cutoff replaces the previous hard-coded 128-tile threshold. Otherwise use the generic rowwise kernel.
  • Optimized row scaling kernel is also extended to be use for NVFP4.
    • Apt unit tests are also added
  • 16 byte Alignment requirement for Swizzling kernels
    • Previously existing kernels had the minimum 4 byte alignment requirement. But even that was never checked
    • Now we have kernels for most of the use-cases doing a int4 read/write and hence 16 byte alignment is a must for both input and output scale pointers.

Blackwell Perf results

MXFP8 rowwise

ShapeBefore (µs)After (µs)Speedup
4096×1282.1111.1831.784×
4096×2562.8181.2892.186×
4096×5124.4131.2473.538×
4096×7686.0141.5373.912×
4096×10248.2041.6644.932×
4096×128010.2781.7935.731×
4096×153613.5761.7297.852×
4096×166422.6351.81112.502×
4096×179225.2651.80613.990×
4096×19202.0831.8261.141×
4096×20482.0491.5051.362×
4096×25602.3031.9131.204×
4096×40962.5512.1301.198×
2048×71683.0332.8861.051×
4096×71683.5193.5171.001×

MXFP8 columnwise

ShapeBefore (µs)After (µs)Speedup
4096×153613.7361.6018.580×
4096×5125.5481.6003.467×
4096×20485.1141.6313.135×
4224×20484.9901.6313.059×
4096×71685.3702.4272.213×
7168×40965.2882.4312.175×
2048×71683.4221.6652.055×

MXFP8 multi-tensor rowwise

ShapeNBefore (µs)After (µs)Speedup
7168×409688.3884.4281.894×
4096×204884.8462.5891.872×
4096×12842.4971.4711.697×
16384×12842.4651.4731.673×
256×25642.0791.3771.510×
2048×7168157.2136.1621.171×
4096×716887.1076.0851.168×

MXFP8 multi-tensor columnwise

ShapeNBefore (µs)After (µs)Speedup
4096×204885.9893.1591.896×
4224×2048207.7214.8391.596×
1024×71683210.7777.4191.453×
4224×2048136.1674.5201.364×
4096×716886.5475.1901.262×
7168×409686.5615.8041.130×

Rubin perf results

MXFP8 rowwise

ShapeBefore (µs)After (µs)Speedup
4096×153611.4331.6157.077×
4096×5123.3401.1812.827×
4096×1281.6051.1561.388×
4096×20481.8841.3691.376×
4096×40962.3102.0371.134×
2048×71682.6812.4821.080×
4096×71683.1483.1481.000×

MXFP8 columnwise

ShapeBefore (µs)After (µs)Speedup
4096×153610.3141.4956.900×
4096×20484.4431.5162.931×
4096×5124.2461.4822.864×
4224×20484.3551.5162.873×
4096×71684.8182.2392.152×
7168×40964.7002.2332.105×
2048×71683.0461.5811.926×

MXFP8 multi-tensor rowwise

ShapeNBefore (µs)After (µs)Speedup
7168×409687.0633.7731.872×
4096×204884.3022.4111.784×
4096×12842.1701.3711.583×
16384×12842.1441.4341.495×
256×25641.7691.3601.300×
4096×716886.1745.5291.117×
2048×7168156.2015.5591.115×

MXFP8 multi-tensor columnwise

ShapeNBefore (µs)After (µs)Speedup
4096×204885.5252.7312.023×
4224×2048207.8354.6091.700×
4224×2048135.3493.5721.498×
4096×716885.7044.2941.328×
1024×7168328.7246.6891.304×
7168×409685.6654.8371.171×

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

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

@vthumbe1503 vthumbe1503 changed the title [Pytorch][Common] Get rid of Narrow width Swizzle kernels for the newly optimized kernels [Common] Get rid of Narrow width Swizzle kernels for the newly optimized kernels Oct 13, 2026
@vthumbe1503 vthumbe1503 changed the title [Common] Get rid of Narrow width Swizzle kernels for the newly optimized kernels [Common] Optimized kernels for Narrow width row scaled swizzling and columnwise swizzling Oct 14, 2026
@vthumbe1503 vthumbe1503 changed the title [Common] Optimized kernels for Narrow width row scaled swizzling and columnwise swizzling [Common] Optimized kernels for swizzling and remove obsolete narrow scaled kernels Oct 14, 2026
@vthumbe1503
vthumbe1503 marked this pull request as ready for review October 14, 2026 06:19
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new actionable issue was found.

Summary

This PR makes the optimized swizzle kernels the default and removes the obsolete narrow kernels.

  • Scale swizzling now picks optimized rowwise and columnwise kernels automatically.
  • Swizzle calls now reject scale buffers that are not 16-byte aligned.

The earlier threads are unnumbered, so they have no entries in previousFindings. Their reported problems are addressed by the current size checks, padded NVFP4 tests, selected-buffer dimensions, and explicit alignment requirement.

Reviews (13) · Last reviewed commit: "Optimize scale swizzle kernels" · Reviewed by Greptile

Comment thread tests/cpp/operator/test_swizzle.cu Resolved
@ptrendx

ptrendx commented Oct 16, 2026

Copy link
Copy Markdown
Member

@vthumbe1503 Please sign every commit in this PR. See https://github.com/NVIDIA/TransformerEngine/blob/main/CONTRIBUTING.rst#sign-your-work

@vthumbe1503
vthumbe1503 force-pushed the swizzle-per-tile-default branch from 12213fd to 540f974 Compare October 16, 2026 21:50
@vthumbe1503
vthumbe1503 requested a review from ptrendx October 16, 2026 21:55
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci L0

@vthumbe1503
vthumbe1503 force-pushed the swizzle-per-tile-default branch from e5fe40f to d586c99 Compare October 23, 2026 16:19
@vthumbe1503
vthumbe1503 force-pushed the swizzle-per-tile-default branch 2 times, most recently from a7fd8fb to 8ae90bc Compare October 25, 2026 19:55
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci L0

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, just a few minor fixes

Comment thread tests/cpp/operator/test_swizzle.cu Resolved
@vthumbe1503
vthumbe1503 force-pushed the swizzle-per-tile-default branch 2 times, most recently from b9634d4 to 56f0f45 Compare October 27, 2026 20:04
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci L0

@vthumbe1503
vthumbe1503 force-pushed the swizzle-per-tile-default branch from a1641e9 to 583a7f4 Compare October 27, 2026 23:55
Oleg-Goncharov
Oleg-Goncharov previously approved these changes Oct 28, 2026

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Use optimized rowwise full-width and columnwise chunk kernels for MXFP8 and NVFP4 scales, including multi-tensor swizzling. Keep the 16-byte scale-buffer alignment contract and cover its validation in C++ tests.

Choose the rowwise full-width kernel after the fallback grid exceeds one SM wave, based on paired GB200 and VR200 measurements.

Signed-off-by: Varun Thumbe <vthumbe@nvidia.com>
@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

/te-ci L0

@Oleg-Goncharov
Oleg-Goncharov self-requested a review October 28, 2026 15:50

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vthumbe1503

Copy link
Copy Markdown
Collaborator Author

Pipeline: 77344495

@vthumbe1503
vthumbe1503 merged commit e614b7a into NVIDIA:main Oct 28, 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.

3 participants