Skip to content

Don't rely on cuda.core for compute capability check - #3743

Merged
kainzhong merged 13 commits into
NVIDIA:mainfrom
CarlosGomes98:cgomes/cutedsl-cuda-bindings-device-capability
Nov 4, 2026
Merged

kainzhong merged 13 commits into
NVIDIA:mainfrom
CarlosGomes98:cgomes/cutedsl-cuda-bindings-device-capability

Conversation

@CarlosGomes98

@CarlosGomes98 CarlosGomes98 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Cutedsl kernels rely on cuda.core to check compute capability, but this is not a TE dependency.

This will make CI able to run using CuTeDSL kernels instead of falling back to CUDA kernels. It also fixes how a all NaN 32 element block is handed so now the scale will be NaN instead of 0 when all elements are NaN, and it's consistent across different configurations for both CUDA and CuTeDSL so the CI tests can pass.

Fixes #3793

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:

  • Replace cuda.core with cuda.bindings
  • Fix NaN handling in MXFP8 quantization kernels

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

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Oct 26, 2026
@CarlosGomes98
CarlosGomes98 force-pushed the cgomes/cutedsl-cuda-bindings-device-capability branch from a7faf28 to 0a9181e Compare October 26, 2026 16:30
@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

This PR replaces the compute-capability query’s cuda.core dependency with cuda.bindings and aligns MXFP8 scale behavior across CUDA and CuTeDSL.

  • MXFP8 scales preserve NaNs for full blocks of NaNs.
  • CuTeDSL checks GPU capability without needing cuda.core.

Reviews (9) · Last reviewed commit: "fix" · Reviewed by Greptile

kainzhong
kainzhong previously approved these changes Oct 26, 2026
@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci

@CarlosGomes98
CarlosGomes98 force-pushed the cgomes/cutedsl-cuda-bindings-device-capability branch from 0a9181e to a8dd393 Compare October 28, 2026 08:45
Signed-off-by: CarlosGomes98 <carlosmiguel.gomes@live.com.pt>
@CarlosGomes98
CarlosGomes98 force-pushed the cgomes/cutedsl-cuda-bindings-device-capability branch from a8dd393 to 07fc40d Compare October 28, 2026 08:48
@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci L0

"""(major, minor) compute capability of a CUDA device (current by default), or (0, 0) if it can't be queried."""
from cuda.core import Device # pylint: disable=no-name-in-module
# pylint: disable=c-extension-no-member
from cuda.bindings import runtime as cudart # pylint: disable=no-name-in-module

@tdophung tdophung Oct 28, 2026 •

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.

you should have docs/envvars.rst include cuda.bindings, instead of cuda.core, also?

@tdophung tdophung Oct 28, 2026 •

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.

seems like cuda-bindings already comes in transitively with nvidia-cutlass-dsl, as shown when I did this on dlcluster venv:

pip show cuda-bindings cuda-python cuda-core nvidia-cutlass-dsl-libs-base nvidia-cutlass-dsl-libs-cu12 | grep -E "^(Name|Version|Requires|Required-by)"
  WARNING: Package(s) not found: cuda-core, cuda-python
  Name: cuda-bindings
  Version: 13.4.4
  Requires: cuda-pathfinder
  Required-by: nvidia-cutlass-dsl-libs-base, nvidia-cutlass-dsl-libs-core, nvidia-cutlass-dsl-libs-cu12
  Name: nvidia-cutlass-dsl-libs-base
  Version: 4.8.1
  Requires: backports.strenum, cuda-bindings, nvidia-cutlass-dsl-libs-core, protobuf, typing-extensions
  Required-by: nvidia-cutlass-dsl, nvidia-cutlass-dsl-libs-cu12
  Name: nvidia-cutlass-dsl-libs-cu12
  Version: 4.8.1
  Requires: backports.strenum, cuda-bindings, nvidia-cutlass-dsl-libs-base, protobuf, typing-extensions
  Required-by: nvidia-cutlass-dsl

Disregard comment

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
@kainzhong

kainzhong commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

@CarlosGomes98 OK actually with your fix, our C++ unit tests will no longer fall back to CUDA and will use CuTeDSL kernels, which reveals an tiny mismatch in my CuTeDSL kernels that would cause a non-bit-exact result than CUDA's

Can you merge CarlosGomes98#1 into your branch? So we can let CI pass for now. I'll ask around to see if this is the canon behavior or we should do the other way around and probably open another PR to flip both CUDA and CuTeDSL

@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci

kainzhong and others added 3 commits October 30, 2026 17:37
This reverts commit 1b5cf2e.

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
The fused/general MXFP8 quantize kernel started each block amax at 0
with a
NaN-ignoring max, so an all-NaN block (e.g. dGeLU/dSiLU/dQGeLU of +-inf)
got
scale 0x00. The CuTeDSL kernels and CUDA's specialized cast-only kernels
give
0xFF, the E8M0 NaN code, which is the agreed behavior.

Seed the per-block amax with NaN instead, so it stays NaN only when
every
element is NaN. Out-of-bounds elements now count as 0 in the activation
paths
(as TMA zero-fill already does without activations), so fully-OOB blocks
do
not write 0xFF into the scale padding. 2D block scaling keeps the 0 seed
since
its warp reduction assumes a non-negative amax. The tensor amax still
ignores
NaN.

Update the C++ reference to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
[Common] Let CuTeDSL match CUDA's NaN handling
…ize kernel"

This reverts commit 1c7d712.

The all-NaN MXFP8 block scale will be standardized on 0xFF in a follow-up. Until
then, keep CUDA and CuTeDSL agreeing on 0.

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci

This reverts commit cb5619e.

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci

1 similar comment
@kainzhong

Copy link
Copy Markdown
Collaborator

/te-ci

Comment thread tests/cpp/operator/test_cast_mxfp8.cu Resolved
@kainzhong
kainzhong merged commit 4e7fee5 into NVIDIA:main Nov 4, 2026
35 of 38 checks passed
tdophung added a commit to tdophung/TransformerEngine that referenced this pull request Nov 10, 2026
…block scales

- SiLU is x * sigmoid(x), as util/math.h computes it; x / (1 + exp(-x))
  rounds differently, so FP32 SiLU differed from CUDA.
- The general kernel carries one dbias sum down the column across its stages,
  as the CUDA kernels do, instead of adding 32-row partial sums.
- With FP16 or FP32 input, the register-resident kernel seeds its block amaxes
  with NaN, so a block of only NaNs gets the NaN scale (0xFF), as in CUDA's
  generic kernel since PR NVIDIA#3743 and in the other CuTeDSL kernels.
- FP32 dbias+dGeLU takes the register-resident kernel, whose dbias matches
  CUDA (the general kernel's still differs in the last bit for FP32).

mxh2 parity against TE main (CUDA), tables off, 702 cases over BF16/FP16/FP32,
all modes, layouts and fills including special values: 678 match (PR NVIDIA#3642
alone: 464). The rest are FP32 dbias with rowwise-only output, where CUDA adds
row pairs (r, r + 32) before summing.

Signed-off-by: Teddy Do <tdophung@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Common] Inconsistent scales with MXFP8 quantization when all values are NaN

3 participants