[Paper Review] High Performance GPU Code Generation for Matrix-Matrix Multiplication using MLIR: Some Early Results
This paper presents an MLIR-based automatic code generation pipeline for high-performance matrix-matrix multiplication on NVIDIA A100 and RTX 3090 GPUs targeting tensor cores. By lowering high-level IR through optimized dialect transformations, the approach achieves 95–119% of CuBLAS performance for FP32 and 80–160% for FP16 mixed-precision workloads, demonstrating that IR-driven compilation can rival hand-optimized libraries without manual coding.
This report presents some early results on code generation targeting tensor cores on NVIDIA GPUs using the MLIR compiler infrastructure. The state-of-the-art in high-performance deep learning today is primarily driven by manually optimized highly tuned libraries. The approach to develop such libraries is often not modular or reusable to the same extent that compiler infrastructure like LLVM is. Manual optimization typically does not use a standard intermediate representation (IR), although the optimizations performed can be encoded as a sequence of transformation steps and customized passes on an IR. Hand tuning may also miss exploration of design points only reachable easily by automatic code generation. We believe that until the recent introduction of MLIR (Multi-level intermediate representation), IR infrastructure was not geared to tackle the problem of automatic generation of domain-specific libraries in an effective manner. In particular, it was hard to represent and transform compute abstractions at high, middle, and low levels using a single IR. With suitable abstractions in MLIR, we build an experimental lowering pipeline that is able to automatically generate code for matrix-matrix multiplication on NVIDIA GPUs targeting its tensor cores. On a set of problem sizes we evaluated, initial performance results show that we are able to attain performance that is 95-119% and 80-160% of CuBLAS for FP32 and FP16 accumulate respectively on NVIDIA's Ampere microarchitecture-based Geforce 3090 RTX. We believe that these results could be used as motivation for further research and development on automatic code and library generation using IR infrastructure for similar specialized accelerators.
Motivation & Objective
- To develop a modular, automatic code generation pipeline for matrix-matrix multiplication on NVIDIA GPUs using MLIR.
- To target tensor cores efficiently without manual kernel tuning, reducing reliance on expert-optimized libraries.
- To evaluate whether IR-based compilation can achieve performance comparable to hand-tuned libraries like CuBLAS.
- To explore the impact of individual optimizations through systematic A/B testing in a modular IR pipeline.
- To establish a foundation for automatic generation of domain-specific, high-performance libraries using a unified intermediate representation.
Proposed method
- The approach uses MLIR's multi-level IR to represent matmul at high, middle, and low abstraction levels, enabling systematic transformation.
- A new MLIR dialect for Warp Matrix Multiply Accumulate (WMMA) operations is introduced, with lowering to LLVM/NVPTX IR.
- The pipeline applies a sequence of dialect lowering and optimization passes, including tiling, tiling to shared memory, and register-level optimizations.
- Optimizations such as pipelined global memory loading and tile size selection are applied incrementally to study their performance impact.
- The code generation pipeline is end-to-end, starting from a high-level matmul operation and compiling to efficient CUDA code targeting tensor cores.
- Performance is evaluated on NVIDIA's Ampere-based RTX 3090 GPU using standard problem sizes and mixed/half-precision configurations.
Experimental results
Research questions
- RQ1Can an IR-based code generation pipeline achieve performance competitive with hand-optimized libraries like CuBLAS for matrix-matrix multiplication on tensor cores?
- RQ2How do individual optimizations such as tile size and memory access pipelining affect performance in a modular, IR-driven pipeline?
- RQ3To what extent can automatic code generation match or exceed the performance of vendor-optimized libraries across different precision formats?
- RQ4Can a unified IR infrastructure like MLIR effectively express and transform high-level compute abstractions for specialized accelerators like tensor cores?
- RQ5How does the performance of automatically generated kernels compare to CuBLAS across varying problem sizes and data types?
Key findings
- The automatically generated kernels achieve 95–119% of CuBLAS performance for FP32 mixed-precision matmul on the RTX 3090, with peak efficiency reaching 95.4% of device theoretical peak.
- For FP16 mixed-precision matmul, performance is consistently within 95–119% of CuBLAS, with better-than-CuBLAS results on smaller problem sizes due to higher occupancy from smaller thread block tiles.
- In FP16-only matmul, the generated code achieves 80–160% of CuBLAS performance, outperforming CuBLAS on larger problem sizes where CuBLAS shows inconsistent performance and suboptimal tile choices.
- The study reveals that CuBLAS uses smaller tile sizes (e.g., 128×128×32) and five-stage pipelining, but suffers from higher global memory stalls, indicating less effective latency hiding.
- Smaller tile sizes (e.g., 64×64×64) improve performance on small problem sizes due to increased occupancy, while larger tiles are more effective on large matrices due to better data reuse.
- The incremental optimization study confirms that pipelining and tile size selection significantly impact performance, with the final optimized pipeline achieving near-peak performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.