NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Tensor Comprehensions: Framework-Agnostic High-Performance Machine Learning Abstractions

Nicolas Vasilache, Oleksandr Zinenko, Theodoros Theodoridis, Priya Goyal, Zachary DeVito, William S. Moses, Sven Verdoolaege, Andrew Adams, Albert CohenarXiv 2018

Introduction

The rapid evolution of deep learning is often bottlenecked by the gap between mathematical innovation and hardware efficiency. While frameworks like PyTorch and TensorFlow provide high-level abstractions, they rely heavily on hand-tuned vendor libraries such as NVIDIA’s cuDNN for performance. This dependency creates a "custom operator penalty": researchers who develop novel layers must either accept suboptimal performance or undertake the arduous task of writing manual CUDA kernels. Tensor Comprehensions (TC) addresses this by providing a high-level language and a polyhedral Just-In-Time (JIT) compiler that automatically generates highly optimized GPU kernels from mathematical notation.

The Challenge of Custom Operators

Modern deep learning performance is built on the back of libraries like cuBLAS and cuDNN. However, these libraries are designed for a fixed set of standard operations. When a researcher introduces a non-standard operation—such as a specific grouped convolution or a novel activation function—the framework often falls back to unoptimized implementations.

Furthermore, vendor libraries are typically "black boxes" that cannot optimize across operator boundaries. This prevents "kernel fusion," where multiple operations are combined into a single GPU kernel to reduce memory traffic and launch overhead. Finally, because these libraries must be generic, they often fail to exploit the specific tensor shapes (e.g., exact batch sizes or hidden layer dimensions) used in a particular model, leaving significant performance on the table.

The Tensor Comprehensions Architecture

TC bridges the gap between high-level intent and low-level execution through a three-tiered system:

1. The TC Language

The TC language is a domain-specific language (DSL) inspired by Einstein notation. It allows users to express tensor operations as pure mathematical identities. The language is designed to be concise and safe; it automatically infers loop ranges and tensor shapes, preventing common errors like out-of-bounds memory access while keeping the code readable for researchers.

2. Polyhedral JIT Compiler

At the heart of TC is a polyhedral compiler. Unlike traditional compilers that treat loops as simple sequences, the polyhedral model treats nested loops as geometric objects. This allows the compiler to perform sophisticated transformations:

  • Loop Scheduling and Tiling: Automatically organizing how data is processed to maximize cache hits and minimize latency.
  • Mapping to Hardware: Intelligently assigning computations to GPU blocks and threads.
  • Memory Promotion: Automatically identifying frequently accessed data and moving it into the GPU’s high-speed shared memory.

3. Autotuning and Compilation Cache

The search space for optimal GPU parameters (such as tile sizes and unroll factors) is vast. TC employs a multi-threaded genetic autotuner that explores this space by compiling and profiling candidate kernels on the actual hardware. Once an optimal configuration is found for a specific tensor shape, it is stored in a compilation cache, ensuring that subsequent JIT requests are nearly instantaneous.

Performance and Key Results

The effectiveness of TC was evaluated using a benchmark of standard and custom operations, as well as production-scale Multi-Layer Perceptrons (MLPs) used in recommendation systems.

  • General Performance: TC-generated kernels achieved up to a 4x speedup over standard, highly-tuned NVIDIA libraries for specific operations.
  • Grouped Convolutions: For ResNeXt-style grouped convolutions, TC outperformed Caffe2 (using cuDNN) by 1.4x to 3.6x on Maxwell GPUs and 1.9x to 8.8x on Pascal GPUs.
  • Kernel Fusion in Production: In a real-world recommendation system model featuring three sequential MLP layers, TC fused the operations into a single kernel. This reduced the execution time to 32µs—a 3.6x speedup over the reference implementation—by eliminating the "death by a thousand launches" (the overhead of launching multiple small CUDA kernels).

Discussion and Limitations

TC demonstrates that "abstraction without regret" is possible: researchers can write mathematical code that the compiler turns into hardware-optimized kernels. By specializing kernels for exact tensor shapes at runtime, TC often outperforms generic vendor libraries.

However, the system currently has limitations. The initial implementation is restricted to NVIDIA GPUs and does not yet support the recurrent definitions required for Recurrent Neural Networks (RNNs). Additionally, while TC handles shared memory well, it does not yet implement advanced register-level optimizations, meaning some kernels remain bottlenecked by memory bandwidth rather than compute power.

Conclusion

Tensor Comprehensions represents a significant step toward framework-agnostic, high-performance machine learning. By automating the path from mathematical expression to optimized GPU code, TC empowers researchers to innovate without being constrained by the limitations of pre-existing operator libraries. Future work aims to expand support to sparse tensors, mixed-precision arithmetic, and a wider range of hardware architectures.

Summary updated

BibTeX
@misc{vasilache2018tensor,
  author = {Nicolas Vasilache and Oleksandr Zinenko and Theodoros Theodoridis and Priya Goyal and Zachary DeVito and William S. Moses and Sven Verdoolaege and Andrew Adams and Albert Cohen},
  title = {{Tensor Comprehensions: Framework-Agnostic High-Performance Machine Learning Abstractions}},
  year = {2018},
  eprint = {1802.04730},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1802.04730},
}
Figure