Yes, it is possible to write a fused CUDA kernel that performs both General Matrix-Matrix Multiplication (GEMM) and communication operations such as all-gather, reduce-scatter, and all-to-all during transformer training. Fusing computation and communication can significantly enhance performance by overlapping data transfer with computation, thereby reducing overall latency.
Implementation Suggestions:
-
Leverage GPU-Initiated Communication:
Utilize GPU capabilities to initiate communication directly from within kernels. This approach allows for immediate data transfer as soon as computation on a data block is completed, facilitating overlap between computation and communication.
-
Design Self-Contained GPU Kernels:
Develop kernels where workgroups (WGs) perform computations and, upon completion, immediately communicate their results to remote GPUs. Concurrently, other WGs continue computation, maintaining high ALU utilization.
-
Utilize Efficient Kernel Fusion Techniques:
Implement kernel fusion strategies that combine GEMM operations with collective communication. This fusion reduces the overhead associated with separate kernel launches and memory accesses.
Open Source Implementations for Reference:
-
CUTLASS Library:
NVIDIA's CUTLASS library provides examples of fused operations, including gather-GEMM-scatter patterns. For instance, the Ampere gather/scatter convolution example demonstrates how to implement such fused operations efficiently.
-
Triton Language:
Triton, developed by OpenAI, is a language and compiler for writing efficient GPU code. It has been used to implement efficient gather-and-scatter matrix multiplication kernels, which can serve as a foundation for fusing GEMM with communication operations. An example implementation is detailed in this blog post.
-
Gemlite:
Gemlite is a collection of simple CUDA kernels designed to help developers create low-bit fused GEMM CUDA code. While its primary focus is on quantization, the principles of kernel fusion it employs can be adapted for combining GEMM with communication operations. More information is available in this blog post.
Research References:
-
Optimizing Distributed ML Communication with Fused Computation-Collective Operations:
This paper introduces methods for fusing computation with collective communication by leveraging GPUs' parallelism and GPU-initiated communication. It presents prototype fused operators, including GEMM combined with all-to-all communication, demonstrating reduced execution time compared to traditional approaches. The paper is available here.
-
FusionStitching: Boosting Execution Efficiency of Memory Intensive Computations for DL Workloads:
This work proposes an optimization framework capable of fusing memory-intensive operations, including GEMM and collective communications, into efficient GPU kernels. It formulates fusion plan optimization as an integer linear programming problem and demonstrates significant speedups over existing methods. The paper can be accessed here.
By studying these resources and leveraging the techniques they describe, you can develop fused CUDA kernels that effectively combine GEMM computations with communication operations, leading to more efficient transformer training.