Skip to content

Refactor C API for TE 3.0 - #3980

Open
timmoon10 wants to merge 21 commits into
NVIDIA:mainfrom
timmoon10:tmoon/c-api-refactor
Open

timmoon10 wants to merge 21 commits into
NVIDIA:mainfrom
timmoon10:tmoon/c-api-refactor

Conversation

@timmoon10

@timmoon10 timmoon10 commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Description

This PR makes breaking changes in the C API to remove deprecated functions. It also makes changes so the C API actually compiles under C.

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

  • Make sure headers are compatible with C and add a test.
  • Remove deprecated C API functions. In cases where a function has a _v2 variant, the original function is changed to match the _v2 variant.
  • Use bool in C API functions instead of int.
  • Make headers "include what you use".

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

timmoon10 and others added 7 commits December 1, 2026 16:03
Fix the public headers so they compile as C:
- Typedef every NVTE enum and struct and include stdbool.h.
- Replace C++-only members of NVTETensorPack with
  NVTE_TENSOR_PACK_MAX_SIZE.
- Take NVTETensor arrays instead of std::vector in
  nvte_delayed_scaling_recipe_amax_and_scale_update_after_reduction.
- Take tensors by value instead of by reference in context-parallel
  attention functions.
- Give C linkage to nvte_cudnn_handle_init, nvte_cublas_handle_init,
  nvte_built_with_cublasmp, and the permutation functions.
- Remove default arguments, use (void) prototypes, guard
  NVTE_Activation_Type for C++, and drop unneeded CUDA includes.

Add a test that calls every C API function from a C translation unit
compiled with strict flags, so building checks that the headers are
valid C and linking checks that the functions have C linkage. A CTest
checks that the test covers every function declared in the headers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Now that the public headers include stdbool.h, change int arguments
and return values that are logically flags to bool: GEMM transpose
flags, router use_pre_softmax, context-parallel attention flags,
multi-tensor optimizer flags, and the nvte_is_non_tn_fp8_gemm_supported
and nvte_fused_topk_with_aux_loss_scores_is_supported results.

Also fix the is_non_paged documentation, which described the opposite
meaning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
…atures

Give each unversioned C API function the signature and behavior of its
latest _v2 variant, and keep the _v2 names as deprecated aliases that
forward to it. Internal callers in common, PyTorch, JAX, and the tests
now use the unversioned names. The EP functions are left unchanged
while that code is being refactored separately.

Notable consequences:
- nvte_cublas_gemm takes alpha/beta/C and an NVTEMatmulConfig. The
  comm-GEMM overlap code and the distributed test map the old
  bias/GELU/accumulate arguments onto the config.
- The MoE aux-loss kernels only implement the deterministic two-stage
  reduction and require a workspace. The atomic path is removed, the
  PyTorch deterministic keyword is a deprecated no-op that warns, and
  the JAX primitive allocates the workspace.
- nvte_clamped_swiglu/dswiglu take glu_linear_offset and
  nvte_splits_to_offsets_multi takes split_alignment.

Also remove nvte_quantize_noop (use the quantization config's noop
tensor), nvte_cublas_gemm_scaled, and the deprecated _unchecked
fused-router functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Remove nvte_convert_pointers_to_tensor, nvte_group_nvfp4_compute_amax,
and nvte_multi_stream_cublas_gemm. Remove the deprecated FP8 block
scaling tensor format: the quantization config attribute (value 3 is
left unused), the Float8BlockScaleTensorFormat enum and its Python
binding, the QuantizationConfigWrapper setter, and the unreachable
compact-format path in the FP8 1D block-scaling kernel. That kernel now
takes return_rowwise/return_columnwise flags instead of option enums.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Remove nvte_cast_transpose, nvte_cast_transpose_with_noop,
nvte_cast_transpose_dbias, and nvte_cast_transpose_dbias_d{gelu,silu,
relu,qgelu,srelu}. nvte_quantize and nvte_quantize_dbias[_d*] dispatch
to the same kernels for delayed scaling, with the noop tensor passed
through the quantization config. Explicitly instantiate the fused
dbias+dact cast-transpose kernels, which those removed functions
previously instantiated implicitly.

Move nvte_transpose_with_noop to transpose.h and delete
cast_transpose_noop.h.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Each header now directly includes the headers that declare what it
uses: cuda_runtime_api.h for CUDA stream and event types, and
stddef.h, stdint.h, and stdbool.h for size_t, fixed-width integers, and
bool. Unused includes are removed: transformer_engine.h from cudnn.h
and utils.h, stdint.h from ep.h, and cuda.h, cuda_fp8.h, and
<functional> from comm_gemm_overlap.h, which now includes <cstddef>,
<vector>, and logging.h directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Zero NVTETensorPack.size in nvte_tensor_pack_create, since the struct no
longer has a default member initializer. Reject NVFP4 operands in the
comm+GEMM overlap GEMM helper. Remove stale comments and reformat calls
and forwarders affected by the _v2 renames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[High impact] The reviewed changes appear safe to merge; no new actionable issue was established.

Summary

Refactors the C API for TE 3.0 and updates native, PyTorch, and JAX callers.

  • Public headers and the test build now support C callers.
  • Several established function names now use newer API contracts.
  • MoE auxiliary-loss calls now provide workspace for fixed-order reduction.

Reviews (9) · Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." · Reviewed by Greptile

timmoon10 and others added 4 commits December 1, 2026 19:50
The public C API headers now typedef their enums and structs, which
made Doxygen emit both the tag and the typedef and Sphinx report
duplicate C++ declarations. Enable TYPEDEF_HIDES_STRUCT so each type
is documented once under its typedef name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
Building the 4over6 kernels with nvcc fails with "wrong number of
template arguments" for quantize_4over6_kernel::Config now that
NVTENVFP44Over6Mode is a typedef'd C enum. Take the mode as an int
template parameter in Config and compute_error_rn. Config::mode keeps
the enum type, and enum values still convert implicitly, so callers
and the NVRTC source are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tim Moon <[email protected]>
@timmoon10

This comment was marked as outdated.

@timmoon10

Copy link
Copy Markdown
Member Author

/te-ci L1

@jberchtold-nvidia

Copy link
Copy Markdown
Collaborator

LGTM from TE/JAX side

@timmoon10 timmoon10 added the 3.0 label Dec 2, 2026
@timmoon10

Copy link
Copy Markdown
Member Author

/te-ci L1

This branch has not been deployed

No deployments
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.

2 participants