Leveraging Instruction Language Model to Generate Vectorized RISC-V Tensor Programs

Yang Bai, Mingjun Li, Wendong Xu, Bei YuOpenReview 2026 · Submission to ICLR 2026 · Rejected · OpenReview

TL;DR

RISCompiler is a new compilation framework that treats hardware optimization as a language generation task. By fine-tuning a Llama-3.2 model with a specialized "Instruction Language Model" (ILM) and a novel Mixture-of-Experts (MoE) adapter strategy, it automatically generates high-performance vectorized code for RISC-V processors, outperforming traditional compilers like LLVM and GCC by up to 1.65x.

What Problem Does This Paper Address?

In the world of high-performance computing and AI, vectorization is the secret sauce for speed. It allows a processor to perform the same operation on multiple data points simultaneously (SIMD). However, the open-source RISC-V architecture’s vector extension (RVV) is notoriously difficult to program.

Traditional compilers (like GCC or LLVM) often fail to vectorize code because they are too "conservative"—they struggle with complex data dependencies and memory patterns. On the other hand, "search-based" compilers try to find the best code by brute-forcing thousands of combinations, which is slow and relies on imperfect performance models. RISCompiler addresses this "vectorization gap" by using Large Language Models (LLMs) to predict the best optimization strategies directly.

Methods

The authors introduce RISCompiler, which transforms the optimization process into a sequence-to-sequence generation task. The core components include:

  1. Instruction Sentences: Instead of feeding raw assembly to the LLM, the authors designed a "language-model-friendly" text representation. These sentences describe the operator (e.g., a matrix multiplication), its dimensions, and specific hardware-level "knobs" like vector width, register count, and instruction combinations.
  2. Instruction Language Model (ILM): Based on the Llama-3.2-3B architecture, this model is trained to "read" a scalar program and "write" the optimized instruction sentences.
  3. Asymmetric LoRA-MoE: This is the technical highlight. Standard fine-tuning (LoRA) uses a single set of trainable weights. RISCompiler uses an asymmetric structure: a shared "A" matrix for general knowledge and multiple "B" matrices acting as "experts" for different types of vectorized instructions. A "router" mechanism decides which expert to use for a given piece of code, making the fine-tuning both efficient and highly specialized.
  4. Three-Stage Pipeline:
    • Offline Learning: Sampling a massive space of possible optimizations to create a training dataset.
  5. Efficient Fine-Tuning: Training the ILM using the MoE strategy.
  6. Code Generation: Using the trained model to generate optimized RISC-V programs for new, unseen operators.

Datasets

The researchers built a comprehensive offline dataset to train the ILM:

  • Workloads: 86 distinct workloads and roughly 1,800 operators.
  • Scale: 0.5 million instruction sentences encompassing various vectorized optimizations.
  • Sources: Operators were derived from popular deep learning benchmarks like TenSet, timm (PyTorch Image Models), and HuggingFace Transformers, covering both Computer Vision and NLP tasks.
  • Evaluation: The model was tested on end-to-end networks including ResNet-50, VGG-16, MobileNet-v2, DenseNet, and BERT.

Key Insights and Ideas

  • Optimization as Translation: The biggest "aha moment" is treating compiler optimization not as a mathematical search, but as a translation task from "what the code does" to "how the hardware should do it."
  • Domain-Specific PEFT: The authors realized that a standard LLM is too general. By using the Asymmetric LoRA-MoE, they allow the model to develop "muscle memory" for specific RISC-V instructions (like vfmacc or vle32) without needing to retrain the entire 3-billion-parameter model.
  • Iterative Refinement: The ILM doesn't just guess the whole program at once. It iteratively predicts optimizations along specific axes (like vector width first, then register count), which helps filter out invalid configurations early.

Key Results

RISCompiler consistently outperformed both traditional compilers and general-purpose LLMs:

  • Single Operators: Achieved speedups of up to 1.65x over LLVM-Vectorizer and GCC-Loops across common operators like Conv2D and GEMM.
  • End-to-End Networks: Improved performance by up to 1.38x on full models like ResNet-50 and BERT.
  • Vs. General LLMs: It significantly outperformed Claude-3-Haiku. While Claude could achieve a 1.34x improvement over scalar code, RISCompiler reached 2.99x on the same operators because it was specifically fine-tuned for the RVV domain.

Limitations and Future Work

  • Fine-Tuning Overhead: Training the ILM takes about 35 hours on a high-end server. The authors note that if you only need to compile a single model once, this might not be the most cost-effective route.
  • Sampling Quality: The model's performance is heavily dependent on the quality of the "high-performance" samples it sees during the offline learning stage.
  • Future Directions: The authors suggest expanding the framework to support more complex operator fusion (combining multiple layers into one) and potentially adapting the ILM approach to other emerging hardware architectures beyond RISC-V.

Summary updated

Abstract

Auto-vectorization is a powerful optimization that significantly improves the performance of tensor programs on modern instruction set architectures.Transforming tensor programs into high performance vectorized programs is in high demand. However, traditional compilers often overlook opportunities to vectorization.Meanwhile, hand-crafting vectorized optimization using specialized instructions remains a complicated and error-prone endeavor that requires in-depth knowledge of specific instruction set architectures and compilers. In this paper, we introduce \textbf{RISCompiler}, a compiler designed to generate vectorized tensor programs with auto-vectorization tailored for the RISC-V target with vector extension. The main concept involves transforming the tensor program exploration task into generation task exploiting an instruction language model (ILM). To facilitate this, we create an instruction sentence representation suitable for ILM, which includes transformation details to accurately represent vectorized RISC-V tensor programs. RISCompiler uses an innovative, parameter-efficient fine-tuning mechanism to enhance domain adaptation by strategically concentrating on vectorized components, thereby boosting both fine-tuning and inference efficiency. During the compilation process, the ILM incorporates insights from offline learning and prior transformations to make optimal optimizations within the current design space. Experimental results demonstrate that RISCompiler, which are capable of generating high-performance vectorized tensor programs automatically, surpasses existing state-of-the-art compilers and scalar versions by a substantial margin.
BibTeX
@misc{bai2026leveraging,
  author = {Yang Bai and Mingjun Li and Wendong XU and Bei Yu},
  title = {{Leveraging Instruction Language Model to Generate Vectorized RISC-V Tensor Programs}},
  year = {2026},
  url = {https://openreview.net/forum?id=SFUMPoEQoC},
  howpublished = {OpenReview},
  note = {Submitted to ICLR 2026},
}
Figure