返回资讯中心
外部精选
软件工程
#开发者实时流

Show HN: Autotune – Genetic LLVM phase-ordering CLI that beats Clang -O3

A production-grade, AI-guided compiler optimization and diagnostics system that systematically searches, validates, and mathematically proves workload-specific LLVM pass pipelines to outperform standard -O3.

Hacker News 最新sandy1910202026/12/6 · 今天28 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

A production-grade, AI-guided compiler optimization and diagnostics system that systematically searches, validates, and mathematically proves workload-specific LLVM pass pipelines to outperform standard -O3.

Quick Start • Empirical Benchmarks • Why Autotune? • Architecture • CLI Reference • CI/CD Integration • Documentation

Compilers like Clang and GCC use fixed, general-purpose pass pipelines (such as -O3 or -O2). While these standard pipelines perform acceptably across millions of disparate software projects, they are fundamentally suboptimal for any specific compute-intensive workload. Because compiler optimizations are interdependent and non-commutative—a phenomenon known in computer science as the Phase-Ordering Problem—applying Pass A before Pass B can either unlock massive SIMD vectorization or permanently destroy vectorization opportunities.

Autotune transforms compiler optimization from manual guesswork into a reproducible, developer-usable science:

Zero Data Fabrication Policy: All speedups and benchmarks reported by Autotune are derived from real empirical execution on physical silicon. The language model is never the final authority—hypotheses must survive execution verification, multi-sample confirmation, and statistical significance testing ($p < 0.05$).

The following table presents real, un-fabricated benchmark results measured across curated workloads on Apple Silicon (ARM64) and Linux (x86_64) using LLVM New Pass Manager. Every result is backed by independent multi-sample re-benchmarking, bitwise correctness checks, and Welch's t-test statistical validation:

All runs evaluated with $N=10$ confirmation repetitions, 3 warmup iterations, CV noise $< 5.0%$, and $p < 0.0001$.

Feature Standard clang -O3

OpenTuner / GCC Plugins CompilerGym Autotune Doctor

Workload-Tailored Passes ❌ Fixed Pipeline ⚠️ Heuristic Only ⚠️ Research Only ✅ Fully Automated GA + AI

LLVM NPM Support ✅ Built-in ❌ Legacy Pass Manager ❌ Deprecated Pass Mgr ✅ Full Modern NPM (LLVM 14-22)

Configurable Baselines ❌ None ❌ Ad-hoc ❌ -O3 Only ✅ -O0, -O1, -O2, -O3, -Os

Statistical Proof Engine ❌ None ❌ Mean/Median Only ❌ Reward Score Only ✅ Welch $t$-test, Mann-Whitney, Cohen $d$

Bitwise Output Verification ❌ None ⚠️ Exit Code Only ❌ Emulated ✅ Exact, Numeric, Checksum, Script

Production Build Export ❌ CLI Flags Only ❌ Manual Shell Script ❌ Python Object Only ✅ CMake, Makefile, Shell, C Header

Zero-Knowledge Security N/A ❌ Plaintext configs ❌ N/A ✅ Native OS Keyring Isolation

CI Regression Gate ❌ None ❌ Custom Scripting ❌ N/A ✅ Native autotune guard with exit codes

🔬 System Workflow Architecture

