Abstract
The GEneral Matrix Multiplication (GEMM) is one of the essential algorithms in scientific computing. Single-thread GEMM implementations are well-optimised with techniques like blocking and autotuning. However, due to the complexity of modern multi-core shared memory systems, it is challenging to determine the number of threads that minimises the multi-thread GEMM runtime. We present a proof-of-concept approach to building an Architecture and Data-Structure Aware Linear Algebra (ADSALA) software library that uses machine learning to optimise the runtime performance of BLAS routines. More specifically, our method uses a machine learning model on-the-fly to automatically select the optimal number of threads for a given GEMM task based on the collected training data. Test results on two different HPC node architectures, one based on a two-socket Intel Cascade Lake and the other on a two-socket AMD Zen 3, revealed a 25 to 40 per cent speedup compared to traditional GEMM implementations in BLAS when using GEMM of memory usage within 100 MB.
Introduction
General Matrix Multiplication (GEMM) is a cornerstone of scientific computing, heavily optimized in standard Basic Linear Algebra Subprograms (BLAS) libraries like Intel MKL and AMD BLIS. However, these optimizations historically focus on single-thread performance or massive, regular-shaped matrices. In modern multi-core shared-memory systems, users typically default to using the maximum number of available physical cores for multi-threaded GEMM.
For small or irregularly shaped matrices—which are common in machine learning tasks like ResNet convolutions—using the maximum number of threads is often sub-optimal. The overhead of synchronizing dozens of threads and copying data to thread-local buffers can eclipse the actual computation time. Because the relationship between matrix dimensions, hardware architecture, and optimal thread count is highly non-linear, hardcoded heuristics fail to consistently select the best performance profile.
The ADSALA Framework
To address this, we propose the Architecture and Data-Structure Aware Linear Algebra (ADSALA) software library. ADSALA treats the underlying BLAS GEMM implementation as a black box and wraps it in a machine learning-driven thread-selection mechanism. The workflow is divided into two distinct phases: installation-time profiling and runtime inference.
Upon installation on a new HPC node, the software automatically runs a suite of GEMM benchmarks using a scrambled Halton sequence to sample matrix dimensions ($m, k, n$) bounded by a 500 MB memory footprint. This data is used to train an XGBoost model. XGBoost was selected because it offers a critical balance of predictive accuracy and ultra-fast evaluation time ($\sim$45-54 $\mu s$). If the ML model takes longer to run than the matrix multiplication itself, the performance gains are negated.
Key Insights and Results
Our profiling revealed that for matrices under 100 MB, the optimal thread count is rarely the maximum available. It is frequently less than half of the available cores, as shown in the distribution of optimal counts across our training data.
The system was tested on two supercomputers: Setonix (AMD EPYC Zen 3, 64 cores/socket) and Gadi (Intel Xeon Cascade Lake, 24 cores/socket). For small matrices (< 100 MB), the ML-driven approach achieved an average speedup of 1.41x (41%) on Setonix and 1.26x (26%) on Gadi compared to the default max-thread BLAS implementation.
In specific edge cases, the speedups were even more dramatic. For a GEMM with dimensions $m=64, k=2048, n=64$ on Gadi, the ML model chose 14 threads instead of the default 96. This decision slashed data copy time from 163 seconds down to 0.4 seconds, yielding an 81.6x overall speedup.
Conclusion and Future Work
While the approach requires an upfront profiling phase, the runtime benefits for small and irregular workloads are substantial. Future work will focus on extending this ML-driven runtime thread selection to other BLAS operations and adapting the system for heterogeneous architectures, optimizing workloads across a mix of CPUs and hardware accelerators like GPUs.
Summary updated