AUGEM: automatically generate high performance dense linear algebra kernels on x86 CPUs

Qian Wang, Xianyi Zhang, Yunquan Zhang, Qing YiSC 2013

TL;DR

This paper introduces AUGEM, a novel framework that automatically generates highly optimized assembly code for dense linear algebra (DLA) kernels on x86 CPUs. By leveraging domain-specific knowledge and a template-based approach, AUGEM significantly outperforms existing vendor-supplied and state-of-the-art BLAS libraries, achieving better performance portability without manual intervention.

What Problem Does This Paper Address?

Dense Linear Algebra (DLA) kernels, such as those found in the Basic Linear Algebra Subprograms (BLAS) library, are fundamental to scientific and engineering computing. Achieving peak performance for these kernels often requires hand-tuned assembly code, which is labor-intensive, error-prone, and difficult to port across different hardware architectures. While existing approaches like ATLAS and Intel MKL offer optimized libraries, they either rely on manual expertise or general-purpose compilers that may not fully exploit hardware features. This paper addresses the challenge of automatically generating high-performance, portable DLA kernels that can match or exceed the performance of manually optimized code.

Methods

AUGEM employs a four-component framework:

  1. Optimized C Kernel Generator: This component takes a simple C implementation of a DLA kernel and applies source-to-source optimizations (e.g., loop unrolling, scalar replacement, prefetching) using the POET library. This step aims to create a low-level C code that exposes opportunities for further machine-level optimization.
  2. Template Identifier: This component analyzes the optimized C code to identify code fragments that match pre-defined "templates." These templates represent common instruction sequences found in optimized DLA kernels.
  3. Template Optimizer: For each identified template, a specialized optimizer generates highly efficient SSE/AVX assembly instructions. This involves machine-level optimizations like SIMD vectorization, register allocation, and instruction selection/scheduling, guided by domain-specific knowledge embedded in the templates.
  4. Assembly Kernel Generator: This component translates the remaining low-level C code into assembly instructions and integrates the optimized template-based code, producing a complete, optimized assembly kernel.

The core novelty lies in the template-based approach to machine-level optimization, which allows for domain-specific knowledge to be systematically applied and automated, enabling portability across different architectures.

Datasets

Not discussed in the paper. The paper focuses on generating code for DLA kernels rather than training on datasets.

Key Insights and Ideas

  • Template-Based Machine-Level Optimization: The paper demonstrates that by codifying common, performance-critical instruction sequences into templates, machine-level optimizations (SIMD, register allocation, instruction scheduling) can be automated and made portable.
  • Domain-Specific Knowledge Encapsulation: Templates act as a mechanism to encapsulate expert knowledge about how to optimize specific DLA patterns, bridging the gap between high-level code and low-level hardware capabilities.
  • Automated Performance Portability: AUGEM achieves high performance across different x86 architectures (Intel Sandy Bridge and AMD Piledriver) without requiring manual tuning for each new platform, a significant improvement over traditional methods.
  • Synergy of Source-to-Source and Machine-Level Optimization: The framework effectively combines source-level optimizations to expose opportunities with specialized machine-level optimizations to exploit them, leading to superior results.

Key Results

The DLA kernels generated by AUGEM consistently outperformed implementations from Intel MKL, ATLAS, and GotoBLAS on both Intel Sandy Bridge and AMD Piledriver processors. Specific improvements cited include:

  • DGEMM: Outperformed Intel MKL by 1.4%, ATLAS by 3.3%, and GotoBLAS by 89.5% on Sandy Bridge. On Piledriver, it outperformed AMD ACML by 2.6%, ATLAS by 5.9%, and GotoBLAS by 66.8%.
  • DGEMV: Outperformed Intel MKL by 3.7%, ATLAS by 13.4%, and GotoBLAS by 8.4% on Sandy Bridge. On Piledriver, it outperformed AMD ACML by 23.6%, ATLAS by 14.3%, and GotoBLAS by 20.2%.
  • AXPY: Outperformed Intel MKL by 19.7%, ATLAS by 6.0%, and GotoBLAS by 12.2% on Sandy Bridge. On Piledriver, it outperformed AMD ACML by 45.5%, ATLAS by 8.2%, and GotoBLAS by 14.2%.
  • DOT: Outperformed Intel MKL by 7.1%, ATLAS by 29.5%, and GotoBLAS by 1.0% on Sandy Bridge. On Piledriver, it outperformed AMD ACML by 28.3%, ATLAS by 17.7%, and GotoBLAS by 54.9%.

The GEMM kernel generated by AUGEM has been integrated into the open-source OpenBLAS library.

Limitations and Future Work

  • Limited Kernel Support: Currently, AUGEM supports optimization for a specific set of DLA kernels (GEMM, GEMV, AXPY, DOT).
  • Template Identification: The identification of templates relies on manual analysis of optimized C code, which could be extended.
  • TRSM Exception: For the TRSM routine, which involves solving triangular matrix equations, the framework's performance was not as dominant as for other kernels. This is attributed to the TRSM computation being partially translated into low-level C code without special optimizations, as it couldn't be directly derived from GEMM.

Future work includes extending the framework to support a broader collection of DLA routines and other computational domains by developing new templates and specialized optimizers. The authors also plan to integrate more generated DLA kernels into OpenBLAS.

Summary updated

BibTeX
@inproceedings{wang2013augem,
  author = {Qian Wang and Xianyi Zhang and Yunquan Zhang and Qing Yi},
  title = {{AUGEM: automatically generate high performance dense linear algebra kernels on x86 CPUs}},
  booktitle = {SC},
  year = {2013},
  doi = {10.1145/2503210.2503219},
}
Figure