Inference with Transformer Encoders on ARM and RISC-V Multicore Processors

Héctor Martínez, Francisco D. Igual, Rafael Rodríguez-Sánchez, Sandra Catalán, Adrián Castelló, Enrique S. Quintana-OrtíEuro-Par 2024

Introduction

As AI moves toward the "edge," the demand for efficient inference on low-power multicore CPUs—such as those based on ARM and RISC-V architectures—has surged. While massive GPUs dominate data centers, smartphones and embedded sensors rely on these CPUs for real-time NLP tasks. However, standard high-performance math libraries (BLAS) often fall short because they are optimized for large, square matrices, whereas Transformer models frequently utilize "skinny" matrices and batched operations.

The Bottleneck in Edge Inference

The core of modern NLP is the Transformer encoder, which relies heavily on General Matrix Multiplication (GEMM). Standard libraries like BLIS and OpenBLAS use fixed cache configuration parameters (CCPs) that lead to inefficient cache usage when processing the non-standard matrix shapes found in multi-head attention (MHA) and feed-forward networks (FFN). This results in poor scaling across multiple CPU cores and significant performance penalties.

Methodology: A Dimension-Aware Approach

To address these inefficiencies, researchers developed a specialized framework that moves away from "one-size-fits-all" math libraries. Their approach centers on three pillars:

  1. Dimension-Aware GEMM: By using an analytical model, the system dynamically selects optimal tile sizes at runtime based on the specific dimensions of the input matrices, rather than relying on static, pre-compiled parameters.
  2. Automated Micro-kernel Generation: A Python-based generator produces assembly-level micro-kernels tailored for ARMv8-A (NEON) and RISC-V (RVV) vector units, ensuring the most efficient kernel is used for each specific task.
  3. Optimized Parallelization: Instead of internal library threading, the researchers implemented application-level parallelism using OpenMP. This strategy is particularly effective for the small batched operations typical in multi-head attention.
Internal architecture of the Transformer encoder's MHA and FFN modules.

As shown in Figure 1, the Transformer encoder consists of complex data flows through MHA and FFN modules. The researchers targeted specific operations—such as the GEMMs in M1-M3 and M9, and the Batched GEMMs (BGEMMs) in M5 and M7—for optimization.

Key Results and Performance Gains

The optimizations were evaluated on an 8-core NVIDIA Carmel (ARM) and a 4-core XuanTie C910 (RISC-V) using BERT-Base and BERT-Large models.

The results demonstrated significant improvements across various sequence lengths ($l$) and batch sizes ($b$):

  • Overall Acceleration: The optimized encoder achieved up to 2.5× speedup compared to standard library baselines.
  • Component-Level Efficiency: Tuning cache parameters and selecting optimal micro-kernels yielded substantial gains even on single-core execution.
  • Multicore Efficiency: By combining dimension-aware GEMM with application-level parallelization, the researchers significantly improved scaling, particularly for the Batched GEMM operations that previously bottlenecked the system.
Speed-up achieved across different Transformer parameters and operation types.

Figure 3 illustrates the speed-up across different components. While standard GEMM operations saw the most consistent improvements, the "Total" speed-up reflects the combined impact of optimizing matrix multiplications, softmax, and parallel execution strategies.

Conclusion

By making underlying math operations "aware" of the specific dimensions used in Transformer models, inference performance on edge devices can be dramatically improved. While challenges like the Softmax bottleneck remain, this dimension-aware approach provides a robust path forward for deploying sophisticated NLP models on low-power multicore hardware.

Reference: Martínez, H., et al. (2024). Inference with Transformer Encoders on ARM and RISC-V Multicore Processors. Euro-Par 2024.

Summary updated

BibTeX
@inproceedings{martinez2024inference,
  author = {Héctor Martínez and Francisco D. Igual and Rafael Rodríguez-Sánchez and Sandra Catalán and Adrián Castelló and Enrique S. Quintana-Ortí},
  title = {{Inference with Transformer Encoders on ARM and RISC-V Multicore Processors}},
  booktitle = {Euro-Par},
  year = {2024},
  doi = {10.1007/978-3-031-69766-1\_26},
}
Figure