Abstract
The computational power increases over the past decades have greatly enhanced the ability to simulate chemical reactions and understand ever more complex transformations. Tensor contractions are the fundamental computational building block of these simulations. These simulations have often been tied to one platform and restricted in generality by the interface provided to the user. The expanding prevalence of accelerators and researcher demands necessitate a more general approach which is not tied to specific hardware or requires contortion of algorithms to specific hardware platforms. In this paper we present COMET, a domain-specific programming language and compiler infrastructure for tensor contractions targeting heterogeneous accelerators. We present a system of progressive lowering through multiple layers of abstraction and optimization that achieves up to 1.98X speedup for 30 tensor contractions commonly used in computational chemistry and beyond.
Introduction
In computational chemistry, simulations of complex molecular systems rely heavily on tensor contractions—high-dimensional generalizations of matrix multiplication. Historically, scientists have faced a difficult choice: utilize high-level languages that are intuitive but inefficient, or develop highly specialized, low-level code that is performant but difficult to maintain and port across hardware architectures. Existing solutions often rely on "black-box" libraries that optimize individual operations but lack the global visibility required for cross-operation optimizations. COMET addresses this by providing a domain-specific compiler that understands both high-level mathematical abstractions (Einstein notation) and low-level hardware constraints simultaneously.
Methods: The COMET Compilation Framework
COMET leverages the Multi-Level Intermediate Representation (MLIR) framework to implement a system of progressive lowering. This approach allows the compiler to apply optimizations at the most appropriate level of abstraction:
- TA Dialect (High-Level): The compiler starts with a Domain-Specific Language (DSL) representing standard mathematical expressions. At this stage, it performs global algorithmic optimizations, such as multi-operand reordering and optimal index permutation, which can reduce the total computational footprint by orders of magnitude.
- LinAlg/Loop Dialects (Intermediate): The high-level representation is lowered to more general operations. COMET utilizes the Transpose-Transpose-GEMM-Transpose (TTGT) method to reformulate complex tensor contractions into standard matrix multiplications (GEMM), leveraging highly optimized existing hardware kernels.
- LLVM/Micro-kernels (Low-Level): Finally, the compiler generates machine code optimized for specific hardware features, such as AVX-512 vector instructions or custom hardware accelerators.
A significant feature of COMET is its support for hardware-software co-design. By integrating with hardware simulators like Aladdin, researchers can evaluate the performance of chemistry workloads on hypothetical custom architectures before physical implementation.
Evaluation and Performance Results
The researchers evaluated COMET using the TCCG benchmark suite (30 tensor contractions) and 118 complex multi-operand expressions from the NWChem package.
Key Performance Metrics: * CPU Speedup: On standard x86 architectures, COMET achieved an average speedup of 1.22x and a peak of 1.98x compared to the manually optimized TCCG library. * Multi-Operand Optimization: By analyzing entire expression chains, COMET achieved up to 23.9x speedup for complex sequences of contractions simply by reordering operations to minimize redundant work. * Accelerator Performance: When targeting simulated custom hardware, COMET reached performance levels of 156 GFLOPS, a 3.1x improvement over software-only vector optimizations on standard CPUs.
The study also highlighted the importance of hardware tailoring; for instance, medium-sized accelerator tiles (64x64) often outperformed larger ones (256x256) by avoiding memory bottlenecks and cache overflows.
Conclusion
COMET demonstrates that a compiler-based approach to tensor algebra can bridge the gap between high-level scientific productivity and low-level hardware performance. By automating complex optimizations across multiple layers of abstraction, COMET matches or exceeds the performance of hand-tuned libraries while maintaining portability. Future work will focus on extending these capabilities to sparse tensor algebra and a wider array of hardware backends.
Summary updated