Simulating at RTL
The second simulation runs the hardware: the Verilog of the DUT, cycle by cycle, in Vivado’s simulator, with everything around it as C++ models that speak its pins. It is slower than pysim and holds less, and it answers the question pysim cannot: does the hardware do what the Python does.
The system: HwSystem(sim, dut)
An RTL simulation starts from an HwSystem: a Simulation with one module named the DUT. The
testbench is everything else, derived, never listed. Build the modules on one simulation, wire them,
and name the DUT:
from waveflow.simulation.simulation import Simulation
from waveflow.hw.clock import Clock
from waveflow.hw.hw_system import DutTop, HwSystem # the system and its DUT
from waveflow.hw.mm_device import build_mm_device # a kernel's memory-mapped device
from waveflow.hw.memif import AXIMMCrossBarIF # the crossbar
from examples.stream_kernel.stream_kernel import PolyKernel, W # the example's kernel
from examples.stream_kernel.stream_kernel_mm import PolyHost # the example's host
clk = Clock(freq=100e6)
sim = Simulation()
kernel = PolyKernel(name="poly_kernel", sim=sim, clk=clk)
host = PolyHost(name="host", sim=sim, cmds=cmds, clk=clk) # the testbench: a SwHost
device = build_mm_device(kernel, sim=sim, clk=clk, mem_dwidth=W) # the kernel's views and front
xbar = AXIMMCrossBarIF(name="xbar", sim=sim, clk=clk, nports_master=1, nports_slave=len(slaves), ...)
... # bind, address map, interrupts
dut = DutTop.of("poly_mm_dut", sim, comps=[device], ifs=[xbar])
sysm = HwSystem(sim, dut, run_until=host.done, check=check)
This is shortened: the whole of it, with the bindings, the address map and the interrupts, is mm_system in stream_kernel_mm.py, walked on The polynomial on a bus. For one module the
whole of it is one line, because the testbench is generated: harness(PolyKernel, workload="test").
The constructor checks the rules, each a refusal that names what to fix:
- the DUT is a root of this simulation;
- every testbench part has an RTL twin – a stream driver’s
AxisMaster, a sink’sAxisSlave, a memory model, a host’s C++ program (BFM testbenches); - no DUT port is left unbound.
The second rule is the line between the two simulations: anything can join a Simulation; only what
has an RTL twin can join an HwSystem. A wireless channel model has no twin, so a study with one is a
pysim study, and its RTL simulation draws the DUT and testbench where everything has one.
The details – every argument, participants(), cut() – are in
The system: HwSystem.
What becomes what
Read it from the outside in:
- The system (dotted) is everything simulated together: an
HwSystem, a simulation plus one named DUT. It is flat – a testbench and a DUT, nothing nested. - The testbench is everything outside the DUT, derived, never listed: here the host, a
SwHostwhose threads are Python in pysim and a C++ twin at RTL. In a smaller system it is stream drivers and sinks. - The DUT (solid) is what is synthesized: a tree of modules – here three devices and the crossbar between them.
- A device (dashed) is a kernel with everything that belongs to it – its memory-mapped views and front, the bus writers that act for it – one IP when the system is packaged.
- A module is a
HwModule: typed ports and a behavior. A kernel is a free-running module whose behavior is a Pythonrun_iterand, at RTL, an HLS body. - The interfaces between modules are typed connections – streams, credit streams, AXI-MM, BRAM, interrupts (Interfaces).
- The messages on them are schemas: the fields once, in Python, and every word packed by generated code.
| colour | what it is | how it becomes RTL |
|---|---|---|
| blue | kernels, and the bus writers a routed stream brings | an HLS body, synthesized by Vitis (csynth) |
| green | memory-mapped fronts and views, memories | framework Verilog, as is (system_rtl) |
| purple | the crossbar | AMD’s axi_crossbar, generated from the pysim address map |
| tan | the testbench | C++ models, never synthesized (system_xsi) |
The Verilog is derived, never written: the build walks the DUT to a SystemTopSpec – every instance,
crossbar slot, stream net and port – and renders the top from it, a sub-top per device
(The system top).
A module’s HLS body
Each kernel’s hardware is its HLS body – the second copy of the kernel, written to read as run_iter
does, and named by kernel_task() (Defining the kernel in Python and HLS).
The generator writes the top around it – for the polynomial three axis ports, ap_ctrl_none, one
hls::task – and its csynth script; nothing about the top is hand-written.
A body that names no word type (KernelTask(..., framed=ports), streamutils::read_msg / write_msg,
the lane routines’ read_boundary_lane) serves the module alone and inside a composite, so each stage
of a pipeline is synthesized once and run at RTL in its own harness and in the whole
(One body, wherever it sits). Before shaping any loop:
Design patterns for loop optimization.
The system flow
One call puts the RTL simulation on a build DAG, after the example’s own codegen (its headers, lane
routines, tops and bodies):
from waveflow.build.build import BuildDag
from waveflow.build.cli import run_dag_cli
from waveflow.build.system_dag import add_system_steps
from waveflow.hw.harness import harness
from examples.stream_kernel.stream_kernel import PolyKernel
from examples.stream_kernel.stream_kernel_build import StreamKernelCodegenStep # the example's codegen
dag = BuildDag()
dag.add(StreamKernelCodegenStep(name="codegen"))
add_system_steps(dag, harness(PolyKernel, workload="test"), work_dir="xsi_work", top="stream_kernel_top")
run_dag_cli(lambda: dag, description="...", default_through="compare", root_dir=HERE)
| step | what it does |
|---|---|
csynth |
Vitis HLS, once per top; fresh while its sources are unchanged |
system_rtl |
the crossbar IP if there is a bus, then the Verilog top derived from the DUT |
scenario |
what the testbench plays, written once, and the run’s cycle bound |
pysim |
the system in Python, from that scenario |
system_xsi |
the RTL under XSI with the testbench’s C++ twins, from the same scenario |
compare |
what the testbench recorded, RTL against pysim, word for word |
run_dag_cli gives every example script --through <step>, --status, --force, and an exit status
that is 1 when a step fails. A build that changed nothing does no work: every step is fresh while what it
reads is unchanged (freshness). csynth targets a Zynq-7020 at
100 MHz unless a top’s script names a part and clock (render_tcl(top, part=..., period_ns=...)).
What compare proves, and what it does not, is the next page.
A ladder of systems
The worked examples climb from the smallest system to the full picture, each the same idea at a larger size:
| system | the DUT | the testbench | worked example |
|---|---|---|---|
| one kernel on streams | a free-running kernel | its harness: a stream driver and sinks | Free-running polynomial |
| a pipeline of kernels on streams | a composite: a broadcast and two stages, joined by internal streams | its harness; each stage alone in its own | Block equalizer |
| one kernel on a bus | the same kernel as a device, and the crossbar | a two-thread SwHost |
The polynomial on a bus |
| a pipeline with memory | a composite of free-running tasks, memory through stream adaptors | stream drivers, sinks, a memory model | memcpy, interleaver |
| several kernels, a memory, a host | devices, a memory, the crossbar | a SwHost |
Two kernels on a bus |
Steps up
A pipeline: block_eq. Four systems on one DAG: each stage in
its harness, the composite, and an error scenario – each its own add_system_steps with a prefix, all
sharing one codegen and the stages’ csynth.
A bus system: markov. markov_system(...) is an HwSystem whose DUT
is two devices, a memory and the crossbar; its host is a SwHost whose C++ twin runs the same two
threads under XSI on generated endpoints. compare checks the host’s bus traces, RTL against pysim, byte
for byte – and the run’s exact cycle count is a gate of its own (XSI system simulation).
Next: Functional verification.