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

Hexcute: A Compiler Framework for Automating Layout Synthesis in GPU Programs

Xiao Zhang, Yaoyao Ding, Bolin Sun, Yang Hu, Tatiana Shpeisman, Gennady Pekhimenko

TL;DR

Hexcute is a new compiler framework that automates the complex task of tensor layout synthesis for GPUs while giving developers explicit control over dataflow and pipelining. By formalizing layout synthesis as a constraint programming problem solved via type inference, it matches the performance of hand-optimized libraries like CUTLASS with up to 8× less code. Furthermore, it delivers massive speedups over high-level frameworks like Triton when executing complex, modern deep learning operators.

What Problem Does This Paper Address?

Achieving peak performance on modern GPUs requires meticulous management of tensor layouts—the exact mapping functions that describe how data is parallelized across threads and arranged within memory hierarchies (shared memory, registers, etc.). Poorly designed layouts lead to severe hardware inefficiencies, such as uncoalesced global memory accesses or shared memory bank conflicts.

Currently, developers face an unpleasant trade-off:

  1. Low-level frameworks (e.g., CUTLASS, Hidet): Offer maximum expressiveness and performance but require programmers to manually specify complex layouts. This process is highly error-prone, tedious, and demands deep hardware expertise.
  2. High-level programming models (e.g., Triton): Automate layout generation using compiler heuristics. However, these heuristics fail to generalize to emerging, complex deep learning operators—such as mixed-type operators used in weight-only quantization or selective scans in Mamba architectures. This failure often results in suboptimal memory placement and excessive data copying.

Hexcute bridges this gap by providing a tile-level programming model that automates layout synthesis while preserving explicit developer control over dataflow and pipelining.

Fig. 1: Shared memory and register tensors in GPU programs. (a) A shared memory tensor stored in row-major-interleaved order. (b) A register tensor distributed across 8 threads, with each thread holding 4 elements. (c) The distribution of the register tensor in (b) is described by a function f.

Methods

Hexcute introduces a Python-embedded Domain-Specific Language (DSL) that extends Hidet Script with tile-level primitives. The framework operates through a multi-step constraint-based compilation workflow:

  • Algebraic Layout Modeling: Hexcute adopts CuTe’s layout abstraction, treating layouts as mathematical functions. Because these layouts form a monoid under function composition, complex layouts can be systematically constructed and inverted.
  • Thread-Value Layout Synthesis: The compiler partitions the program's data-flow graph into subgraphs separated by memory boundaries. It sets performance-critical operations (like GEMM) as anchors, instantiates their hardware-mandated layouts, and propagates constraints forward and backward using a type-inference-based algorithm.
  • Shared Memory Layout Unification: Once register layouts are determined, Hexcute builds alignment-aware constraints for shared memory accesses. It uses a layout operation called unification to find a conflict-free base memory layout and applies swizzling functions to eliminate bank conflicts.
  • Analytical Cost Model: When multiple hardware instruction choices create a vast search space of valid layouts, Hexcute utilizes an analytical cost model based on instruction scheduling and microbenchmarks to select the lowest-latency candidate without needing full compilation.

Datasets

The framework was evaluated using extensive microbenchmarks and end-to-end deep learning workloads on NVIDIA A100 and H100 GPUs.

  • Operator Benchmarks: FP16 GEMM, Fused Multi-Head Attention (MHA) Forward/Decoding, Blockwise Scaled FP8 GEMM, and Warp-Specialized GEMM.
  • Complex Layers: Mixed-type Mixture-of-Experts (MoE) and the Mamba selective scan operator.
  • End-to-End Workloads: Integrated into the state-of-the-art vLLM inference engine to evaluate popular open-source LLMs: DeepSeek-R1-AWQ, Jamba-mini-1.7, and Qwen-3-32B.

Key Insights and Ideas

  • Layouts as Types: By embedding layout functions directly into tensor types, layout consistency becomes a verifiable type-inference problem. The compiler guarantees correctness-by-construction across the entire execution graph.
  • The Sweet Spot of Control: Fully automated compilers often make poor data placement decisions for non-standard operators. Hexcute proves that letting the engineer dictate where data lives and how it pipelines, while letting the compiler handle how it is packed and mapped to threads, yields optimal performance with minimal code.
  • Vectorization via Layout Inference: Ad-hoc heuristics often fall back to scalar memory instructions when faced with mixed data types (e.g., FP16 activations multiplied by INT4 weights). Hexcute's systematic mathematical solver naturally discovers wider, vectorized memory instructions (up to 16 bytes per instruction), maximizing memory bandwidth utilization.

Key Results

  • Code Efficiency: Hexcute matched or exceeded the performance of expert-tuned libraries like cuBLAS and FlashAttention while reducing the lines of code by 1.27× to 7.94× compared to CUTLASS.
  • Mixed-Type MoE Speedups: On an H100 GPU, Hexcute achieved an average speedup of 6.46× over Triton and 28.42× over older Marlin implementations for mixed-type MoE layers.
  • Mamba Selective Scan: Outperformed the hand-optimized Mamba library by 4.17× due to superior instruction selection and software pipelining.
  • End-to-End vLLM Performance: Delivering generation speedups of up to 2.60× on DeepSeek-R1-AWQ and 2.04× on a Mamba-based model, demonstrating massive practical impact for LLM serving.

Limitations and Future Work

  • Chained GEMM Constraints: When multiple GEMM operations are sequentially connected via register tensors, Hexcute may introduce register-layout conversion overhead to maintain correctness. Currently, users must manually annotate consistent thread arrangements to avoid this. The authors plan to automate dependency analysis to eliminate this manual step.
  • Search Space Complexity: While the analytical cost model effectively prunes the layout search tree, an exponential explosion remains theoretically possible if a program contains a massive number of highly interdependent shared-memory buffers. Further formalization of search-space decomposition is flagged for future research.

Summary updated

BibTeX
@misc{zhang2025hexcute,
  author = {Xiao Zhang and Yaoyao Ding and Bolin Sun and Yang Hu and Tatiana Shpeisman and Gennady Pekhimenko},
  title = {{Hexcute: A Compiler Framework for Automating Layout Synthesis in GPU Programs}},
  year = {2025},
  eprint = {2504.16214},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.16214},
}
Figure