Skip to content

[CUDA] Build compact fpA intB kernels by default - #32324

Merged
Tianlei Wu (tianleiwu) merged 3 commits into
microsoft:mainfrom
tianleiwu:tlwu/compact_fpa_intb_gemm
Aug 31, 2026
Merged

Tianlei Wu (tianleiwu) merged 3 commits into
microsoft:mainfrom
tianleiwu:tlwu/compact_fpa_intb_gemm

Conversation

@tianleiwu

Copy link
Copy Markdown
Contributor

Description

  • Build a compact fpA_intB CUDA kernel set by default: FP16 activations, INT4/INT8 weights, scale-only quantization, and block_size=32.
  • Add onnxruntime_USE_FPA_INTB_GEMM_FULL to retain the complete BF16, zero-point, bias, larger-block-size, and native Hopper kernel matrix when required.
  • Identify the compact configuration with USE_COMPACT_FPA_INTB_GEMM and exclude native Hopper kernels from it.
  • Support the compact non-Hopper kernels on SM75 and newer devices, using SM75 below Ampere, SM89 on Ada, and the SM80 compatibility path otherwise.
  • Keep eligibility, workspace estimation, profiling, prepacked-weight validation, tests, diagnostics, and documentation aligned with the compact contract.

Motivation and Context

The default fpA_intB build compiled many kernel variants that are not required by the FP16 INT4/INT8 RC model contract. A compact default reduces the generated CUDA kernel set while preserving the full matrix behind an explicit build option.

The compact kernels are non-Hopper kernels rather than SM80-only kernels: they support compute capability 7.5 and newer. Native Hopper TMA/WGMMA kernels remain restricted to SM90 and the full build.

Testing

  • Compact CUDA provider and onnxruntime_provider_test build.
  • Full-mode onnxruntime_providers_cuda_llm build.
  • MatMulNBitsWorkspace.*: 14 tests passed.
  • Fp16Int8GroupwiseTest.* and Fp16Int4GroupwiseTest.*: 2 tests passed on SM90 through the non-Hopper compatibility path.
  • Changed-file lintrunner, Python syntax validation, and git diff --check passed.

Rename the compact build define to describe its FP16-only kernel set and restore non-Hopper dispatch support for SM75 and newer devices. Keep runtime eligibility, profiling, tests, diagnostics, and documentation aligned with the compact contract.
@tianleiwu
Tianlei Wu (tianleiwu) marked this pull request as ready for review August 31, 2026 03:00
Copilot AI balanced review requested due to automatic review settings August 31, 2026 03:00

Copilot AI left a comment

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.

Pull request overview

Makes compact FP16 INT4/INT8 CUDA fpA_intB kernels the default while retaining the full kernel matrix behind an option.

Changes:

  • Adds compact/full build configuration and source filtering.
  • Aligns runtime eligibility, dispatch, profiling, validation, and workspace estimation.
  • Updates tests and documentation for the compact contract.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmake/CMakeLists.txt Adds compact and full build modes.
cmake/onnxruntime_cuda_source_filters.cmake Filters unused compact-mode kernels.
docs/contrib_ops/cuda/matmul_nbits.md Documents both kernel modes.
onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemm/fpA_intB_gemm_template.h Adds compact architecture dispatch.
onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemv/dispatcher.h Restricts compact GEMV variants.
onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemv/fpA_intB_gemv.cu Adds compact launch and support logic.
onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.cc Implements compact eligibility and profiling.
onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.h Aligns construction and validation.
onnxruntime/test/contrib_ops/cuda_kernels/fpA_intB_gemm_kernel_test.cc Exercises compact kernel shapes.
onnxruntime/test/contrib_ops/matmul_4bits_test.cc Updates build-specific diagnostics.
onnxruntime/test/providers/cuda/test_cases/matmul_nbits_workspace_test.cc Tests compact eligibility and architecture selection.
onnxruntime/test/python/quantization/test_op_matmulnbits_prepacked_cuda.py Expands prepacked-weight parity coverage.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.cc
Comment thread onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.h
@tianleiwu
Tianlei Wu (tianleiwu) enabled auto-merge (squash) August 31, 2026 03:21
@tianleiwu
Tianlei Wu (tianleiwu) merged commit d59a890 into microsoft:main Aug 31, 2026
90 checks passed
Tianlei Wu (tianleiwu) added a commit that referenced this pull request Aug 31, 2026
## Description

Refine fpA-intB GEMV support checks and test coverage for the compact
kernel configuration introduced by PR #32324. The support query now
evaluates the physical device architecture separately from the selected
kernel/layout architecture, while compact mode remains limited to FP16
groupwise kernels using the non-SM90 layout.

## Summary of Changes

### GEMV support and dispatch

| File | Change |
|------|--------|
| `onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemv/fpA_intB_gemv.h` |
Update the support-query declaration to accept both device and kernel
architectures. |
| `onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemv/fpA_intB_gemv.cu` |
Apply compact/full build checks using separate device and kernel
architecture inputs, including SM90-layout and BF16 constraints. |
| `onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.h` | Pass the
physical device architecture and selected packing architecture to the
support query. |

### Tests

| File | Change |
|------|--------|
|
`onnxruntime/test/contrib_ops/cuda_kernels/fpA_intB_gemm_kernel_test.cc`
| Add support-matrix coverage for combinations of device architecture,
kernel/layout architecture, and kernel type. |
|
`onnxruntime/test/python/quantization/test_op_matmulnbits_prepacked_cuda.py`
| Use compact-compatible `block_size=32` in the configuration-key
fixture so the test exercises fpA-intB instead of falling back. |

## Testing

- CUDA internal tests passed: 123 tests, including
`FpAIntBGemvTest.SupportUsesDeviceAndKernelArchitectures`.
- Four Python configuration-key tests passed against a fresh native
build.
- Both modified translation units compiled successfully with compact
mode disabled/full-mode settings.
- `git show --check` passed with no whitespace errors.
- `lintrunner -a` was attempted; the Ruff, Ruff-format, and ClangFormat
adapters failed without reporting violations in the changed files.

## Motivation and Context

A Hopper device can use either the SM80-compatible packing/layout or the
native SM90 layout. Treating the selected layout architecture as the
device architecture incorrectly rejected valid compatibility-layout
dispatch, while ignoring the layout allowed compact mode to select
unsupported kernels. Keeping these inputs separate makes the support
matrix reflect both hardware capability and the compiled kernel path.

## Checklist

- [x] Tests added/updated
- [x] No breaking changes
- [x] Documentation updated (not applicable)
This was referenced Sep 14, 2026
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