[Paper Review] The CoRa Tensor Compiler: Compilation for Ragged Tensors with Minimal Padding
CoRa is a tensor compiler that compiles ragged tensor operators with minimal padding, enabling efficient execution on CPUs and GPUs by generating optimized code for irregular data shapes. It achieves a 1.6× geomean speedup over PyTorch on an NVIDIA V100 GPU and a 1.37× speedup over TensorFlow on a 64-core ARM CPU for transformer multi-head attention.
There is often variation in the shape and size of input data used for deep learning. In many cases, such data can be represented using tensors with non-uniform shapes, or ragged tensors. Due to limited and non-portable support for efficient execution on ragged tensors, current deep learning frameworks generally use techniques such as padding and masking to make the data shapes uniform and then offload the computations to optimized kernels for dense tensor algebra. Such techniques can, however, lead to a lot of wasted computation and therefore, a loss in performance. This paper presents CoRa, a tensor compiler that allows users to easily generate efficient code for ragged tensor operators targeting a wide range of CPUs and GPUs. Evaluating CoRa on a variety of operators on ragged tensors as well as on an encoder layer of the transformer model, we find that CoRa (i)performs competitively with hand-optimized implementations of the operators and the transformer encoder and (ii) achieves, over PyTorch, a 1.6X geomean speedup for the encoder on an Nvidia GPU and a 1.86X geomean speedup for the multi-head attention module used in transformers on an ARM CPU.
Motivation & Objective
- Address the performance bottleneck caused by padding and masking in deep learning frameworks when processing variable-shaped data.
- Enable efficient, portable compilation of ragged tensor operators across diverse hardware substrates like CPUs and GPUs.
- Reduce the need for hand-optimized kernels by automating high-performance code generation for irregular tensor operations.
- Overcome limitations in existing dense and sparse tensor compilers that fail to express or optimize ragged tensor operations effectively.
- Provide a unified, extensible compiler stack that supports both CPU and GPU backends with minimal performance loss due to shape irregularity.
Proposed method
- Design a domain-specific language (DSL) to express ragged tensor operators with variable-sized tensor slices and irregular loop bounds.
- Introduce a code generation pipeline that transforms high-level operator descriptions into optimized LLVM or CUDA code, avoiding padding through shape-aware scheduling.
- Leverage loop transformation techniques such as tiling, fusion, and parallelization to handle variable loop bounds while preserving data locality and instruction-level parallelism.
- Integrate with Z3 for constraint solving and LLVM for low-level code generation, enabling automatic optimization of memory access patterns and kernel launch configurations.
- Support both CPU and GPU backends by generating target-specific code with hardware-aware optimizations, including register blocking and warp-level primitives on GPUs.
- Use a modular architecture to decouple operator specification from code generation, enabling easy extension to new operators and hardware platforms.
Experimental results
Research questions
- RQ1Can a tensor compiler generate high-performance code for ragged tensor operators without relying on padding or masking?
- RQ2How does the performance of automatically generated code from CoRa compare to hand-optimized implementations on diverse hardware platforms?
- RQ3To what extent does CoRa reduce computational waste compared to padding-based approaches in transformer models?
- RQ4Can CoRa achieve competitive performance across both CPU and GPU workloads while maintaining portability and low implementation effort?
- RQ5How effective is CoRa in optimizing complex, real-world operators such as multi-head attention and transformer encoder layers?
Key findings
- CoRa achieves a 1.6× geomean speedup over PyTorch on an NVIDIA V100 GPU for the transformer encoder layer, demonstrating strong competitiveness with hand-optimized kernels.
- On a 64-core ARM Neoverse N1 CPU, CoRa achieves a 1.37× geomean speedup over TensorFlow for the multi-head attention module, significantly outperforming the baseline.
- The performance of CoRa-generated kernels is competitive with hand-optimized implementations, indicating that automatic code generation can match expert-level optimization.
- CoRa reduces wasted computation by avoiding padding, especially in large-batch scenarios where padding overhead becomes substantial, as shown in the FLOP analysis of the transformer encoder.
- The compiler successfully handles complex, irregular loop structures in ragged operators without sacrificing performance, even on highly parallel architectures like GPUs.
- Evaluation on eight NLP datasets confirms that CoRa's performance is stable across diverse sequence lengths and data distributions, validating its generalization capability.
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.