vhls-opt — Vitis HLS Command Runner & Optimizer
This skill has two modes: Run (command execution) and Opt (code optimization analysis).
Mode 1: Run — HLS Command Execution
Convert shorthand into Vitis HLS commands and execute them.
Environment Detection
Before the first execution in a conversation, verify the environment is set up:
- Use the Bash tool to run:
which vitis 2>/dev/null && vitis --version 2>&1 | head -5
- If
vitis is NOT found, ask the user to set up their Vitis environment first (e.g., source <Vitis_install_path>/settings64.sh) and retry.
- If
vitis IS found, proceed directly.
Cache the result: skip this check on subsequent invocations in the same conversation.
Shorthand Grammar
run <ACTION> <CONFIG_FILE> <WORK_DIR>
<ACTION> : csim | csynth | cosim | pack | impl
<CONFIG_FILE> : required, must end with .cfg
<WORK_DIR> : required
- Both paths are relative to the current working directory unless absolute.
Command Templates
| Action |
Command |
| csynth |
v++ -c --mode hls --config <CFG> --work_dir <DIR> |
| csim |
vitis-run --mode hls --csim --config <CFG> --work_dir <DIR> |
| cosim |
vitis-run --mode hls --cosim --config <CFG> --work_dir <DIR> |
| pack |
vitis-run --mode hls --package --config <CFG> --work_dir <DIR> |
| impl |
vitis-run --mode hls --impl --config <CFG> --work_dir <DIR> |
Execution Rules
All arguments present and validated:
- Verify
<CONFIG_FILE> exists using the Read tool or Bash test -f. If missing, stop and tell the user.
- Verify
<WORK_DIR> exists (or can be created). If it does not exist, create it with mkdir -p.
- Show the user the exact command that will be executed.
- Execute it using the Bash tool. For long-running actions (
csynth, cosim, impl), set timeout to 600000 (10 minutes).
- After execution, report the result:
- Success: Print "Completed successfully." and show the last 20 lines of output.
- Failure: Print the full stderr/stdout and highlight the error. If a log file exists in
<WORK_DIR>, read the tail of the log for additional context.
- For
csynth: after success, automatically read and display key metrics from <WORK_DIR>/<component>/syn/report/csynth.rpt (or the first csynth.rpt found under <WORK_DIR>) — specifically the Performance Estimates and Utilization Estimates sections.
Missing <CONFIG_FILE>: State it is required, explain that the HLS config file (.cfg) contains the component source files, top function, clock period, and device target. Ask the user to provide it.
Missing <WORK_DIR> only: Ask the user for it.
Multiple actions: The user may chain actions (e.g., run csim csynth cosim config.cfg workdir). Execute them sequentially in the given order, stopping on the first failure.
Post-Run Reporting
After any successful action, check for and report:
- Warnings count from the output
- For
csynth: latency, II, clock period, and resource utilization from csynth.rpt
- For
cosim: pass/fail status from cosim output
- For
impl: timing (WNS/TNS) and utilization from implementation reports
Mode 2: Opt — HLS Code Optimization Analysis
Analyze HLS code and provide optimization directions with feasibility assessment. Optimizations are applied iteratively — one group at a time — with cosim verification after each round.
Required Inputs
- Optimization goals (throughput / latency / II / fmax / resources)
- Current constraints (target device / memory / interfaces) or
.cfg file
<CONFIG_FILE> and <WORK_DIR> — needed to run csynth/cosim during iterations
- Code (snippet or file)
If the user provides a <WORK_DIR>, automatically read:
- The
.cfg file for constraints (clock, part, top function)
- Source files referenced in the
.cfg
<WORK_DIR>/<component>/syn/report/csynth.rpt for current metrics
Step 0: Baseline (run when user asks for baseline, or before first optimization)
Before any optimization, establish a baseline:
- Run
csynth using the command template from Mode 1.
- Find and read the synthesis report: use Glob
<WORK_DIR>/**/csynth.rpt to locate it.
- Extract and display a Baseline Report with:
- Target clock period and estimated clock (fmax)
- Latency (min/max, in cycles and absolute time)
- Initiation Interval (II)
- Resource utilization (BRAM, DSP, FF, LUT) — counts and percentages
- Any timing or resource warnings
- Save these numbers internally as the baseline for comparison in later iterations.
If the user asks for "baseline" or "baseline performance", run this step and stop — do not proceed to optimization unless asked.
Workflow
- Restate goals and constraints.
- Retrieve baseline metrics (run Step 0 if no baseline exists yet).
- Analyze the code for:
- Correctness risks
- Performance bottlenecks (loop II, memory bandwidth, dependencies, interfaces)
- Pragma opportunities (pipeline, dataflow, array_partition, stream, etc.)
- Group improvements into logical categories. Typical groups:
- Loop optimization: pipeline, unroll, loop_flatten, loop_merge
- Memory optimization: array_partition, array_reshape, bind_storage
- Dataflow / streaming: dataflow, stream depth, FIFO sizing
- Interface optimization: m_axi burst, interface pragma, port widths
- Algorithmic restructuring: code refactoring, function inlining, data type changes
- Groups may vary based on the specific code and goals.
- Present all groups with rationale, expected impact, and trade-offs for each. Ask the user which group to apply first, or recommend a starting order.
Iterative Optimization Loop
Apply optimizations one group at a time. For each iteration:
- Apply the changes for the current group using the Edit tool on the source files.
- Run csynth to get updated metrics.
- Run cosim to verify functional correctness.
- Report iteration results:
- cosim pass/fail status — if FAIL, immediately revert the changes (using Edit to restore the original code) and report the failure. Do not proceed to the next group.
- Updated metrics vs. baseline and vs. previous iteration:
- Latency delta
- II delta
- fmax delta
- Resource utilization delta (BRAM, DSP, FF, LUT)
- Summary: whether this group improved, regressed, or was neutral for each metric.
- Proceed or stop:
- If cosim passed and metrics improved, confirm with the user before moving to the next group.
- If cosim passed but metrics regressed, ask the user whether to keep or revert.
- If cosim failed, revert and ask the user how to proceed.
Repeat until all groups are applied or the user is satisfied.
Output Format (per iteration)
Iteration N: <Group Name>
─────────────────────────
A) Changes Applied
- List of edits with rationale
B) csynth Results
- Latency: <new> (baseline: <old>, delta: <+/->)
- II: <new> (baseline: <old>, delta: <+/->)
- fmax: <new> (baseline: <old>, delta: <+/->)
- BRAM: <new> (baseline: <old>, delta: <+/->)
- DSP: <new> (baseline: <old>, delta: <+/->)
- FF: <new> (baseline: <old>, delta: <+/->)
- LUT: <new> (baseline: <old>, delta: <+/->)
C) cosim Result: PASS / FAIL
D) Recommendation: Keep / Revert / User decision needed
Final Summary
After all iterations, present a cumulative summary:
Optimization Summary
════════════════════
Baseline → Final
| Metric | Baseline | Final | Delta |
|---------|----------|--------|--------|
| Latency | ... | ... | ... |
| II | ... | ... | ... |
| fmax | ... | ... | ... |
| BRAM | ... | ... | ... |
| DSP | ... | ... | ... |
| FF | ... | ... | ... |
| LUT | ... | ... | ... |
Groups applied: ...
Groups reverted: ...
cosim: all PASS / N failures
1---2name: vhls-opt3description: Vitis HLS command execution and code optimization. Use when: (1) running Vitis HLS commands (csim, csynth, cosim, pack, impl) from shorthand like 'run csynth config.cfg workdir', or (2) analyzing HLS C/C++ code for optimization (throughput, latency, II, fmax, resources). Trigger on mentions of 'vhls', 'hls run', 'run csynth/csim/cosim/pack/impl', 'hls optimize', 'baseline', or HLS performance analysis requests.4---56# vhls-opt — Vitis HLS Command Runner & Optimizer78This skill has two modes: **Run** (command execution) and **Opt** (code optimization analysis).910---1112## Mode 1: Run — HLS Command Execution1314Convert shorthand into Vitis HLS commands and **execute them**.1516### Environment Detection1718Before the first execution in a conversation, verify the environment is set up:19201. Use the Bash tool to run: `which vitis 2>/dev/null && vitis --version 2>&1 | head -5`212. If `vitis` is NOT found, ask the user to set up their Vitis environment first (e.g., `source <Vitis_install_path>/settings64.sh`) and retry.223. If `vitis` IS found, proceed directly.2324Cache the result: skip this check on subsequent invocations in the same conversation.2526### Shorthand Grammar2728```29run <ACTION> <CONFIG_FILE> <WORK_DIR>30```3132- `<ACTION>` : `csim | csynth | cosim | pack | impl`33- `<CONFIG_FILE>` : required, must end with `.cfg`34- `<WORK_DIR>` : required35- Both paths are relative to the current working directory unless absolute.3637### Command Templates3839| Action | Command |40|--------|---------|41| csynth | `v++ -c --mode hls --config <CFG> --work_dir <DIR>` |42| csim | `vitis-run --mode hls --csim --config <CFG> --work_dir <DIR>` |43| cosim | `vitis-run --mode hls --cosim --config <CFG> --work_dir <DIR>` |44| pack | `vitis-run --mode hls --package --config <CFG> --work_dir <DIR>` |45| impl | `vitis-run --mode hls --impl --config <CFG> --work_dir <DIR>` |4647### Execution Rules48491. **All arguments present and validated**:50 - Verify `<CONFIG_FILE>` exists using the Read tool or Bash `test -f`. If missing, stop and tell the user.51 - Verify `<WORK_DIR>` exists (or can be created). If it does not exist, create it with `mkdir -p`.52 - Show the user the exact command that will be executed.53 - Execute it using the Bash tool. For long-running actions (`csynth`, `cosim`, `impl`), set `timeout` to 600000 (10 minutes).54 - After execution, report the result:55 - **Success**: Print "Completed successfully." and show the last 20 lines of output.56 - **Failure**: Print the full stderr/stdout and highlight the error. If a log file exists in `<WORK_DIR>`, read the tail of the log for additional context.57 - For `csynth`: after success, automatically read and display key metrics from `<WORK_DIR>/<component>/syn/report/csynth.rpt` (or the first `csynth.rpt` found under `<WORK_DIR>`) — specifically the Performance Estimates and Utilization Estimates sections.58592. **Missing `<CONFIG_FILE>`**: State it is required, explain that the HLS config file (`.cfg`) contains the component source files, top function, clock period, and device target. Ask the user to provide it.60613. **Missing `<WORK_DIR>` only**: Ask the user for it.62634. **Multiple actions**: The user may chain actions (e.g., `run csim csynth cosim config.cfg workdir`). Execute them sequentially in the given order, stopping on the first failure.6465### Post-Run Reporting6667After any successful action, check for and report:68- Warnings count from the output69- For `csynth`: latency, II, clock period, and resource utilization from `csynth.rpt`70- For `cosim`: pass/fail status from cosim output71- For `impl`: timing (WNS/TNS) and utilization from implementation reports7273---7475## Mode 2: Opt — HLS Code Optimization Analysis7677Analyze HLS code and provide optimization directions with feasibility assessment. Optimizations are applied **iteratively** — one group at a time — with cosim verification after each round.7879### Required Inputs8081- Optimization goals (throughput / latency / II / fmax / resources)82- Current constraints (target device / memory / interfaces) or `.cfg` file83- `<CONFIG_FILE>` and `<WORK_DIR>` — needed to run csynth/cosim during iterations84- Code (snippet or file)8586If the user provides a `<WORK_DIR>`, automatically read:87- The `.cfg` file for constraints (clock, part, top function)88- Source files referenced in the `.cfg`89- `<WORK_DIR>/<component>/syn/report/csynth.rpt` for current metrics9091### Step 0: Baseline (run when user asks for baseline, or before first optimization)9293Before any optimization, establish a baseline:94951. Run `csynth` using the command template from Mode 1.962. Find and read the synthesis report: use Glob `<WORK_DIR>/**/csynth.rpt` to locate it.973. Extract and display a **Baseline Report** with:98 - Target clock period and estimated clock (fmax)99 - Latency (min/max, in cycles and absolute time)100 - Initiation Interval (II)101 - Resource utilization (BRAM, DSP, FF, LUT) — counts and percentages102 - Any timing or resource warnings1034. Save these numbers internally as the baseline for comparison in later iterations.104105If the user asks for "baseline" or "baseline performance", run this step and stop — do not proceed to optimization unless asked.106107### Workflow1081091. **Restate** goals and constraints.1102. **Retrieve baseline metrics** (run Step 0 if no baseline exists yet).1113. **Analyze** the code for:112 - Correctness risks113 - Performance bottlenecks (loop II, memory bandwidth, dependencies, interfaces)114 - Pragma opportunities (pipeline, dataflow, array_partition, stream, etc.)1154. **Group improvements** into logical categories. Typical groups:116 - **Loop optimization**: pipeline, unroll, loop_flatten, loop_merge117 - **Memory optimization**: array_partition, array_reshape, bind_storage118 - **Dataflow / streaming**: dataflow, stream depth, FIFO sizing119 - **Interface optimization**: m_axi burst, interface pragma, port widths120 - **Algorithmic restructuring**: code refactoring, function inlining, data type changes121 - Groups may vary based on the specific code and goals.1225. **Present all groups** with rationale, expected impact, and trade-offs for each. Ask the user which group to apply first, or recommend a starting order.123124### Iterative Optimization Loop125126Apply optimizations **one group at a time**. For each iteration:1271281. **Apply** the changes for the current group using the Edit tool on the source files.1292. **Run csynth** to get updated metrics.1303. **Run cosim** to verify functional correctness.1314. **Report iteration results**:132 - cosim pass/fail status — if FAIL, immediately revert the changes (using Edit to restore the original code) and report the failure. Do not proceed to the next group.133 - Updated metrics vs. baseline and vs. previous iteration:134 - Latency delta135 - II delta136 - fmax delta137 - Resource utilization delta (BRAM, DSP, FF, LUT)138 - Summary: whether this group improved, regressed, or was neutral for each metric.1395. **Proceed or stop**:140 - If cosim passed and metrics improved, confirm with the user before moving to the next group.141 - If cosim passed but metrics regressed, ask the user whether to keep or revert.142 - If cosim failed, revert and ask the user how to proceed.143144Repeat until all groups are applied or the user is satisfied.145146### Output Format (per iteration)147148```149Iteration N: <Group Name>150─────────────────────────151A) Changes Applied152 - List of edits with rationale153154B) csynth Results155 - Latency: <new> (baseline: <old>, delta: <+/->)156 - II: <new> (baseline: <old>, delta: <+/->)157 - fmax: <new> (baseline: <old>, delta: <+/->)158 - BRAM: <new> (baseline: <old>, delta: <+/->)159 - DSP: <new> (baseline: <old>, delta: <+/->)160 - FF: <new> (baseline: <old>, delta: <+/->)161 - LUT: <new> (baseline: <old>, delta: <+/->)162163C) cosim Result: PASS / FAIL164165D) Recommendation: Keep / Revert / User decision needed166```167168### Final Summary169170After all iterations, present a cumulative summary:171172```173Optimization Summary174════════════════════175Baseline → Final176177| Metric | Baseline | Final | Delta |178|---------|----------|--------|--------|179| Latency | ... | ... | ... |180| II | ... | ... | ... |181| fmax | ... | ... | ... |182| BRAM | ... | ... | ... |183| DSP | ... | ... | ... |184| FF | ... | ... | ... |185| LUT | ... | ... | ... |186187Groups applied: ...188Groups reverted: ...189cosim: all PASS / N failures190```191192<p class="sphinxhide" align="center"><sub>Copyright © 2026 Advanced Micro Devices, Inc</sub></p>193<p class="sphinxhide" align="center"><sup><a href="https://www.amd.com/en/corporate/copyright">Terms and Conditions</a></sup></p>