Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

IntrinTrans

IntrinTrans is a LangGraph-based agentic pipeline that automatically migrates ARM NEON vector intrinsic C/C++ code to RISC-V Vector (RVV) intrinsic code. It combines an LLM translation agent with iterative compile-test-optimize feedback loops to produce correct, vectorized RVV implementations.

Architecture Overview

The pipeline is implemented as a LangGraph StateGraph with the following nodes:

START
 │
 ▼
translator ──────────────────────────────────────────────┐
 │ │ (compile/test failure → fix)
 ▼ │
compiler ──(fail)──► translator (fix) / select_best ◄────┘
 │
 ▼ (success)
tester ──(fail)──► translator (fix) / optimizer (fix) / select_best
 │
 ▼ (pass)
optimizer ──► compiler ──► tester
 │ │
 │ (pass)▼
 │ record_version
 │ │
 └─────────────── (loop) ────┘
 │ (limit reached)
 ▼
 select_best ──► END
Node Responsibility
translator Calls LLM to generate or fix RVV code from the ARM NEON source; manages multi-turn conversation history
compiler Cross-compiles the generated code with CMake + Ninja; runs optional register liveness analysis
tester Executes the binary via QEMU or remote SSH; validates [Tests Passed] and checks for RVV intrinsic usage
optimizer Calls LLM to improve register usage guided by liveness analysis; supports fix sub-loops
record_version Appends each passing optimized variant to all_passed_versions
select_best Picks the highest-speedup (or latest) version as best_version

Prerequisites

Requirement Notes
Python ≥ 3.9 Async/await, TypedDict generics
RISC-V GCC toolchain Cross-compiler targeting rv64gcv; set RISCV_TOOLCHAIN_PATH
CMake ≥ 3.16 + Ninja Build system for cross-compilation
QEMU (qemu-riscv64) For local functional testing at vlen=128/256; or a remote RISC-V device
OpenAI-compatible API key Any provider routed via OPENAI_BASE_URL (e.g., OpenRouter)
VecIntrinBench Benchmark suite providing ARM NEON source files and GTest-based test files (included as a git submodule)

Installation

# 1. Clone the repository
git clone git@github.com:RuyiAI-Stack/IntrinTrans.git
cd IntrinTrans
# 2. Initialize submodules
git submodule update --init --recursive
# 3. Install Python dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
# Edit .env with your values
# 5. Validate configuration
python run.py --check-config

Usage

Translate a single function

python run.py --func-name <casename> --model <model-id>

The tool auto-locates source and test files from:

  • VecIntrinBench/src/arm/<casename>.cpp — ARM NEON source
  • VecIntrinBench/test/<casename>.cpp — GTest-based functional test
  • VecIntrinBench/perf/<casename>.cpp — (optional) performance test

Examples:

# Translate using DeepSeek V3
python run.py --func-name volk_32u_popcnt --model deepseek/deepseek-v3.2
# Translate with custom attempt limits
python run.py --func-name volk_32u_popcnt \
 --model google/gemini-3.1-pro-preview \
 --max-translation 5 \
 --max-optimization 2

Project Structure

VITrans-CSCWD/
├── run.py # CLI entry point
├── requirements.txt # Python dependencies
├── .env.example # Environment configuration template
│
├── intrintrans/ # Core package
│ ├── config.py # Config loader (.env + os.environ)
│ ├── state.py # LangGraph state types (TranslationState, TranslationPhase)
│ ├── graph.py # LangGraph workflow definitions (full / opt-only)
│ │
│ ├── agents/
│ │ └── llm_client.py # Async OpenAI-compatible client with retry logic
│ │
│ ├── nodes/
│ │ ├── translator.py # Translator node (NEON → RVV via LLM)
│ │ ├── compiler.py # Compiler node (CMake + Ninja cross-compilation)
│ │ ├── tester.py # Tester node (QEMU / remote SSH execution)
│ │ └── optimizer.py # Optimizer, record_version, select_best nodes
│ │
│ └── utils/
│ ├── build_tools.py # cmake_build_and_test, run_test, parse_code, liveness analysis
│ └── logging_utils.py # Step record helpers, log formatting
│
└── VecIntrinBench/ # Benchmark submodule (ARM NEON sources + GTests)
 ├── src/arm/ # Input: ARM NEON intrinsic functions
 ├── test/ # Functional test cases (GTest)
 ├── perf/ # Performance test cases (optional)
 └── toolchain/riscv.cmake # RISC-V CMake toolchain file

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /