SuperAPI AI Directory

DeepGEMM - DeepSeek's Open-Source FP8 General Matrix Multiplication Library

Author: AI小集 · Original source: AI工具集

What is DeepGEMM

DeepGEMM is an open-source library from DeepSeek designed for efficient and concise FP8 matrix multiplication (GEMM), currently supporting only NVIDIA Hopper tensor cores. DeepGEMM supports both normal and Mixture-of-Experts (MoE) grouped GEMM operations, is based on Just-In-Time (JIT) compilation technology, requires no compilation at installation time, and supports dynamic optimization at runtime. DeepGEMM is based on fine-grained scaling and CUDA core two-level accumulation technology to address the issue of insufficient FP8 precision, while using Hopper's Tensor Memory Accelerator (TMA) feature to improve data transfer efficiency. DeepGEMM's core code is only about 300 lines, making it easy to learn and optimize. DeepGEMM's lightweight design achieves or exceeds expert-level optimized libraries across a variety of matrix shapes.

DeepGEMM

DeepGEMM's Main Features

  • Efficient FP8 Matrix Multiplication (GEMM): DeepGEMM is an efficient library designed specifically for FP8 (8-bit floating point) matrix multiplication, supporting fine-grained scaling and significantly improving the performance and precision of matrix operations.
  • Supports Normal and Grouped GEMM:
    • Normal GEMM: Suitable for conventional matrix multiplication operations.
    • Grouped GEMM: Supports grouped matrix multiplication in Mixture-of-Experts (MoE) models, including contiguous layout and masked layout, optimizing scenarios where multiple experts share shapes.
  • Just-In-Time (JIT) Compilation Design: Based on just-in-time compilation technology, all kernels are dynamically compiled at runtime, with no compilation at installation time. Optimization is performed according to parameters such as matrix shape and block size, saving registers and improving performance.
  • Hopper Architecture Optimization: Designed specifically for the NVIDIA Hopper architecture, fully leveraging Tensor Memory Accelerator (TMA) features, including TMA load, store, multicast, and descriptor prefetch, significantly improving data transfer efficiency.
  • Fine-Grained Scaling and Two-Level Accumulation: To address the issue of insufficient FP8 precision, DeepGEMM introduces fine-grained scaling technology, based on a CUDA core two-level accumulation mechanism, upgrading FP8 computation results to a higher-precision format (such as BF16) to ensure computational precision.
  • Lightweight Design: The core code is concise, only about 300 lines, making it easy to understand and extend. It avoids dependencies on complex templates or algebraic structures, reducing the difficulty of learning and optimization.

DeepGEMM's Project Address

DeepGEMM's Performance

  • Normal GEMM (Non-Grouped) Performance
    • Maximum Speedup: Under certain matrix shapes, DeepGEMM can achieve a speedup of 2.7x, significantly improving the efficiency of matrix multiplication.
    • Computational Performance: In large-scale matrix operations, DeepGEMM can achieve computational performance exceeding 1000 TFLOPS, approaching the theoretical peak of Hopper architecture GPUs.
DeepGEMM
  • Grouped GEMM (MoE Model) Performance
    • Speedup: In grouped GEMM, DeepGEMM can achieve a speedup of 1.1-1.2x, significantly improving the training and inference efficiency of MoE models.
    • Memory Bandwidth Optimization: Based on TMA features, DeepGEMM performs excellently in memory bandwidth utilization, achieving performance close to the hardware limit.
      • Contiguous Layout
DeepGEMM
      • Masked Layout
DeepGEMM

DeepGEMM's System Requirements

  • Hardware Requirements:
    • GPU Architecture: NVIDIA Hopper architecture must be supported, specifically GPUs that support sm_90a. GPUs with Hopper architecture such as H800 or H100 are recommended, designed specifically for FP8 computation and Tensor Core optimization.
    • CUDA Compatibility: CUDA 12.3 or later is required. CUDA 12.8 or later is recommended for optimal performance.
  • Software Requirements:
    • Operating System Recommendation: Use a Linux operating system (such as Ubuntu, CentOS, etc.), because CUDA and PyTorch have better support on Linux.
    • Python Version: Python 3.8 or later.
    • CUDA Toolkit: CUDA 12.3 or later. The CUDA version must match the GPU architecture. CUDA 12.8 or later is recommended to fully leverage the features of the Hopper architecture.
    • PyTorch: PyTorch 2.1 or later.
    • CUTLASS Library: CUTLASS 3.6 or later.
  • Other Requirements:
    • Common compilation tools (such as gcc, make, etc.).
    • The torch.utils.cpp_extension module, used for CUDA extensions.

DeepGEMM Application Scenarios

  • Large-Scale AI Model Inference: Accelerates high-dimensional matrix multiplication and improves inference speed.
  • Mixture of Experts (MoE) Models: Optimizes grouped matrix multiplication and improves computational efficiency.
  • Low-Precision Computation:Solves FP8 precision issues through fine-grained scaling, maintaining high-precision output.
  • High-Performance Computing: Based on Hopper architecture features, improves matrix operation efficiency.
  • Deep Learning Framework Optimization: As a low-level optimization library, it accelerates model training and inference.