Tensor Processing Primitives: A Programming Abstraction for Efficiency and Portability in Deep Learning Workloads

Evangelos Georganas, Dhiraj D. Kalamkar, Sasikanth Avancha, Menachem Adelman, Cristina Anderson, Alexander Breuer, Narendra Chaudhary, Abhisek Kundu, Md. Vasimuddin, Sanchit Misra, Ramanarayan Mohanty, Hans Pabst, Barukh Ziv, Alexander HeineckearXiv 2021 · DOI

TL;DR

Tensor Processing Primitives (TPP) introduce a "virtual Tensor ISA" that bridges the gap between inflexible vendor libraries and slow framework-level implementations. By providing a compact set of 2D tensor building blocks, TPP enables developers to write portable, high-performance Deep Learning and HPC kernels that rival or outperform hand-tuned assembly across diverse CPU architectures like x86 and ARM.

What Problem Does This Paper Address?

The programming landscape for Deep Learning (DL) has reached a plateau. Currently, developers face a frustrating trade-off:

  1. Vendor Libraries (e.g., oneDNN, cuDNN): These offer peak performance but are "monolithic black boxes." They are inflexible, hard to extend for novel operators, and non-portable across different hardware vendors.
  2. Tensor Compilers (e.g., TVM, MLIR): While promising, they often struggle to generate code that reaches the "achievable peak" of modern hardware, especially for complex operators, and can suffer from prohibitive compilation times.
  3. Framework Primitives: Implementing new ideas directly in PyTorch or TensorFlow is easy but usually results in underwhelming performance because the underlying "generic" kernels aren't optimized for specific hardware nuances like vector lengths or cache hierarchies.

The authors argue that the missing link is a proper abstraction layer—a set of primitives that are low-level enough to be efficient but high-level enough to be platform-agnostic.

Methods

The core innovation is the Tensor Processing Primitive (TPP). Instead of high-level layers (like a full Convolution), TPPs define a compact set of mathematical operators on 2D tensors.

The Virtual Tensor ISA

TPPs act as a "virtual ISA." A developer writes code using these 2D primitives, and the TPP back-end (leveraging Just-In-Time or JIT technology) generates the optimal machine code (AVX-512, AMX, ARM SVE, etc.) for the specific processor at runtime.

The collection is categorized into:

  • Unary TPPs: Operations like Identity, Exp, ReLU, and Transpose.
  • Binary TPPs: Add, Mul, MatMul, and Compare.
  • Ternary TPPs: The heavy hitters, including GEMM and Batch-Reduce GEMM (BRGEMM).
Table of Unary TPPs showing the breadth of supported 2D operations.

Matrix Equations and Fusion

To handle complex operations without creating massive intermediate memory buffers, the authors introduced a mini-eDSL for Matrix Equations. This allows multiple TPPs to be fused into a single optimized kernel. For example, a "Softmax" can be expressed as a tree of TPPs. The system uses a "register scoring" algorithm (an extension of the Sethi-Ullman algorithm) to decide the best order of operations to minimize register spills and memory traffic.

Datasets

The TPP approach was evaluated across a wide range of real-world workloads and benchmarks:

  • Standard DL Models: ResNet-50 (Image processing), DLRM (Recommendation systems), and BERT-Large (Natural Language Processing).
  • Graph Neural Networks: GraphSAGE using the OGB-Products dataset.
  • Computational Biology: ATACworks for genomic sequencing data.
  • HPC Applications: CP2K (electronic structure theory) and EDGE (seismic wave simulation).
  • Video Inference: I3D-Kinetics-400.

Key Insights and Ideas

  • 2D is the Sweet Spot: While tensors are often 4D or 5D, the authors found that 2D primitives are the ideal granularity. They are complex enough to map well to hardware vector units and matrix accelerators (like Intel AMX) but simple enough to be used as universal building blocks.
  • Separation of Concerns: TPP allows the "what" (the algorithm) to be separated from the "how" (the hardware-specific optimization). A researcher can write a BERT layer once, and it will run efficiently on both an Intel Xeon and an AWS Graviton2.
  • Emulation as a First-Class Citizen: TPP allows for bit-accurate emulation of new hardware features (like AMX or Bfloat16) on older CPUs. This lets developers prepare software for next-generation chips before they are even released.
  • Vertical Register Fusion: By using the Matrix Equation eDSL, the system performs "vertical fusion," keeping data in registers across multiple operations, which is far more efficient than the "horizontal fusion" typically found in DL libraries.

Key Results

The performance gains are significant across the board:

  • Productivity: A novel BF16 Split-SGD operator, which is difficult for standard compilers to optimize, saw a 38x speedup when implemented via TPP.
  • End-to-End DL: TPP-based BERT training outperformed the Hugging Face reference by 1.5x to 8.5x across different platforms.
  • Portability: The same TPP code achieved high hardware utilization (66-84% of peak) on both x86 and ARM architectures.
  • HPC: In the CP2K molecular dynamics suite, replacing standard BLAS calls with TPP-GEMM resulted in up to a 17% performance boost.
  • Scalability: The TPP-based workloads showed near-perfect weak scaling up to 64 sockets in a cluster environment.
Fig. 1. Use-cases of TPPs in various software stacks.

Limitations and Future Work

While the current work focuses heavily on CPUs (Intel and ARM), the authors acknowledge that the TPP abstraction is naturally suited for GPUs and specialized AI accelerators.

  • Future Architectures: Plans are in place to extend the TPP back-end to support NVIDIA (CUDA) and AMD (HIP) GPUs, as well as the POWER architecture.
  • Compiler Integration: The authors envision TPP becoming a formal dialect within the MLIR (Multi-Level Intermediate Representation) ecosystem, allowing tensor compilers to use TPP as a high-performance lowering target.

Summary updated

BibTeX
@misc{georganas2021tensor,
  author = {Evangelos Georganas and Dhiraj D. Kalamkar and Sasikanth Avancha and Menachem Adelman and Cristina Anderson and Alexander Breuer and Narendra Chaudhary and Abhisek Kundu and Md. Vasimuddin and Sanchit Misra and Ramanarayan Mohanty and Hans Pabst and Barukh Ziv and Alexander Heinecke},
  title = {{Tensor Processing Primitives: A Programming Abstraction for Efficiency and Portability in Deep Learning Workloads}},
  year = {2021},
  eprint = {2104.05755},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.05755},
}
Figure