XSI build rung (from zero)
This page explains the RTL rung used when Vitis cosim is not the right execution path (notably free-running ap_ctrl_none task-network tops).
Terms first
| Term | Plain meaning |
|---|---|
| RTL / Verilog | Synthesized hardware description (*.v) from csynth_design, evaluated cycle-by-cycle by a simulator. |
| xsim | Vivado’s RTL simulator engine. |
| xvlog | Vivado Verilog compiler (xvlog compiles Verilog sources for xsim). |
| xelab | Vivado elaboration/link step; xelab -dll emits a simulator DLL you can load from C/C++. |
| XSI | Xilinx Simulator Interface: C/C++ API to drive an xsim DLL (put_value, run, get_value). |
| BFM | Bus Functional Model: testbench code that behaves like external bus peers (memory and streams) cycle-by-cycle. |
.f file |
Text manifest listing Verilog files; passed to xvlog -f <manifest>. |
End-to-end flow
For this rung, the flow is:
csynth -> Verilog -> xvlog -> xelab -dll -> BFM via XSI -> compare against golden
Concretely:
csynth_designgeneratessolution1/syn/verilog/*.v.- An
.fmanifest (for examplertl_interleaver_canon.f) lists those.vfiles. xvlog -f rtl_<top>.fcompiles the RTL.xelab work.<top> -dll -s <top>elaborates and emits a loadable simulator DLL.- A C++ BFM executable loads that DLL via XSI and drives AXI-MM + AXI-Stream pins cycle-by-cycle.
- The BFM compares DUT outputs with the golden model.
Supplied vs generated vs authored
| artifact | who makes it | authoring reality |
|---|---|---|
solution1/syn/verilog/*.v |
Vitis csynth | Fully generated; do not hand-edit. |
rtl_<top>.f |
you today (future step later) | Mostly listing generated .v paths. |
xsi_loader.*, xsi_shared_lib.h, run.bat / run.sh |
framework (waveflow/build/xsi/) |
Copied into each workspace by the build; do not hand-edit. |
*_bfm_tb.cpp |
generated, or you | Generated from the testbench graph when the TB is declared as a component graph (mem_copy); hand-assembled for the interleaver tops. Either way it composes framework bus models — it contains no per-cycle handshake code. |
The bus models themselves (AxisMaster, AxiMmReadSlave, …) are framework code in
waveflow/build/xsi/xsi_bfm.h, and scenario data crosses as burst bundles written by Python. See
BFM Testbenches.
Practical Windows/run-script notes
From examples/interleaver/xsi/run.bat:
- With no verb the script runs
xvlog, thenxelab -dll, theng++, then executes the BFM EXE; a verb selects phases (see Building once, running many times). PATHmust include Vivadobin, xsim DLL locations, and MinGW toolchain paths.- Use Windows invocation conventions (for example
.\run.bat <top> <tb_basename>). - If running from MSYS/Git Bash, set
MSYS_NO_PATHCONV=1to avoid path rewriting surprises.
Codegen vs build/execution responsibilities
- Codegen responsibility: produce the top/kernel sources and port shape (see schema HLS codegen and related build codegen pages).
- Build/execution responsibility (this page): compile generated RTL and execute it in simulation (
xvlog/xelab/XSI/BFM).
Codegen defines what gets built; this rung defines how that RTL is executed and checked.
Building once, running many times
An XSI run is four phases: compile the RTL (xvlog), elaborate it into a design library (xelab
-dll), compile the testbench (g++), and simulate. On the examples the first three take 20–30 s
together and the simulation a fraction of a second — so re-running a design that has not changed
should cost only the last one. Three pieces make it so.
The runner takes a verb. run.bat / run.sh accept, in any order after the top and testbench
names, trace, one of the verbs below, and a vectors directory:
| verb | phases |
|---|---|
rtl |
compile the RTL and elaborate the snapshot |
tb |
compile and link the testbench |
build |
rtl + tb |
run |
run the testbench that is built, against the snapshot that is elaborated |
all (or none) |
every phase, unconditionally — what the -m xsi gates use |
.\run.bat mem_copy mem_copy_bfm_tb build
.\run.bat mem_copy mem_copy_bfm_tb run runs\p3
Each phase deletes its own outputs before it rebuilds them, so a failed phase cannot leave an older
artifact behind. With trace, the design is elaborated with the VCD dumper as a second top into
its own snapshot, xsim.dir/<top>_trace, so a traced and an untraced build coexist. Every run of
the traced snapshot writes <top>_trace.vcd; a run of the untraced one never does.
XsiSnapshot decides what to rebuild. The runner never decides whether a phase is needed;
waveflow.build.xsi_snapshot.XsiSnapshot
does, by content:
from waveflow.build.xsi_snapshot import XsiSnapshot
snap = XsiSnapshot(xsi_dir, top="mem_copy", tb="mem_copy_bfm_tb")
snap.stale() # ["rtl", "tb"], a subset, or [] -- what a build would run
snap.build() # runs only the stale phases; returns them
out = snap.run(vectors_dir=xsi_dir / "runs" / "p3") # build (incrementally), then run
After a phase succeeds it writes a stamp: a SHA-256 of every input the phase read. For the design,
that is the runner script, rtl_<top>.f, every file it lists and every file of each --include
directory (and, traced, the dumper). For the testbench, it is the runner, <tb>.cpp,
xsi_loader.cpp, every quoted #include they reach, and WF_TB_CXXFLAGS. A phase is skipped only
when its stamp matches and its output exists. Timestamps are not used: a regenerated file with
identical bytes is still fresh, and an edit that is undone is fresh again.
The design’s stamp lives inside xsim.dir/<snapshot>/, so deleting the snapshot — which the gates
do to force a clean build — deletes its stamp too. RtlSimStep,
XsiWorkspace (and with it system_xsi), and the vendor-block RTL runners all
go through XsiSnapshot.
A run reads its scenario from a directory you choose. Testbenches name their bundles
vectors/<port>. With a vectors directory — the runner’s last argument, or run(vectors_dir=...)
— the BFM library reads and writes those bundles there instead (WF_VECTORS_DIR, resolved in
xsi_bundle.h), and puts the run’s waveform database there too. So two runs of one snapshot do not
overwrite each other’s outputs, and they can run in parallel: build once, then call
run(d, build=False) from several threads. Eight parallel mem_copy runs took 0.27 s in total, and
each wrote outputs byte-identical to a single run’s.
A scenario’s sizes are part of the scenario too. The cycle bound of the generated main and the
size of a memory arena are compiled into the testbench as defaults, and a run’s vectors/run.json
overrides them (wfbfm::run_param; written by waveflow.utils.burst_io.write_run_params). A run
that overrides one prints WF_RUN_PARAM <key>=<value>. This is what lets one compiled testbench
serve every workload: mem_copy’s workload sweep
runs fifty job lengths at RTL in 36 s, each point checked bit-exact, at about 0.5 s a point
(0.3 s of it simulating) — against 20–30 s a point when every run rebuilt everything.
A run reads whatever
run.jsonits vectors directory holds. A scenario writer that owns avectors/should therefore write one every time, even at the default scenario, so a previous point’s sizes cannot outlive it —MemCopySim.write_scenariodoes.
A plain SystemVerilog testbench: SvSimStep
The same three tools also run a hand-written SystemVerilog testbench with no HLS and no XSI
involved: xvlog compiles the design and the testbench, xelab elaborates the testbench as the top,
and xsim runs it to completion. SvSimStep (waveflow/build/svsim_steps.py) is that run as a
build step. It is a thin wrapper over run_sv_sim (waveflow/scripts/sv_sim.py, also the sv_sim
command line).
from pathlib import Path
from waveflow.build.svsim_steps import SvSimStep
dag.add(SourceStep(artifact="adder_src", path="adder.sv"))
dag.add(SourceStep(artifact="adder_tb", path="tb_adder.sv"))
dag.add(SvSimStep(name="adder_sim", sources=["adder.sv"], tb="tb_adder.sv",
consumes=["adder_src", "adder_tb", "vectors"],
sim_artifact="adder_sim_dir", sim_dir=Path("sim/adder"),
outputs={"adder_results": Path("sim/adder/results.txt")},
plusargs={"vectors": Path("vectors/in.txt")}))
| Parameter | Meaning |
|---|---|
sources, tb |
design sources and the testbench file, relative to config.root_dir or absolute |
consumes |
per instance: the SourceSteps of the .sv files plus whatever wrote the testbench’s inputs |
sim_artifact, sim_dir |
the simulation directory, the step’s one guaranteed artifact |
outputs |
files the testbench itself writes. They join produces, so freshness is judged on data the simulation produced, and a run that died before writing them fails the step rather than leaving a stale sim_dir that looks fresh |
plusargs |
-testplusarg name=value. A Path value is resolved against config.root_dir, so the testbench gets an absolute path to its vectors |
top, tcl, keep, capture_output |
the top module (default: the testbench’s stem), an xsim run.tcl (default --runall), keep the old sim_dir, capture tool output into the error |
A tool failure raises SvSimError and the DAG records a failed step with its traceback. No reference
example uses this rung yet; tests/build/test_svsim_steps.py pins the commands it builds.
See also
- Build System index — one flow, fork at the RTL rung.
- BFM Testbenches — the bus models, the five-phase lifecycle, and how a TB is assembled.
- schema HLS codegen — generating the C++/HLS side consumed by build steps.