NVIDIA / NVIDIA/cutlass

[FEA] Add INT8 support for sm_120 CollectiveBuilder (TmaWarpSpecialized)

Open
#2,717 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

? - Needs Triage CUTLASS C++ feature request inactive-30d inactive-90d
Dominant language
C++
Stars
10.5k
Forks
2.1k
Avg merge
3d 11h
Merged PRs (30d)
7

Description

Which component requires the feature?

CUTLASS C++

Feature Request

SM120 TmaWarpSpecialized builder supports for int_8

Hello,
Currently, I am trying to write an INT8 GEMM kernel for the Blackwell architecture (targeting sm_120), but I am encountering a compilation error.

TL;DR

how can we write a int8_gemm cuda kernel using cutlass now

Environment
  • GPU: NVIDIA RTX 5090 (blackwell arch)
  • CUDA: 12.8
  • CUTLASS Version: 7817e47154d7869320f3fa6b409ec8c5e5958970
Description

I am trying to compile an INT8 GEMM kernel for the sm_120 architecture using the CUTLASS 3.x CollectiveBuilder.
My policy struct is correctly configured to deduce ElementAccumulator as int32_t when the input type ElementAB is int8_t.
Here is my core policy struct:

template <typename ElementAB_, typename ElementD_,
          template <typename, typename, typename> typename Epilogue_,
          typename TileShape, typename ClusterShape, typename KernelSchedule,
          typename EpilogueSchedule>
struct cutlass_3x_gemm_sm120 {
  using ElementAB = ElementAB_; // int8_t
  using LayoutA = cutlass::layout::RowMajor;
  static constexpr int AlignmentA =
      128 / cutlass::sizeof_bits<ElementAB>::value;

  using LayoutB = cutlass::layout::ColumnMajor;
  static constexpr int AlignmentB =
      128 / cutlass::sizeof_bits<ElementAB>::value;

  using ElementD = ElementD_; // e.g., bfloat16_t
  using LayoutD = cutlass::layout::RowMajor;
  static constexpr int AlignmentD = 
      128 / cutlass::sizeof_bits<ElementD_>::value;

  // Correctly deduce accumulator type
  using ElementAcc =
      typename std::conditional<std::is_same_v<ElementAB, int8_t>, int32_t,
                                float>::type; // Becomes int32_t
  using Epilogue = Epilogue_<ElementAcc, ElementD, TileShape>;

  // Use the deduced accumulator type for MMA
  using ElementAccumulator = ElementAcc; // Correctly set to int32_t

  using ElementCompute = float;
  using ElementC = void;
  using LayoutC = cutlass::layout::RowMajor;
  static constexpr int AlignmentC = AlignmentD;
  
  using EVTCompute = typename Epilogue::EVTCompute;

  using CollectiveEpilogue =
      typename cutlass::epilogue::collective::CollectiveBuilder<
          cutlass::arch::Sm120, cutlass::arch::OpClassTensorOp, TileShape,
          ClusterShape, cutlass::epilogue::collective::EpilogueTileAuto,
          ElementAccumulator, ElementCompute, ElementC, LayoutC, AlignmentC,
          ElementD, LayoutD, AlignmentD, EpilogueSchedule,
          EVTCompute>::CollectiveOp;

  using CollectiveMainloop =
      typename cutlass::gemm::collective::CollectiveBuilder<
          cutlass::arch::Sm120, cutlass::arch::OpClassTensorOp, ElementAB,
          LayoutA, AlignmentA, ElementAB, LayoutB, AlignmentB,
          ElementAccumulator, TileShape, ClusterShape,
          cutlass::gemm::collective::StageCountAutoCarveout<...>,
          KernelSchedule>::CollectiveOp;

  using GemmKernel = cutlass::gemm::kernel::GemmUniversal<
      Shape<int, int, int, int>, CollectiveMainloop, CollectiveEpilogue, void>;
};
Compling Args
'nvcc': [
                    '-O3',                        # optimization level
                    '-std=c++17',
                    # 添加torch的默认NVCC标志
                    '-D__CUDA_NO_HALF_OPERATORS__',
                    '-D__CUDA_NO_HALF_CONVERSIONS__',
                    '-D__CUDA_NO_BFLOAT16_CONVERSIONS__',
                    '-D__CUDA_NO_HALF2_OPERATORS__',
                    '--expt-relaxed-constexpr',
                    '--expt-extended-lambda',      
                    '-U__CUDA_NO_HALF_OPERATORS__',
                    '-U__CUDA_NO_HALF_CONVERSIONS__',
                    '-U__CUDA_NO_BFLOAT16_CONVERSIONS__',
                    '-U__CUDA_NO_HALF2_OPERATORS__',
                    '-gencode=arch=compute_120a,code=sm_120a', # Blackwell
            ]
ERROR

When I instantiate this policy with ElementAB = int8_t, ElementD = cutlass::bfloat16_t, and KernelSchedule = cutlass::gemm::collective::KernelScheduleAuto, the compilation fails with the following error:

cutlass/include/cutlass/gemm/collective/builders/sm120_mma_builder.inl(82): error: static assertion failed with "SM120 TmaWarpSpecialized builder currently only supports F8F6F4 MMA."
    static_assert(detail::is_sm10x_f8f6f4_element<ElementA>() && detail::is_sm10x_f8f6f4_element<ElementB>(),
    ^
          detected during:
            instantiation of class "cutlass::gemm::collective::CollectiveBuilder<cutlass::arch::Sm120, cutlass::arch::OpClassTensorOp, ElementA, GmemLayoutATag, AlignmentA, ElementB, GmemLayoutBTag, AlignmentB, ElementAccumulator, TileShape_MNK, ClusterShape_MNK, StageCountType, BuilderScheduleTag, ...>> [with ElementA=int8_t, ..., ElementB=int8_t, ..., ElementAccumulator=int32_t, ...]"
Analysis

The static_assert clearly indicates that the sm_120 builder (TmaWarpSpecialized) is currently implemented only for the new F8/F6/F4 data types and does not yet support int8_t.

The instantiation trace confirms my policy is correctly passing ElementA=int8_t, ElementB=int8_t, and ElementAccumulator=int32_t to the CollectiveBuilder.

Question

How can we write a int8_gemm kernel using cutlass3 now for emergency

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cutlass/include/cutlass/gemm/collective/builders/sm120_mma_builder.inl at the SM120 TmaWarpSpecialized static assertion, then trace the CollectiveBuilder instantiation shown in the report. Determine the existing F8/F6/F4 builder path and the requirements for int8_t inputs with int32_t accumulation. Done means an sm_120 INT8 GEMM policy can instantiate and compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.