Compilation of Generalized Matrix Chains with Symbolic Sizes
Preprint
Abstract
Generalized Matrix Chains (GMCs) are products of matrices where each matrix carries features (e.g., general, symmetric, triangular, positive-definite) and is optionally transposed and/or inverted. GMCs are commonly evaluated via sequences of calls to BLAS and LAPACK kernels. When matrix sizes are known, one can craft a sequence of kernel calls to evaluate a GMC that minimizes some cost, e.g., the number of floating-point operations (FLOPs). Even in these circumstances, high-level languages and libraries, upon which users usually rely, typically perform a suboptimal mapping of the input GMC onto a sequence of kernels. In this work, we go one step beyond and consider matrix sizes to be symbolic (unknown); this changes the nature of the problem since no single sequence of kernel calls is optimal for all possible combinations of matrix sizes. We design and evaluate a code generator for GMCs with symbolic sizes that relies on multi-versioning. At compile-time, when the GMC is known but the sizes are not, code is generated for a few carefully selected sequences of kernel calls. At run-time, when sizes become known, the best generated variant for the matrix sizes at hand is selected and executed. The code generator uses new theoretical results that guarantee that the cost is within a constant factor from optimal for all matrix sizes and an empirical tuning component that further tightens the gap to optimality in practice. In experiments, we found that the increase above optimal in both FLOPs and execution time of the generated code was less than 15\% for 95\% of the tested chains.Keywords
All Related Versions
This publication has 22 references indexed in Scilit:
- On the parenthesisations of matrix chains: All are useful, few are essentialJournal of Combinatorial Optimization, 2025
- Armadillo: an Efficient Framework for Numerical Linear Algebra2025
- A parallel implementation of the ensemble Kalman filter based on modified Cholesky decompositionJournal of Computational Science, 2019
- Some matrix nearness problems suggested by Tikhonov regularizationLinear Algebra and its Applications, 2016
- A Dual Method for Computing Power Transfer Distribution FactorsIEEE Transactions on Power Systems, 2016
- Sparsity-based correction of exponential artifactsSignal Processing, 2016
- Compiler multiversioning for automatic task granularity controlConcurrency and Computation: Practice and Experience, 2014
- Processor allocation and task scheduling of matrix chain products on parallel systemsIEEE Transactions on Parallel and Distributed Systems, 2003
- An O(n) algorithm to find a near-optimum partition of a convex polygonJournal of Algorithms, 1981
- On Efficient Computation of Matrix Chain ProductsIEEE Transactions on Computers, 1973