[Paper Review] High-Performance Tensor Contraction without Transposition
This paper presents TBLIS, a high-performance tensor contraction library that eliminates explicit transposition by fusing tensor-to-matrix mapping with BLIS-based matrix multiplication kernels. By leveraging the BLIS framework's flexible algorithmic structure, the authors achieve performance near matrix multiplication levels, outperforming traditional approaches like TTGT and BSMTC in both single- and multi-core workloads, especially for complex tensor shapes.
Tensor computations--in particular tensor contraction (TC)--are important kernels in many scientific computing applications. Due to the fundamental similarity of TC to matrix multiplication (MM) and to the availability of optimized implementations such as the BLAS, tensor operations have traditionally been implemented in terms of BLAS operations, incurring both a performance and a storage overhead. Instead, we implement TC using the flexible BLIS framework, which allows for transposition (reshaping) of the tensor to be fused with internal partitioning and packing operations, requiring no explicit transposition operations or additional workspace. This implementation, TBLIS, achieves performance approaching that of MM, and in some cases considerably higher than that of traditional TC. Our implementation supports multithreading using an approach identical to that used for MM in BLIS, with similar performance characteristics. The complexity of managing tensor-to-matrix transformations is also handled automatically in our approach, greatly simplifying its use in scientific applications.
Motivation & Objective
- To eliminate the performance and memory overhead of explicit tensor transposition in tensor contraction.
- To develop a general-purpose, high-performance tensor contraction library that avoids code generation and runtime overhead.
- To achieve performance comparable to optimized matrix multiplication using a flexible, extensible framework.
- To enable efficient multithreaded execution with minimal user intervention in tensor layout management.
- To provide a production-ready, open-source solution (TBLIS) that supports diverse tensor shapes and contraction patterns.
Proposed method
- The authors design two novel tensor-to-matrix mappings—Scatter-Matrix Tensor Contraction (SMTC) and Block-Scatter-Matrix Tensor Contraction (BSMTC)—that enable in-place access to tensor elements within matrix kernels.
- These mappings are integrated into the BLIS framework, which allows transposition and data packing to be fused with kernel computation, eliminating separate transposition operations and additional workspace.
- The approach leverages BLIS's modular design, where matrix multiplication is decomposed into independent algorithmic components, enabling custom tensor contraction algorithms to be constructed from the same primitives used for MM.
- The implementation uses a block-based data layout and optimized memory access patterns to improve cache reuse and vectorization, minimizing data movement.
- Multithreading is achieved using the same threading model as BLIS for matrix multiplication, ensuring consistent performance scaling.
- The TBLIS library automatically handles tensor-to-matrix index transformations, abstracting away low-level complexity for users.
Experimental results
Research questions
- RQ1Can tensor contraction be implemented at near-matrix multiplication performance without explicit transposition or additional workspace?
- RQ2How does the performance of BLIS-based tensor contraction compare to traditional TTGT and BSMTC approaches across diverse tensor shapes?
- RQ3To what extent does the proposed method scale across multiple cores in both computation- and communication-bound scenarios?
- RQ4Can the BLIS framework's modularity be effectively used to build high-performance, general-purpose tensor contraction kernels?
- RQ5What is the impact of inefficient data access patterns on tensor contraction performance, and how can they be mitigated?
Key findings
- The BSMTC algorithm achieves performance within 10% of peak machine performance for many tensor shapes, approaching the efficiency of matrix multiplication.
- In single-core, computation-bound cases, BSMTC and BLIS perform similarly and close to peak, while TTT (TTGT) shows a sharp performance drop, falling below 10 GFLOPs for larger tensors.
- For communication-bound cases, BSMTC maintains ~30 GFLOPs, while TTT drops to <10 GFLOPs, indicating a significant performance advantage of the proposed approach.
- In multi-core execution, BSMTC achieves speedups up to 21.1× over TTT, with speedup ranging from 1.3× to 21.1× depending on tensor shape, demonstrating strong scalability.
- The BSMTC algorithm outperforms BLIS in several cases, likely due to a more optimal matrix multiplication variant used internally, highlighting the benefits of algorithmic customization.
- The TBLIS library successfully avoids the workspace overhead of TTGT and provides a production-ready, open-source implementation under BSD license.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.