Space Filling Curves is All You Need: Communication-Avoiding Matrix Multiplication Made Simple
Organizations: Intel Corporation
Abstract
General Matrix Multiplication (GEMM) is the cornerstone of HPC workloads and Deep Learning. State-of-the-art (SOTA) vendor libraries tune tensor layouts, parallelization schemes and cache blocking to minimize data movement across the memory hierarchy and maximize throughput. However, optimal settings for these parameters depend on the target platform and matrix shapes, making exhaustive tuning infeasible. In this work, we address this cumbersome scheduling search and tuning using space-filling curves (SFC). We partition the matrix multiplication using advancements in SFC, and obtain platform-oblivious and shape-oblivious matrix multiplication schemes with a high degree of data locality. We extend the SFC-based work partitioning to implement Communication-Avoiding (CA) algorithms with replication techniques in a seamless fashion. The resulting SFC-CA GEMM achieves provable asymptotic communication optimality for both square and rectangular matrix regimes. Across four x86 and Arm platforms, SFC-CA GEMM outperforms vendor libraries by up to 5.5 per shape and 1.8 in weighted harmonic mean (WHM) throughput. Last, we show the impact of our work on two real-world applications by leveraging our SFC-CA GEMM as a compute backend: i) prefill of LLM inference with speedups up to 1.85 over SOTA inference runtimes, and ii) distributed-memory matrix multiplication with speedups up to 2.3 over the SOTA distributed-memory GEMM framework with vendor-optimized compute backend.
Figures & tables
| Matrix shape / regime | Dimension/thread conditions and layer choice | SFC-CA GEMM words Matched lower-bound type |
|---|---|---|
| Square: 2D / 2.5D (Cor. 3 (i)) | , , and , in addition to the shared cache-fit condition. gives 2D. | Memory-dependent |
| 1D output bands Any (Cor. 3 (ii)) | with . Each core owns full rows of . | Compulsory input/output |
| Short inner dimension (Cor. 3 (iii)) | with . Writing dominates the total traffic. | Compulsory output |
| Large inner dimension , (Cor. 3 (iv)) | . The exact choice must be feasible. | Compulsory input |
| Three large dimensions Any ordering of (Cor. 3 (v)) | . Assume and are powers of two. Choose and . | Memory-independent |