Introduction
High-performance computing (HPC) has long relied on hand-tuned assembly micro-kernels for General Matrix Multiplication (GEMM). While these kernels achieve peak performance, they suffer from significant maintainability and portability issues. This research explores the use of the Apache TVM compiler framework to automatically generate a family of high-performance GEMM routines, matching or exceeding the performance of industry-standard libraries like BLIS and Intel MKL.
The Challenge of Manual Tuning
Traditional GEMM libraries often provide a single micro-kernel optimized for "squarish" matrices. However, deep learning workloads frequently involve "skinny" or "rectangular" matrices (e.g., in ResNet-50). Fixed-size, hand-coded kernels often fail to utilize CPU caches efficiently for these diverse shapes. Furthermore, writing and maintaining assembly code for every new processor architecture is a labor-intensive "black art" that hinders rapid deployment on new hardware.
Methodology: A Family of Blocked Algorithms
The researchers implemented a family of blocked algorithms that manage data movement across the memory hierarchy, specifically targeting L3, L2, and L1 caches, as well as CPU registers. By using TVM’s scheduling primitives, optimizations such as loop tiling, packing, and SIMD (Single Instruction, Multiple Data) vectorization are described in Python and then compiled into high-performance machine code.
As shown in Figure 3, the approach utilizes a multi-level loop structure (L1 through L6) to orchestrate data movement. Analytical models, rather than exhaustive auto-tuning, are used to determine optimal cache blocking parameters and micro-kernel dimensions based on specific hardware targets. This allows the generator to adapt the micro-kernel shape (e.g., $4 \times 28$ vs. $8 \times 12$) to the specific dimensions of the input matrices.
The flexibility of this framework allows for the generation of various algorithmic variants, including those that involve packing the result matrix C (see Figure 5). This diversity ensures that the most efficient memory access pattern can be selected for a given workload.
Performance and Portability
The TVM-generated kernels were evaluated on ARM (NVIDIA Carmel), AMD EPYC, and Intel Xeon platforms. Key findings include:
- Square Matrices: Performance matched the hand-tuned BLIS library (~29 GFLOPS on ARM).
- Deep Learning Workloads: For rectangular layers in ResNet-50, TVM significantly outperformed BLIS. For instance, in one specific layer, TVM achieved 22.4 GFLOPS compared to BLIS’s 13.3 GFLOPS.
- Binary Size: The automated approach produced much smaller binaries (approximately 520 KiB for TVM vs. over 27 MiB for the ARM Performance Libraries).
Conclusion and Future Work
This work demonstrates that modern compilers like TVM can generate code as efficient as human-written assembly while offering superior flexibility for non-standard matrix shapes common in deep learning. Future improvements will focus on closing the gap in software prefetching on x86 architectures and exploring more complex nested parallelization schemes to better utilize high-core-count processors.
Summary updated