Skip to content

[Common] Experimental CuTeDSL MXFP8 backends in C++ via TVM-FFI - #3137

Merged
ptrendx merged 180 commits into
NVIDIA:mainfrom
kainzhong:cutedsl_mxfp8_common
Sep 29, 2026
Merged

ptrendx merged 180 commits into
NVIDIA:mainfrom
kainzhong:cutedsl_mxfp8_common

Conversation

@kainzhong

@kainzhong kainzhong commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds an experimental, opt-in CuTeDSL backend for MXFP8 quantization. MXFP8 nvte_quantize calls can be routed to JIT-compiled CuTeDSL (CUTLASS Python DSL) kernels instead of the existing CUDA C++ kernels, bridged into the C++ dispatcher via apache-tvm-ffi (https://github.com/apache/tvm-ffi).

It's off by default (use NVTE_ENABLE_CUTEDSL_QUANT_BACKEND=1 to enable) and transparently falls back to the CUDA kernels for any unsupported config or shape (use NVTE_WARN_IF_CUTEDSL_BACKEND_NOT_CHOSEN=1 to enable warning for unsupported cases).

How it works

  • Python CuTeDSL kernels (transformer_engine/common/CuTeDSL/) register a factory as a TVM-FFI global.
  • On a matching MXFP8 quantize, the C++ dispatcher builds a config key, asks Python to JIT-compile + register a kernel for that config (cached), then invokes it with DLTensor views of the TE tensors.
  • Any miss (backend disabled, unsupported config, non-32-aligned shape) returns false → existing mxfp8::quantize CUDA path runs unchanged.

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

  • Added utility classes and functions to retrieve TVM-FFI global functions using strings
  • Ported MXFP8 CUDA C++ quantization code to CuTeDSL

Breaking changes:

  • Building TE from python now requires apache-tvm-ffi package installed. If building the C++ lib, you can pass NVTE_WITH_CUTEDSL to cmake to opt-out.
  • apache-tvm-ffi and nvidia-cutlass-dsl packages are TE's dependency now.

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

@kainzhong
kainzhong force-pushed the cutedsl_mxfp8_common branch from daee750 to 218cd24 Compare June 27, 2026 08:27
@kainzhong
kainzhong force-pushed the cutedsl_mxfp8_common branch 4 times, most recently from 2f8c8da to 8448930 Compare July 8, 2026 21:44
@kainzhong
kainzhong marked this pull request as ready for review July 8, 2026 23:25
@greptile-apps

greptile-apps Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Adds optional CuTeDSL backend with new build-time and runtime dependencies.

The PR is not ready to merge while the new device-count limit can fail quantization.

Findings

  1. P1 Device count limit breaks quantization ▶
  2. P2 Backend tests always skip ▶

Summary

The PR adds an opt-in CuTeDSL MXFP8 quantization path through TVM-FFI, with build controls and cross-backend tests. Since the previous review, kernel first-launch state was changed to use a fixed-size device array; that introduces a failure on hosts with more than 32 visible devices.

Reviews (84) · Last reviewed commit: "nit"

Comment thread build_tools/pytorch.py
Comment thread transformer_engine/common/CuTeDSL/cast/mxfp8/quantize_mxfp8.py Outdated
Comment thread build_tools/pytorch.py Outdated
Comment thread build_tools/pytorch.py Outdated
Comment thread setup.py Outdated
Comment thread tests/pytorch/mxfp8/test_mxfp8_cutedsl_backend.py Outdated
Comment thread tests/pytorch/mxfp8/test_mxfp8_cutedsl_backend.py Outdated
Comment thread transformer_engine/common/CuTeDSL/__init__.py Outdated
Comment thread transformer_engine/common/CuTeDSL/activations.py Outdated
Comment thread transformer_engine/common/CuTeDSL/activations.py Outdated
Comment thread transformer_engine/common/CuTeDSL/activations.py Outdated
Comment on lines +44 to +70
std::string to_key() const {
std::string key;
key.reserve(56);
key.append("cutedsl_mxfp8_")
.append(te_dtype_to_str(dtype))
.append("_")
.append(te_dtype_to_str(fp8_dtype))
.append("_")
.append(rowwise ? "1" : "0")
.append("_")
.append(colwise ? "1" : "0")
.append("_")
.append(swizzled ? "1" : "0")
.append("_")
.append(with_amax ? "1" : "0")
.append("_")
.append(with_dbias ? "1" : "0")
.append("_")
.append(with_dact ? "1" : "0")
.append("_")
.append(with_act ? "1" : "0")
.append("_")
.append(with_noop ? "1" : "0")
.append("_")
.append(activation_to_str(activation));
return key;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Kind of random, but this function is quite slow. You could do the same much faster with raw char*
manipulation.

@kainzhong kainzhong Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Emmmm but I reserved 56 chars before I do append. I don't know if char* will be faster than this since they both don't require resizing the string?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You still need to create those additional 1-letter strings in this version. At the very least you could make a "1_" and "0_" strings upfront and use those instead (also, you don't even need the underscore there between those 1s and 0s).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah OK I just made some changes. Now every quantization config owns their cache and the cache key is uint32 now. This to_key is now only used to build the function name used when registering the function to TVM-FFI registry and it happens only once when you request a not yet ready kernel. Later we will fetch it from C++ cache with uint32 cache key which is more efficient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

concat_strings is more ergonomic and it doesn't need the bool ? "1" : "0" pattern. It also gets rid of some, but not all, of the heap allocations.

inline std::string concat_strings(const Ts &...args) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One thing to note also is the cache key should include at least the SM arch of the device that was used for the compilation - otherwise there is a chance in the heterogeneous gpu setup to try running the kernel compiled for 1 architecture on another architecture.

Comment thread transformer_engine/common/cast/mxfp8/quantize_mxfp8_cutedsl.cuh
Comment thread transformer_engine/common/cast/mxfp8/quantize_mxfp8_cutedsl.cuh
Comment thread transformer_engine/common/CMakeLists.txt Outdated
@kainzhong
kainzhong force-pushed the cutedsl_mxfp8_common branch from 948fab5 to 2930b1b Compare July 10, 2026 00:34
Comment thread transformer_engine/common/CuTeDSL/utils_fp8.py Outdated
Comment thread transformer_engine/common/CuTeDSL/utils.py Outdated
Comment thread transformer_engine/common/__init__.py Outdated
@kainzhong
kainzhong force-pushed the cutedsl_mxfp8_common branch from af55445 to 87adfe7 Compare July 24, 2026 18:33
Comment thread transformer_engine/common/CuTeDSL/utils.py Outdated
Comment thread transformer_engine/common/cast/mxfp8/quantize_mxfp8_cutedsl.cuh Outdated
Comment thread tests/pytorch/mxfp8/test_mxfp8_cutedsl_backend.py Outdated
Comment thread tests/pytorch/mxfp8/test_mxfp8_cutedsl_backend.py
@kainzhong
kainzhong force-pushed the cutedsl_mxfp8_common branch from 6e55eef to c47fc5c Compare July 27, 2026 20:09
kainzhong and others added 5 commits July 27, 2026 20:09
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
for more information, see https://pre-commit.ci

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 and others added 5 commits September 19, 2026 01:48
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>
python3.10 --version
python3.10 -m pip install torch==${MIN_TORCH_VERSION}
python3.10 -m pip install cmake pybind11[global] ninja pydantic "importlib-metadata>=1.0" packaging einops onnxscript "nvidia-cudnn-frontend>=1.25.0"
python3.10 -m pip install cmake pybind11[global] ninja pydantic "importlib-metadata>=1.0" packaging einops onnxscript "nvidia-cudnn-frontend>=1.25.0" "apache-tvm-ffi>=0.1.12"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@fheinecke I modified this so GitHub CI can pass. Is this OK?

Comment thread qa/L1_cppunittest_cutedsl_off/test.sh
Comment thread docs/installation.rst Outdated
Comment on lines +104 to +106
# apache-tvm-ffi is required to build the CuTeDSL bridge when using --no-build-isolation.
# If that's not wanted, set NVTE_WITH_CUTEDSL=0 to build without CuTeDSL and tvm-ffi bindings.
pip3 install "apache-tvm-ffi>=0.1.12"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: This is a quickstart for naive users, who shouldn't need to be aware of advanced configurations like NVTE_WITH_CUTEDSL=0.

Suggested change
# apache-tvm-ffi is required to build the CuTeDSL bridge when using --no-build-isolation.
# If that's not wanted, set NVTE_WITH_CUTEDSL=0 to build without CuTeDSL and tvm-ffi bindings.
pip3 install "apache-tvm-ffi>=0.1.12"
pip3 install apache-tvm-ffi>=0.1.12 # Install build-time dependencies

Comment thread README.rst Outdated
Comment on lines +230 to +236
# Required by the default CuTeDSL-enabled build when using --no-build-isolation.
pip install "apache-tvm-ffi>=0.1.12"
pip install --no-build-isolation git+https://github.com/NVIDIA/TransformerEngine.git@stable

Set ``NVTE_WITH_CUTEDSL=0`` on the second command to build without the optional CuTeDSL bridge
and apache-tvm-ffi as its python build dependency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: This is a minimal build guide for naive users. Documenting advanced options here is distracting.

Suggested change
# Required by the default CuTeDSL-enabled build when using --no-build-isolation.
pip install "apache-tvm-ffi>=0.1.12"
pip install --no-build-isolation git+https://github.com/NVIDIA/TransformerEngine.git@stable
Set ``NVTE_WITH_CUTEDSL=0`` on the second command to build without the optional CuTeDSL bridge
and apache-tvm-ffi as its python build dependency.
pip install apache-tvm-ffi>=0.1.12 # Build-time dependencies
pip install --no-build-isolation git+https://github.com/NVIDIA/TransformerEngine.git@stable

@ptrendx ptrendx mentioned this pull request Sep 23, 2026
1 of 13 tasks
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Comment thread build_tools/wheel_utils/build_wheels.sh
Comment thread qa/L0_pytorch_unittest/test.sh Outdated
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_fused_rope.xml $TE_PATH/tests/pytorch/test_fused_rope.py || test_fail "test_fused_rope.py"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_nvfp4.xml $TE_PATH/tests/pytorch/nvfp4 || test_fail "test_nvfp4"
python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_mxfp8.xml $TE_PATH/tests/pytorch/mxfp8 || test_fail "test_mxfp8"
NVTE_WARN_IF_CUTEDSL_BACKEND_NOT_CHOSEN=1 python3 -m pytest --tb=auto --junitxml=$XML_LOG_DIR/pytest_test_mxfp8.xml $TE_PATH/tests/pytorch/mxfp8 || test_fail "test_mxfp8"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Backend tests always skip

This job sets only the fallback-warning variable, not NVTE_ENABLE_CUTEDSL_BACKEND=1. The new PyTorch test module skips every CuTeDSL comparison when that enable variable is unset, so L0 collects the suite without exercising the new backend. The same issue occurs in qa/L0_jax_unittest/test.sh:31, whose new JAX comparison module uses the same skip gate. This leaves the feature without its intended L0 correctness coverage.

kainzhong and others added 2 commits September 23, 2026 21:02
* disable CuTeDSL support and other fix

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

* remove docs that mention CuTeDSL since they are off by default now

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

* fix

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

* remove test_cutedsl_backend.cpp

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

* make envvar.rst more human

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>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Comment thread transformer_engine/common/init_python.cpp Outdated
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Comment thread transformer_engine/common/cast/mxfp8/quantize_mxfp8_cutedsl.cuh Outdated
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Comment on lines +45 to +46
NVTE_CHECK(num_devices <= kMaxDevices,
"Too many visible CUDA devices for CuTeDSL: ", num_devices);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Device count limit breaks quantization

If a host has more than 32 visible CUDA devices, the first supported CuTeDSL quantization throws while creating its kernel state. The call fails instead of launching the kernel or falling back to CUDA. The previous dynamically sized array handled the device count returned by CUDA.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Currently a host won't have so many CUDA devices plus this workaround will be removed once I know how to fix CuTeDSL's end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Understood. Given that hosts with more than 32 visible CUDA devices are not an expected deployment scenario for this experimental backend, and this workaround will be removed once the CuTeDSL limitation is resolved, I’ll treat the risk as accepted.

@ptrendx
ptrendx merged commit eb56ba2 into NVIDIA:main Sep 29, 2026
12 checks passed
fheinecke pushed a commit that referenced this pull request Sep 29, 2026
* start draft

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

* remove benchmark scripts

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* add license

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

* fix

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

* make cutlass dsl required

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

* fix linting errors

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* warn failed compilation

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* make tvm-ffi common dependency

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

* use a higher version for cutlass-dsl

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

* less comment

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

* skip zeroing buffer if noop flag set

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

* refactor activations

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

* fix

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

* lint

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

* fix

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* nit

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

* maybe it's better to prepare tvm-ffi & cutedsl kernels in common/__init__.py

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* nit

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* fix

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* fix

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

* fix

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

* fix

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

* also flush colwise scale in SMEM

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

* use explicit fp8 types

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* nit

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

* add checks

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

* refactor

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

* nit

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

* nit

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

* nit

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

* fi

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

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

* nit

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

* nit

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

* skip comparision test if cutedsl disabled

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

* fix

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

* Merge pull request #3 from janekb04/cutedsl_mxfp8_common

Perform noop tensor check on device

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

* add test to the qa script

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

* warn only once if dlopen fails

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

* fix

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

* let tests cover swizzling

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

* warn not chosen cutedsl kernel during testing

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

* improve lazyload so now the cache is uint32

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* let tests be verbose about warnings so we know if cutedsl kernel is not dispatched

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

* support swizzled scale for specialized kernel but disable it

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

* fix

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

* nit

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

* fix inline ptx

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

* more fix

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

* revert to mul

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

* nit

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add jax tests

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

* also ignore noop when dbias

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* relax dim check for the kernels

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

* reject 2D quant

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

* run more tests with CuTeDSL path

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make rowwise only handle divisible cases

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

* fallback to CUDA if not TMA aligned

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* specialize skip masking version

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

* nit

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add type annotations

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* optimize masking

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

* skip masking for some acts

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* allow user to opt out from building with CuTeDSL

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

* better warning

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

* doc

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add jax test coverage for cutedsl

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

* fix device sm query

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

* catch more python error

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nit

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

* nit

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

* nit

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

* fix

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

* make tvm-ffi required for python users

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

* optimize dbias

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* skip scale bound check whenever possible

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* allow colwise to fuse relu too

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

* dispatch to rowwise specialized with swizzled scale

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

* don't link tvmffi if building a standalong C++ lib without framework

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

* change some logging

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

* use the right fast math flag

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

* also let test script use NVTE_DEBUG

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

* also let mutex cover the loading of tvm-ffi func

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

* locate tvm-ffi include dir from setup_common_extension

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

* fix how tests run with cutedsl enabled

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nit

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

* reduce framework scope tests run with cutedsl backend

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

* allow C++ tests to run with cutdsl

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

* remove tvmffi and cutlass dependencies from setup.py due to being optional

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

* encode sm numbers in tvm_ffi function name & cache key

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

* make C++ tests run in sequential

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

* make CuTeDSL default and cover C++ in L1

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

* Improvements and fix to CuTe DSL kernel launches (#7)

* [Common] Bypass Python wrapper overhead with __tvm_ffi_object__

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Avoid heap allocations in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Avoid querying device in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Fix packed dtype handling in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* Apply review suggestions

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

---------

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix dispatching so it never uses specialized if grid won't fit

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

* also add tests

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

* Minor fixes to CuTe DSL infrastructure (#8)

* Improvements and fix to CuTe DSL kernel launches (#7)

* [Common] Bypass Python wrapper overhead with __tvm_ffi_object__

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Avoid heap allocations in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Avoid querying device in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Fix packed dtype handling in DLTensorWrapper

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* Apply review suggestions

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

---------

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [Common] Add missing dtypes to CuTe DSL dispatch

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

* [Common] Add line information to CuTe DSL inline PTX helpers

Signed-off-by: Jan Bielak <jbielak@nvidia.com>

---------

Signed-off-by: Jan Bielak <jbielak@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add missing ip & loc

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

* refactor so we don't need #pragma to avoid collision in tests

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

* whoops

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

* whoops again

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

* rename NVTE_ENABLE_CUTEDSL_QUANT_BACKEND to NVTE_ENABLE_CUTEDSL_BACKEND

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

* switch back to NVTE_WARN_IF_CUTEDSL_BACKEND_NOT_CHOSEN

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

* use TE's to_string to convert dtype to str

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

* remove MXFP8QuantFused

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

* move python init from tests to TE lib

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

* software path for e8m0 conversion

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nit

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

* remove unreachable branch

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

* fold quantize_mxfp8_cutedsl_config.h back to quantize_mxfp8_cutedsl.h

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

* nit

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

* nit for some C++

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

* rewrite dsl_user_op to cute.jit if possible and let compiler optimize

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

* fix python init

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

* prefere inline_ptx instead of llvm.inline_asm

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nit

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

* fix activation encoding

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

* remove unused device_is_blackwell function

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

* link C++ test executable to libtvm_ffi.so

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

* move cutedsl utils from math.h to a separate file

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

* recover test_cast_mxfp8.cu

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

* no need to init extension now

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

* hoist importorskip in cutedsl python tests

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

* fix activation_func_to_enum so it works with CUDA 12.8

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

* make NVTE_WITH_CUTEDSL both a env var and a cmake option

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

* fix TE path searching for python bootstrap

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

* when enabling cutedsl manually, also initialize python if it's not done before

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

* use dlsym

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

* fix

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

* nit

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

* let main TE lib link to Python::Module

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

* add a test to cover untested manually enable cutedsl path

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

* fix

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nit

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

* update min ver workflow

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

* rename L1 CUDA C++ UT

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

* fix build issues for CuTeDSL backend (#10)

* disable CuTeDSL support and other fix

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

* remove docs that mention CuTeDSL since they are off by default now

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

* fix

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

* remove test_cutedsl_backend.cpp

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

* make envvar.rst more human

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

---------

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

* fix

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

* fix python tests

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

* skip L1 C++ UT with CUDA when CuTeDSL is not enabled globally

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

* fix

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

* fix C++ UT python discovery

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

* fix deadlock for multigpu

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

* fix python init

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

* fix python init again thanks to codex

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

* refactor the serialized initial launch

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

* nit

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

---------

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Jan Bielak <jbielak@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jan Bielak <janekb04@icloud.com>
Co-authored-by: Jan Bielak <jbielak@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants