BLASFEO: A Hardcore Engine for Embedded Linear Algebra

In the field of embedded systems and real-time optimization, efficient linear algebra operations are a core bottleneck. Traditional BLAS libraries such as OpenBLAS or MKL, while powerful, often exhibit inefficiencies and poor cache utilization for small matrices (dimensions in the hundreds).

BLASFEO: A Hardcore Engine for Embedded Linear Algebra
Project Homepage

The BLASFEO project stands out as an open-source library led by Gianluca Frison (giaf), specifically designed for embedded optimization. Based on the GitHub repository (https://github.com/giaf/blasfeo), it provides high-performance Basic Linear Algebra Subprograms (BLAS) focused on cache-resident matrices, widely used in Model Predictive Control (MPC) and robotic systems.

This article analyzes BLASFEO from a technical perspective, helping embedded experts deeply integrate and accelerate applications.

Project Introduction

BLASFEO, which stands for Basic Linear Algebra Subroutines for Embedded Optimization, was initiated around 2017 with the aim of providing a lightweight and efficient matrix computation library for embedded environments. The project optimizes for moderately sized matrices (hundreds of dimensions) suitable for cache, commonly found in real-time optimization algorithms such as MPC or Quadratic Programming (QP).

The repository contains a core implementation in C, supporting both double and single precision floating-point operations, licensed under the 2-Clause BSD, facilitating commercial and academic use.

Installation uses the CMake system, supporting automatic target detection (X64_AUTOMATIC) for cross-platform builds. Example process: after cloning the repository,<span>mkdir build; cd build; cmake ..; make</span>. For cross-compilation, set<span>BLASFEO_CROSSCOMPILING=ON</span> to disable tests.

The testing framework is based on Python 3.6+ and Jinja, using<span>tester.py</span> to run benchmarks, such as<span>python tester.py testset_default.json</span>.

The project supports various operating systems (Linux, Windows, macOS) and provides an Android integration guide, including memory alignment and denormals handling. More benchmarks and documentation can be found in the project wiki (https://blasfeo.syscop.de), and the repository is actively maintained, with updates for new architectures planned until 2025.

The core innovation of BLASFEO lies in its dual linear algebra implementation: high-performance mode (LA=HIGH_PERFORMANCE) and reference mode (LA=REFERENCE), with the former utilizing target-specific assembly kernels.

It is closely integrated with HPIPM (High-Performance Interior Point Method Solver), forming a complete stack for embedded optimization.

Project Features

BLASFEO’s core strength lies in its architecture-level optimizations and flexibility, with the following key technical highlights:

  1. Dual API Design: Standard BLAS/LAPACK API (column-major storage) and custom BLASFEO API. The latter reduces overhead for small matrices, using<span>blasfeo_dmat</span> and<span>blasfeo_dvec</span> structures (defined in<span>include/blasfeo_common.h</span>), with a non-destructive API requiring additional output parameters. Supports Level 3 routines such as<span>dgemm</span> (matrix multiplication),<span>dsyrk</span> (symmetric rank-k update),<span>dtrmm</span> (triangular matrix multiplication),<span>dpotrf</span> (Cholesky decomposition), and<span>dgetrf</span> (LU decomposition).

  2. Multi-Architecture Support and Optimization: Customizable through the TARGET variable, including Intel (SkyLake, Haswell, Sandy Bridge), AMD (Bulldozer, Jaguar), and ARM (Cortex-A76, A57, A55, even Apple M1). The GENERIC target is implemented in pure C, suitable for architectures with 16+ floating-point registers. CMake automatically detects the best x64 target to ensure compatibility. Optimization strategies include panel-major (PANELMAJ) matrix format: block row-major with fixed-height panels and internal column-major, enhancing cache utilization.

  3. Outstanding Performance: Designed for cache-resident matrices, utilizing SIMD instructions and assembly kernels in high-performance mode. Benchmarks for small matrices show that BLASFEO is 1.5-10 times faster than OpenBLAS, especially on RISC-V processors, achieving matrix operations through vectorization optimizations. Compared to MKL, it is more efficient on ARM embedded platforms, with a smaller footprint suitable for low-power scenarios.

  4. Strong Extensibility: Supports column-major (COLMAJ) and panel-major (MF=PANELMAJ) formats. Integrates HPIPM for QP solving, handling multi-level optimization structures such as block tridiagonal arrow matrices. Resource-efficient, suitable for RTOS and embedded MCUs.

Compared to Eigen or Armadillo, BLASFEO focuses more on embedded real-time performance, reducing overhead.

Development Use Cases

BLASFEO shines in embedded optimization, with the following hardcore cases combining code and practical applications:

  1. Model Predictive Control (MPC) in Robotic Navigation: Used for fast embedded MPC in human-aware robotic navigation. Integrating HPIPM, BLASFEO provides the linear algebra backend. Example code (BLASFEO API):
#include <blasfeo_target.h>
#include <blasfeo_common.h>
#include <blasfeo_d_aux.h>
#include <blasfeo_d_blas.h>

int main() {
    struct blasfeo_dmat A, B, C;
    blasfeo_allocate_dmat(50, 50, &A);  // Allocate 50x50 matrix
    // Fill A, B
    blasfeo_dgemm('N', 'N', 50, 50, 50, 1.0, &A, 0, 0, &B, 0, 0, 0.0, &C, 0, 0);  // C = A * B
    blasfeo_free_dmat(&A);
    return 0;
}

Deployed on ARM Cortex-A57, with iteration time <1ms, enhancing robot real-time performance.

  1. RISC-V Band Matrix Optimization: Optimizing band matrix BLAS algorithms for RISC-V processors, such as<span>dgbmv</span><span> (band matrix-vector multiplication). Configured with TARGET=GENERIC, benchmarks show 1.5-10x acceleration. Practical application: embedded signal processing, handling filter matrices.</span>

  2. ADMM Solver in MPC: Building a sparse ADMM solver to handle linear MPC with terminal elliptical constraints. BLASFEO manages Cholesky and LU decompositions, code example:<span>blasfeo_dpotrf('L', n, &A, 0, 0, &A, 0, 0);</span>. Applied in automotive control, achieving high accuracy and low latency.

  3. Utilization of Multi-Level Optimization Structures: Utilizing block tridiagonal arrow structures in HPIPM, BLASFEO accelerates proximal solvers. Suitable for distributed embedded systems, such as IoT network optimization.

These use cases demonstrate the modular advantages of BLASFEO in real-time embedded scenarios.

Conclusion

BLASFEO is an open-source paradigm for embedded linear algebra, with optimizations for small matrices, multi-architecture support, and HPIPM integration, facilitating MPC and robotic applications.

Leave a Comment