TL;DR
Hexcute is a new compiler framework that automates "layout synthesis"—the complex process of mapping data to GPU threads and memory—without sacrificing the performance of hand-tuned libraries. By treating layouts as mathematical functions and solving them via type inference, it enables researchers to write high-performance kernels for emerging models like DeepSeek-R1 and Mamba with significantly less code and effort than traditional low-level tools.
What Problem Does This Paper Address?
To get maximum performance out of a modern GPU (like an NVIDIA H100), programmers must meticulously manage how data is arranged in memory and distributed across thousands of threads. This mapping is called a tensor layout.
Currently, developers face a "Goldilocks" problem:
- Low-level frameworks (e.g., CUTLASS): Offer peak performance but require "heroic" programming effort. Developers must manually specify every layout and ensure they are consistent across different hardware instructions (like Tensor Cores), which is error-prone and time-consuming.
- High-level compilers (e.g., Triton): Are much easier to use because they use "heuristics" (rules of thumb) to automate layouts. However, these heuristics often fail on complex, modern operators—such as "mixed-type" operations (e.g., FP16 activations with INT4 weights) or the "scan" operations used in Mamba architectures—leading to suboptimal performance.
Hexcute aims to bridge this gap: providing the explicit control of low-level tools with the automation of high-level compilers.
Methods
Hexcute introduces a principled approach to layout synthesis by formalizing it as a constraint programming problem.
- Layouts as Functions: Borrowing from the CuTe library, Hexcute models layouts as mathematical functions that map thread/value indices to logical coordinates.
- Type-Inference Algorithm: Instead of the user specifying layouts, the user defines the high-level dataflow (e.g., "load this, then multiply"). Hexcute then infers the optimal layouts by looking at the requirements of the hardware instructions (like
mmafor matrix math orldmatrixfor memory loads). - Algebraic Constraints: Because layouts form a "monoid" under composition, Hexcute can use algebraic operations to solve for "unknown" layouts in a program graph.
- Analytical Cost Model: When multiple valid layout/instruction combinations exist, Hexcute uses a microbenchmark-based cost model to predict which one will have the lowest latency, selecting the winner without needing to run every version on the hardware.
Datasets
The authors evaluated Hexcute across a wide range of performance-critical operators and end-to-end models:
- Standard Operators: FP16 GEMM (General Matrix Multiplication), Fused Multi-Head Attention (MHA) for both forward and decoding passes.
- Emerging Operators: Mixed-type Mixture-of-Experts (MoE) kernels and the selective scan operator used in the Mamba architecture.
- End-to-End Evaluation: Integrated into the vLLM inference engine to test models like DeepSeek-R1-AWQ, Jamba-mini-1.7, and Qwen-3-32B.
- Hardware: Benchmarks were performed on NVIDIA A100 and H100 GPUs.
Key Insights and Ideas
- Decoupling Dataflow from Layout: The "aha moment" is that a programmer should be able to say what the algorithm does (the dataflow) while the compiler determines how the data sits in memory (the layout).
- Systematic vs. Heuristic: Unlike Triton, which uses fixed rules, Hexcute’s synthesis is systematic. It can "discover" complex layouts needed for weight-only quantization (like the Marlin kernel) that heuristics typically miss.
- Vectorization by Design: By solving for layouts that satisfy alignment constraints, Hexcute naturally generates wider, vectorized memory instructions (e.g., 16-byte loads), which are essential for saturating GPU memory bandwidth.
Key Results
- Productivity: Hexcute reduced the amount of code required by 1.27× to 7.94× compared to CUTLASS while achieving similar performance.
- Operator Speedups:
- For mixed-type MoE operators, Hexcute achieved an average speedup of 6.46× over Triton.
- On Mamba selective scans, it outperformed the hand-optimized Mamba library by 4.17× on average.
- End-to-End Performance: In vLLM, Hexcute delivered up to a 2.60× speedup on DeepSeek-R1-AWQ and a 2.04× speedup on Mamba-based models compared to the standard Triton-based implementations.
- Compilation Time: Despite the complex synthesis, Hexcute’s compilation time is comparable to Triton (e.g., ~48 seconds for a GEMM layer).
Limitations and Future Work
- Register-Layout Conversions: If a program has multiple matrix multiplications with conflicting layout requirements, Hexcute may insert "rearrange" operations. These operations involve inter-thread data exchange, which can add overhead.
- Manual Annotations: Currently, users must sometimes provide hints (annotations) to ensure consistent thread arrangements across different parts of a complex kernel. The authors aim to automate this in the future.
- Search Space Complexity: While the cost model helps, the search space for shared-memory layouts can theoretically be exponential. The authors suggest further work on pruning this search space for even more complex programs.
Summary updated