xilinx/ross-ai-assistant/hls-matlab-to-cpp
Claude Code and agent skill by xilinx/ross-ai-assistant
- community
Checking that the SKILL.md file is still in the repository.
Convert MATLAB sample-based code to plain C++ frame-based loops — analyze algorithm, generate C++ that compiles with g++, verify against MATLAB golden, then hand off to /hls-architect for HLS dataflow architecture.
Install
npx vskill@latest install xilinx/ross-ai-assistant/hls-matlab-to-cppSKILL.md
MATLAB to C++ Conversion
Convert MATLAB sample-based algorithms into frame-based plain C++ that compiles with g++, then hand off to /hls-architect for multi-stage HLS dataflow architecture.
Preamble — Verify Tooling + Capture Required Parameters
Step 0 — Run ./reference/setup.md in tooling-only mode
All required tooling (Vitis HLS, MATLAB, OpenCV) is verified by the ./reference/setup.md skill. At this point in the flow there is no design directory yet, so call ./reference/setup.md with mode=tooling-only — design discovery and build commands (Steps 2 & 3 of ./reference/setup.md) are skipped.
The ./reference/setup.md skill will:
- Source Vitis (and export
$XILINX_VITIS) — Step 1 - Detect & verify OpenCV install if the testbench will use
cv::imread— Step 4 - Locate MATLAB and export
$MATLAB_BIN— Step 5
If ./reference/setup.md cannot resolve a tool (e.g. MATLAB not on PATH, OpenCV lib path missing), it prompts the user with AskUserQuestion. Do not proceed until `./reference/setup.md` reports all three checks passed (or marked N/A).
After ./reference/setup.md returns, the following env vars are guaranteed to be set:
| Env var | Set by | Used by | |
|---|---|---|---|
$XILINX_VITIS | ./reference/setup.md Step 1 | g++ compile commands in Step 2 & Step 4 | |
$OPENCV_INCLUDE | ./reference/setup.md Step 4 | g++ -I flag for testbench compile | |
$OPENCV_LIB | ./reference/setup.md Step 4 | g++ -L flag for testbench compile | |
$MATLAB_BIN | ./reference/setup.md Step 5 | Step 0 — running the user's .m files |
Downstream skills (/hls-architect, /hls-optimize, /csim, /csynth, /cosim) inherit this environment — never re-verify or re-source.
Capture pipeline parameters
Parse parameters from $ARGUMENTS:
Expected format:
Examples:
Parse logic:
- Extract MATLAB file path (first non-key=value argument)
- Extract
part=...→ store asXPART - Extract
clock=...→ store asCLOCK_NS - Extract
throughput=...→ store asTHROUGHPUT_TARGET
No silent defaults. If any of <matlab-file>, part=, clock=, or throughput= is missing from $ARGUMENTS, prompt the user with AskUserQuestion:
| Missing arg | Question header | Question text | |
|---|---|---|---|
| matlab file | "MATLAB script" | "Which MATLAB script should I convert? (path to .m file)" | |
part= | "FPGA part" | "FPGA part to target? (e.g. xczu9eg-ffvb1156-2-e)" | |
clock= | "Clock period" | "Clock period in ns? (e.g. 3.3 for ~303 MHz)" | |
throughput= | "Throughput" | "Throughput target? (e.g. 4400 FPS, 500 Msps, 1 GFLOPS)" |
Why no defaults: silent defaults (xczu9eg, 3.5 ns) used to mask user typos and propagate the wrong values into /hls-architect and /hls-optimize. The prompt forces an explicit choice and surfaces parsing failures immediately.
After all four are resolved, print confirmation:
Flow Overview
Print this at the very start so the user can track progress throughout:
Re-print this overview after each step completes with a ✓ next to the completed step so the user always knows where the flow is.
Design Workspace
Before running Step 0, derive design_name from the MATLAB script filename (snake_case, no .m extension).
Call ./reference/design-layout.md to orient the workspace:
This prints the full expected directory tree without creating anything. Confirm the tree with the user, then proceed — each step calls ./reference/design-layout.md to create its directory before writing files.
Step 0 / 4 — Run MATLAB Simulation (Golden Reference)
Before converting anything, run the MATLAB simulation to capture golden inputs and outputs. These are used in Step 2 to verify the generated C++.
Launch MATLAB CLI
Use $MATLAB_BIN — exported by ./reference/setup.md Step 5. Do NOT hardcode a path here; that breaks for any user other than the one whose path was baked in.
If $MATLAB_BIN is empty at this point, ./reference/setup.md mode=tooling-only was not run (or it failed) — go back and re-run it before continuing.
Run the Simulation
Once the MATLAB CLI is open, run the *_runme.m script in the design directory:
Important:
- Run only the simulation section — do not run any MtoHDL Coder or code generation sections
- If the runme script contains both, stop before the HDL/HLS coder calls
Save Inputs and Outputs
Save both the input data (stimulus) and output data (golden reference) so the C++ testbench can use the same files:
Keep note of: output dimensions, data type, and border pixels that are undefined (e.g., warmup edges for filter kernels).
Write to golden/
Call ./reference/design-layout.md design_name=<name> stage=golden
Then copy into design_name/golden/:
- All MATLAB source files (
*.m) from the input design path matlab_input.bin— saved stimulusmatlab_golden.bin— saved golden reference output
Print before proceeding:
Step 0b — Range Instrumentation
Capture min/max of every intermediate variable from the MATLAB simulation. This drives exact-bitwidth type selection in Step 2 — tight widths reduce area and improve achievable II. Without this, type selection falls back to conservative static analysis.
0. Detect design type
Examine the design directory:
- Type A — script-based: the top-level runme calls no sub-function
.mfiles; all computation is inline. The MATLABwhocommand can see all variables after the script runs. - Type B — function-based: the design has multiple
.mfiles that start with thefunctionkeyword. Sub-function internals are invisible towho— only the function's return values appear in the caller's workspace. These require per-function instrumentation.
Detection rule: scan the design directory for .m files. If more than one file begins with function (excluding the runme/tb scripts), it is Type B.
1. Generate instrumented MATLAB files
Type A — append snippet to runme
Add this block to the end of the *_runme.m script, after the main algorithm has already executed. Do not modify the algorithm itself.
Type B — auto-generate instrumented sub-functions
Use the two scripts shipped with this repo under ./hls-scripts/:
Both gen_all_instr.py and gen_matlab_instr.py ship with the repo — no external download required.
Step 1: Generate `*_instr.m` for every sub-function:
This scans the design directory, finds all files starting with function, skips *_instr, *_runme, *_tb, *_range, *_init, and generates <name>_instr.m for each. The prefix embedded in every RANGE line equals the filename stem (e.g., hb2_fir_i.m → prefix hb2_fir_i).
Print the summary output from gen_all_instr.py — it lists every generated file and its tracked variable count.
Step 2: Create or update an instrumented runner.
Create <design_name>_full_instr_runme.m in the design directory that:
- Calls
clear functionsat the top to reset all persistent variables - Calls the
*_instrversions of every sub-function (not the originals) - Uses the same stimulus and parameters as the original runme
- Prints any top-level coefficient/LUT ranges directly via
fprintf('RANGE ...')before the pipeline loop
The RANGE lines are emitted by each *_instr.m function automatically at the end of their execution — no additional snippet is needed in the runner.
Note on loop-internal constants:gen_all_instr.pytracks ALL named assignments inside the outer loop, including constants likebit_start = 21oroffset = fi(1025,...). These will appear in the RANGE output with trivial ranges (e.g.,[21,21]). Ignore them when building the type table — they are not signal-path variables.
Note on output_direct temps: assignments likecout(i) = expr_with_no_named_intermediateare captured via injected temp variables namedrng_<array>_N. These appear asRANGE prefix_rng_<array>_Nand represent the actual output signal value — keep them in the type table.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hls-matlab-to-cpp/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/xilinx/ross-ai-assistant/hls-matlab-to-cpp)