AsmEvo Architecture Guide: Source-Free AMDGCN Optimization Pipeline
Learn AsmEvo's 5-stage AMDGCN pipeline: code-object recovery, hot-window editing, ABI rebuilds, differential verification, and in-place patch fallback.
Why Assembly-Level GPU Optimization Exists
High-level ML compilers (PyTorch Inductor, Triton, HIP, and LLVM AMDGPU) translate tensor operations through multiple abstraction layers before emitting AMDGCN machine instructions. Each abstraction layer hides micro-architectural realities of AMD CDNA architectures (such as MI300X and MI308X): exact global/LDS memory latency hiding, s_waitcnt barrier granularity, VGPR/SGPR register bank pressure, and wave occupancy boundaries.
AsmEvo (arXiv:2608.20711) treats the compiled AMDGPU code object (K₀)—rather than high-level source—as the primary optimization artifact. Instead of guessing how a compiler change might propagate down to assembly, AsmEvo edits the recovered AMDGCN instructions directly and gates every candidate against the original binary.
Stage-by-Stage AsmEvo Pipeline Architecture
Stage 1: Code-Object Recovery (K₀ → Reassemblable AMDGCN)
Compiled AMD GPU kernels are packaged inside ELF/HSACO code objects containing machine code, symbol tables, and kernel descriptors (which specify VGPR/SGPR counts, LDS allocation, and argument offsets). AsmEvo disassembles K₀ into a structured, reassemblable AMDGCN representation that preserves label targets, metadata sections, and calling conventions so edits can be assembled cleanly back into an executable binary.
Stage 2: Profiling-Guided Hot-Window Editing
Asking an LLM to rewrite an entire multi-thousand-line GPU assembly listing causes context drift and frequent syntax or semantic regressions. AsmEvo first profiles the unmodified kernel under realistic launches to isolate hot code windows—inner loops and stall-heavy instruction blocks responsible for the bulk of execution cycles. A long-horizon agent focuses edits exclusively on those windows, targeting:
- Wait-counter placement (
s_waitcnt): Separating memory loads from dependent ALU instructions so wavefronts stay active during global or LDS fetches. - Instruction selection & dual-issue scheduling: Replacing redundant address calculations or interleaving VALU, SALU, and MFMA instructions.
- Register pressure & occupancy tuning: Trimming live-range overlaps to cut VGPR spills or step across hardware occupancy thresholds.
Stage 3: Metadata-Aware ABI-Preserving Rebuilding
Modifying register usage or instruction counts changes the binary layout and sometimes requires updating the AMDGPU kernel descriptor metadata. AsmEvo rebuilds the candidate object K' with metadata awareness so the host launcher ABI (argument buffer offsets, grid/block semantics, and symbol bindings) stays intact.
Stage 4: Differential Verification & Correctness-Gated Timing
Raw assembly edits are unforgiving: a single misplaced s_waitcnt or clobbered register can make a kernel finish faster purely because it skipped computation or corrupted memory. AsmEvo enforces a differential verification gate:
- Capture exact input buffers and launch parameters from identical GPU launches.
- Execute both the untouched original binary
K₀and candidateK'. - Compare full output tensors and memory states for functional equivalence.
- Measure wall-clock kernel timing only for candidates that pass differential verification.
Stage 5: Conservative In-Place Patch Fallback
Certain production binaries carry strict structural constraints or layout assumptions that resist full code-object rebuilding. When a full rebuild is blocked, AsmEvo falls back to conservative in-place binary patching, applying verified local instruction replacements while keeping surrounding binary offsets untouched.
Summary of Pipeline Components & Failure Modes Prevented
| Pipeline Stage | Primary Mechanism | Failure Mode Prevented |
|---|---|---|
| Code-Object Recovery | Disassembly + metadata extraction from HSACO/ELF | Broken branch labels or lost kernel descriptors |
| Hot-Window Profiling | Runtime cycle/stall localization | Agent wasting edits on cold setup/epilogue code |
| Metadata-Aware Rebuild | ABI-preserving reassembly of K' |
Host launcher crashes or mismatched kernel args |
| Differential Verification | Output comparison vs. K₀ on identical launches |
Silent math bugs, race conditions, memory corruption |
| In-Place Patch Fallback | Local binary patching when rebuild fails | Hard failure on rigid closed production binaries |
Next Steps
Model how each pipeline stage affects projected latency on the Interactive Speedup Explorer, inspect the complete MI308X & MI300X Benchmarks, or review hands-on ROCm and AMDGCN checklists in Engineering Tips.