flowchart TD A[C/C++ Workload Source] --> B[AST Feature Extraction & Profiling] B --> C[Empirical Baseline Benchmarking: -O0 / -O1 / -O2 / -O3] C --> D{Pipeline Seeding} D -->|Offline Heuristics| E[Microarchitecture-Biased Hardware Seeds] D -->|LLM Guidance| F[AI Pass Candidate Synthesis] E --> G[Genetic Algorithm Phase-Order Evolution Engine] F --> G G --> H[LLVM Pipeline Compilation: clang -> opt NPM -> native binary] H --> I[Pluggable Correctness Validation Gate] I -->|Failed / Miscompiled| J[Automatic Discard & Crash Analysis] I -->|Verified Correct| K[Fresh Multi-Sample Confirmation Benchmarking] K --> L[Statistical Verification: Welch t-test, Mann-Whitney U, Cohen's d] L --> M[Evidence Grading: Grade A / B / C / D / F] M --> N[Structured JSON & Interactive Standalone HTML Reports] N --> O[autotune apply / export / guard / reproduce]

Loading

🚀 Quick Start

  1. Installation

Recommended (isolated CLI install via pipx):

pipx install autotune-doctor

Or via pip:

pip install autotune-doctor

Or zero-setup Docker (includes LLVM/Clang toolchain):

docker run --rm -v "$PWD:/work" ghcr.io/youknowme19/autotune doctor /work/kernel.c

Or Homebrew (macOS / Linux):

brew install --HEAD packaging/homebrew/autotune.rb

Or install latest developer build from source:

git clone https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor.git cd Autotune-The-Phase-Ordering-CLI-Doctor pip install -e ".[dev]"

  1. Verify Toolchain Health

autotune doctor

Autotune v0.5.0 Phase-Ordering CLI Doctor

System & Toolchain Diagnostics ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Check Component ┃ Status ┃ Details ┃ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Python Version │ [OK] │ 3.11.15 │ │ OS & Architecture │ [OK] │ Darwin (arm64 - Apple Silicon) │ │ Clang Compiler │ [OK] │ /opt/homebrew/opt/llvm/bin/clang (v22.1.8) │ │ LLVM Opt Binary │ [OK] │ /opt/homebrew/opt/llvm/bin/opt (v22.1.8) │ │ Measurement Backend │ [OK] │ macOS high-precision monotonic timing │ └─────────────────────┴────────┴───────────────────────────────────────────────┘

  1. Optimize a Workload (Flagship Command)

autotune doctor examples/conv2d/kernel.c --preset quick --baseline -O0

╭──────────────────────────────────────────────────────────╮ │ AUTOTUNE DOCTOR │ │ AI-Guided LLVM Phase-Ordering Optimization & Diagnostics │ ╰──────────────────────────────────────────────────────────╯ Analyzing kernel.c (Preset: quick)... Gen 01/04 [━━━━━╸──────────────] | Best: 48.494 ms | Gain: 1.47x | Diversity: 1.00 | Valid: 8 Gen 02/04 [━━━━━━━━━━╸─────────] | Best: 48.494 ms | Gain: 1.47x | Diversity: 0.62 | Valid: 7 Gen 03/04 [━━━━━━━━━━━━━━━╸────] | Best: 48.037 ms | Gain: 1.48x | Diversity: 0.88 | Valid: 7 Gen 04/04 [━━━━━━━━━━━━━━━━━━━━╸] | Best: 45.998 ms | Gain: 1.55x | Diversity: 0.88 | Valid: 8

🏆 OPTIMIZATION FOUND

  • Baseline (-O0): 71.217 ms
  • Autotune Winner: 45.998 ms
  • Confirmed Gain: 1.55× (Grade A — IMPROVED)
  • Correctness: ✓ PASS
  • Statistical p: 0.0000 (Cohen's d: 56.27)

Winning pass pipeline: sroa → loop-rotate → licm → instcombine → loop-unroll

Artifacts:

  • JSON Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.json
  • HTML Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.html

Reproduce: autotune reproduce .autotune/runs/run_20260905_195221_f6b2f20b/report.json

🛠️ CLI Command Reference

autotune doctor

Flagship end-to-end workload optimization, evidence grading, and diagnostics.

autotune doctor <source> [OPTIONS]

Options: -b, --baseline TEXT Baseline optimization level [-O0|-O1|-O2|-O3|-Os|-Oz] (default: -O3) -p, --preset [quick|balanced|aggressive] Search preset budget (default: balanced) -w, --workload PATH Path to stdin workload input file --args TEXT Space-separated argv arguments passed to executable --correctness-strategy [exitcode|numeric] Validation verification strategy -o, --output-json PATH Path to export structured JSON report --export-sh PATH Export standalone reproduction shell script --cflags TEXT Extra compiler/linker flags (e.g. "-I./include -lm -march=native") --compile-commands PATH Path to compile_commands.json to auto-extract project flags --no-llm Enforce 100% offline heuristic search (zero network calls)

Real-World C/C++ Project Usage (CMake / Custom Headers / Libraries):

Pass custom include paths, macros, and libraries directly:

autotune doctor src/solver.cpp --cflags "-I./include -DFULL_PRECISION -lm -march=native"

Or auto-extract flags from your CMake/Meson/Bear compilation database:

autotune doctor src/solver.cpp --compile-commands build/compile_commands.json

autotune profile

Inspects AST structural complexity, loop depths, memory vs compute intensity, and suggests pass families.

autotune profile examples/matrix_transpose/kernel.c

Machine-readable JSON output for tooling pipelines:

autotune profile examples/matrix_transpose/kernel.c --json

autotune explain

Generates human-readable, scientifically grounded explanations of why the winning pass sequence outperformed baseline.

autotune explain .autotune/runs/run_latest/report.json

Explicitly deconstructs performance gains into:

Applies the winning pass pipeline and generates production compiler artifacts without mutating user source code.

autotune apply report.json --output-dir ./build/autotune/

Emits:

Exports reproducible compilation recipes into standard build systems.

Export CMake integration snippet:

autotune export report.json --format cmake -o autotune.cmake

Export Makefile snippet:

autotune export report.json --format make -o Makefile.autotune

Export standalone shell script:

autotune export report.json --format shell -o build_optimized.sh

autotune guard

Continuous Integration performance gate preventing speed and correctness regressions.

Fail CI build if candidate regresses by more than 3%:

autotune guard examples/matrix_transpose/kernel.c --reference report.json --threshold 0.03

Strict environment mode (fails if CPU architecture or LLVM major version changes):

autotune guard examples/matrix_transpose/kernel.c --reference report.json --strict-env --ci

🛡️ Continuous Integration Guard Gate

Integrate Autotune directly into your GitHub Actions workflow to block regressions in pull requests:

name: Performance Regression Guard

on: push: branches: [ main ] pull_request: branches: [ main ]

jobs: autotune-guard: runs-on: ubuntu-latest steps:

  • uses: actions/checkout@v4
  • uses: actions/setup-python@v5 with: python-version: "3.11"
  • name: Install LLVM & Clang run: sudo apt-get update && sudo apt-get install -y clang llvm llvm-dev
  • name: Install Autotune run: pip install autotune-doctor
  • name: Verify Performance Gate run: | autotune guard src/kernel.c --reference benchmarks/golden_report.json --threshold 0.05 --ci

📈 Statistical Rigor & Evidence Grades

Autotune does not rely on single-run measurements. Every candidate is evaluated using interleaved runs, Coefficient of Variation (CV%) noise checks, and non-parametric statistical tests:

Grade Classification Speedup ($\times$) Statistical Criteria Action

A IMPROVED $\ge 1.05\times$

$p < 0.05$, $d > 0.5$, CV $< 10%$

Eligible for Production & Knowledge Store

B MODEST_GAIN $1.02\times - 1.05\times$

$p < 0.05$, $d > 0.2$, CV $< 12%$

Statistically significant minor improvement

C NOISY_IMPROVEMENT $> 1.02\times$

$p \ge 0.05$ or High Variance Improvement observed but noisy

D PARITY $0.98\times - 1.02\times$ Indistinguishable from Baseline Optimization neutral

F

REGRESSION / FAIL

$< 0.98\times$ or Error Incorrect output, crash, or slowdown Immediate Discard

🔒 Security & Privacy

Zero Secret Leakage: API keys stored via autotune config keyring utilize native OS Keyring mechanisms (Keychain on macOS, SecretService on Linux) and are never logged, serialized into JSON reports, or committed.

100% Offline Capability: With --no-llm, Autotune runs entirely locally using AST heuristics and genetic algorithms with zero network calls.

Non-Destructive: autotune apply outputs to .autotune/artifacts/ or custom directories; original source files are never altered.

📄 License & Citations

Autotune is distributed under the Apache 2.0 License. See LICENSE for details.

If you use Autotune in your research or production systems, please cite:

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →