Introduction
In modern deep learning, tensor operators like General Matrix Multiplication (GEMM) and Convolution account for over 90% of computational workloads. To achieve peak performance, these operators must be meticulously optimized for specific hardware using low-level primitives such as assembly instructions and hardware-specific intrinsics. Traditionally, this process requires months of expert human effort for every new chip architecture, creating a significant bottleneck in hardware-software co-design.
While Large Language Models (LLMs) have shown promise in code generation, they typically struggle with low-level hardware-specific optimizations. Standard prompting techniques often result in generic C code that fails to leverage specialized hardware features like vector registers or complex memory hierarchies.
The QiMeng-TensorOp Framework
To address these challenges, the authors propose QiMeng-TensorOp, a framework designed to bridge the gap between high-level intent and low-level performance. The system automates the generation of high-performance tensor operators through a structured three-step process.
1. Hardware Architecture Comprehending
The first stage involves extracting critical hardware factors from technical manuals. By providing the LLM with "Hardware Intrinsic Optimization Hints," the system enables the model to map architectural specifications—such as cache sizes, register counts, and instruction sets (e.g., RISC-V's vfmacc.vv)—directly to effective optimization strategies.
2. Tensor Operator Generation (TOG)
Rather than generating assembly code directly, which is highly error-prone for LLMs, QiMeng-TensorOp employs a two-tier generation strategy:
- Sketch Generation: The LLM produces a high-level C or CUDA "sketch" that defines the overall structure, including memory tiling and loop reordering.
- Kernel Generation via Meta-Programming: The LLM writes a Python script that programmatically generates the final assembly kernel. This approach leverages the LLM's superior proficiency in Python to manage complex low-level details like register allocation and instruction scheduling reliably.
3. LLM-Assisted MCTS Auto-Tuning
The final stage optimizes performance parameters (e.g., tile sizes) using Monte Carlo Tree Search (MCTS). Unlike traditional "blind" search algorithms, QiMeng-TensorOp uses the LLM's semantic reasoning to guide the search. The LLM analyzes search history to suggest promising tuning actions, significantly pruning the search space and accelerating convergence to optimal configurations.
Experimental Evaluation
The framework was rigorously tested across multiple hardware platforms, including RISC-V (C906 to K1), ARM (A72, A76), and NVIDIA GPUs (RTX 4060, A100). Benchmarks included GEMM and Convolution operators with dimensions derived from state-of-the-art models like Llama-3 and ResNet-50.
Key Results
- Performance Superiority: On RISC-V architectures, QiMeng-TensorOp achieved 251% of the performance of the expert-tuned OpenBLAS library. On NVIDIA GPUs, it reached 124% of cuBLAS performance.
- Efficiency Gains: Compared to the widely used TVM auto-compiler, the framework delivered up to 1.38× speedup for GEMM and 2.43× for Convolution.
- Cost Reduction: The automated pipeline reduces development time from weeks of expert labor to approximately 12–20 minutes, representing a 200× reduction in engineering cost.
Conclusion and Future Work
QiMeng-TensorOp demonstrates that LLMs, when guided by structured hardware knowledge and a meta-programming approach, can surpass human experts in low-level code optimization. By treating hardware manuals as a source of "semantic priors," the framework achieves both high performance and cross-platform portability. Future research will focus on expanding the library of supported operators (e.g., LayerNorm, Softmax) and further refining the auto-tuning process for heterogeneous systems.
Summary updated