Skip to content

AgRefactor: Self-Evolving Agentic Workflow for HLS Compatibility and Performance

🕒 Published (v1): 2026-06-29 22:02 UTC · Source: Arxiv · link

Why this paper was selected

Jason Cong (UCLA, ACM/IEEE Fellow, EDA giant); self-evolving agentic workflow for HLS

Ask a follow-up

Open an assistant pre-loaded with this paper's context.

💬 Ask ChatGPT✦ Ask Claude

TL;DR

AgRefactor is a self-evolving multi-agent workflow that automatically refactors real-world C/C++ software into synthesizable High-Level Synthesis (HLS) code. It combines a specialized long-term memory system (accumulating factual and strategic knowledge across tasks) with hybrid LLM + algorithmic tool execution. On 9/11 challenging benchmarks (programs 5–10× larger than prior work), it outperforms or matches state-of-the-art automated and LLM-based refactoring approaches.

Problem

Converting real-world software into HLS-synthesizable code is labor-intensive: domain experts may spend days on a single project. Existing automated (rule-based) tools lack generalizability—they fail on external libraries, nested pointer arithmetic, and complex structs. Pure LLM-based workflows require manual RAG curation, exhibit high output variance, and are computationally expensive at scale. Neither class of approach addresses structural refactoring (the most hardware-performance-critical step), and both break down on programs longer than a few hundred lines.

Method

AgRefactor is a pipeline of specialized agents orchestrated via the AG2 framework:

  1. Test Generator produces testbenches and interface contracts before any refactoring, propagating these constraints downstream.
  2. Parallel Identifiers (6 category-specific agents: recursion, runtime VLAs, system calls, dynamic memory, pointers, others) detect non-synthesizable constructs; an Items Organizer deduplicates their findings.
  3. Planner produces a structured refactoring plan, augmented by two long-term memory banks:
  4. Factual memory: stores (program, identified items, refactoring strategy, generalized critique) tuples from past tasks.
  5. Strategic memory: stores plans from successful trials.
  6. Retrieval uses a hybrid distance metric: \(d(q, p) = \alpha |e^c_q - e^c_p|_2 + (1-\alpha)|e^i_q - e^i_p|_2\) combining raw code embeddings \(e^c\) and identified-item embeddings \(e^i\) (\(\alpha = 0.6\)).
  7. Tool Specialist + HeteroRefactor integration: the system greedily attempts the automated tool first (<5 s); on failure, the Tool Specialist rewrites just the constructs blocking the tool, then re-runs it—avoiding full LLM generation.
  8. Refactor Worker applies the plan; an Analyzer-Fixer loop iterates on synthesis/simulation errors (max 3 retries).
  9. Performance Optimization Agent: operates in a CLI environment with access to Vitis HLS, LightningSim (fast latency estimation), and source-to-source transformation tools (SoDA, Prometheus, StreamHLS). It follows a three-phase hierarchy (structural rewrites → critical-path analysis → pragma tuning) and maintains a tree-based working memory where nodes are synthesized code versions linked by condensed strategy summaries. Programmatic monitors track context-window size and trigger periodic tree updates to prevent context degradation and performance stagnation.

Memory entries are stored in ChromaDB; embeddings computed via all-MiniLM-L6-v2.

Key Contributions

  • End-to-end automated pipeline from C/C++ software to synthesizable, performance-optimized HLS code, targeting structural refactoring (not just pragma insertion).
  • Self-evolving agentic memory with a task-specific hybrid distance metric; automatically rejects critiques containing program-specific identifiers to ensure generalizability.
  • Hybrid LLM/tool execution: agents invoke HeteroRefactor as a callable backend, reducing LLM invocation to only what the tool cannot handle.
  • Tree-based working memory for long-running optimization agent, with programmatic monitors for context-window management and stagnation detection.
  • Comprehensive benchmark suite of 45 real-world kernels (up to 1,266 LoC) from image codecs, cryptography, and computational genomics.

Results

  • Compatibility (refactoring): AgRefactor outperforms or matches HeteroRefactor and HLSRewriter on 9/11 benchmarks (run 20Ă— each); HeteroRefactor scores 0 on 8/11 of these harder cases.
  • Memory ablation (GPT-5-mini): memory-enabled workflow outperforms no-memory baseline on 10/11 benchmarks (82% winning, 0% losing).
  • Memory ablation (GPT-5): outperforms or matches no-memory on 4/6 benchmarks (67% winning, 10% draw).
  • Performance optimization: 6.51Ă— geometric mean latency speedup over AutoDSE (SoTA pragma tuning tool); 1.20Ă— speedup over optimized open-source HLS designs at <20% extra resource overhead.
  • Memory augmentation also reduces inner-loop fix retries on benchmarks like ahocorasick, dfs, and wordbreak.
  • On av1_compound_type_rd (>1,000 LoC), both baseline and AgRefactor succeed rarely (0–1/20), indicating distribution shift limits memory transfer for very large programs.

Limitations

  • Memory retrieval introduces marginal noise on benchmarks where a static knowledge source (e.g., the Vitis HLS manual) already provides sufficient coverage (median_cut, argon2_fill_segment).
  • Large programs (>1,000 LoC) exhibit significant distribution shift from training memory, limiting knowledge transfer.
  • Evaluation uses GPT-5 family only; generalization to other LLM backends is untested.
  • Inner fixing loop is capped at 3 retries; complex bugs requiring deeper iteration cannot be resolved.
  • The original HLSRewriter baseline comparison is approximate (reproduced, not faithful, due to closed-source components and Catapult-specific toolchain).

Relevance to Harnesses / Meta-Harnesses

AgRefactor is a concrete instantiation of a domain-specialized meta-harness: it orchestrates heterogeneous agents (Identifiers, Planner, Refactor Worker, Analyzer-Fixer, Tool Specialist, Optimization Agent) via a programmatic outer loop, with tool calls, memory retrieval, and retry logic managed by the harness rather than any individual agent. The self-evolving memory system—where the harness accumulates cross-task experience and injects it into agent contexts—demonstrates how a meta-harness can improve over time without human intervention. The programmatic monitors for context-window management and stagnation redirection in the optimization agent are a reusable meta-harness pattern for sustaining long-running agentic loops. This work is directly relevant for researchers studying how harnesses can integrate heterogeneous tool backends, manage agent context degradation, and implement adaptive knowledge retrieval to improve multi-step code transformation pipelines.