Memory Copy — a free-running composite kernel
This is the worked example for the concurrent (free-running) flow,
the counterpart to the sequential register-map example. Where simp_fun is a single
host-launched function, mem_copy is a composite of free-running hls::tasks that copies a run of
words from one memory region to another — and it is verified not by Vitis co-simulation (which cannot
drive a free-running kernel) but by driving the real RTL cycle-by-cycle through an XSI BFM.
Beyond demonstrating composite free-running kernels, mem_copy reuses core infrastructure — the
reusable MemRStream / MemWStream adaptors and the m_axi bus — whose timing models Waveflow ships
pre-fit for supported platforms, so the loosely-timed pysim reproduces the RTL with no calibration of
its own. (Those shared models were in fact measured on mem_copy behind the scenes; that machinery
is the general calibration guide, not a step in this example — fitting a custom
component’s timing is taken up in the interleaver example.) The final page visualizes that timing.
Learning Objectives
What this adds to the examples before it – a kernel that only answered streams, alone (Free-running polynomial), in stages (Block equalizer) or behind a bus (The polynomial on a bus) – in the order the pages teach it:
- Make a kernel master memory: its reads and writes go over two
m_axibundles through the framework’sMemRStream/MemWStreamadaptors, with no memory logic of its own. - Forward each command in-band along the pipeline – one stream, each command welded to its data – so every stage knows which job it is working on.
- Put a memory model (
MemoryMod, one shared arena) in the testbench, and check the golden on the words the RTL wrote into it. - Read the generated
hls::tasktop’sm_axiports (offset=offandstable), and state the system asHwSystem(sim, dut): the kernel the DUT, the drivers and the memory the testbench. - Draw the concurrent timing of a traced RTL run on an activity diagram: the pipeline overlap and where every cycle of the period goes.
- Reuse the platform’s pre-fit timing of the
m_axibus and the memory-stream adaptors, so pysim matches the RTL’s period with no calibration of your own.
In this example
The pages build the design up from Python, parallel to the register-map example. You model it, test it in Python, generate the kernel, state the system, then run the RTL:
- Module overview — the three-stage design, the in-band forwarding protocol, and how it is wired.
- Python model — the schemas and the three
FreeRunModleaves + the composite. - Testbench (Python) — the graph (
wire_mem_copy), theMemCopySimprocedure, and running the pysim step. - DUT codegen — what an
hls::taskis, and how the design graph becomes theap_ctrl_nonetop. - The system —
mem_copy_system(), the cut, and what the system flow derives from it: the system top, the harness of BFM models, the scenario. - RTL simulation — running the system flow end to end, the RTL-vs-pysim comparison, and the golden at 3000 cycles.
- Visualizing timing — tracing an RTL run and rendering it: the pipeline overlap, the bottleneck, where every cycle of the period goes, and why the loosely-timed pysim reproduces it using the platform’s shipped infra models (no per-example calibration).
Table of contents
- Module Overview - What the module does — copy a run of words between memory regions — and why the simplest possible design is worth building: it exercises the whole free-running flow with nothing computed, so the structure is the subject rather than the maths. A data mover is also a real block: it is what a DMA engine in an SoC does.
- Python - Building the design in Python: the three FreeRunMod leaves and the composite that wires them, and how to write each kind of block. Starts from the typed schemas every stream carries — the host's CopyCmd of two offsets, a length and a transaction id, in element and word coordinates rather than byte addresses.
- Testbench (Python) - The testbench is itself a component graph, not a script that pokes the design: the DUT plus the participants around it, wired with the same Interface objects the design uses internally. That is the trick — one graph drives two backends, a fast SimPy run or a cycle-accurate RTL harness, and neither can describe a different test because there is only one description.
- DUT codegen - Lowering the three-leaf graph to a free-running Vitis HLS top. Explains what an hls::task is: a body the runtime re-fires on its own whenever its input streams have data, so there is no host handshake and the stages overlap — which is why sequence, read and write become three tasks wired by FIFOs rather than one sequential function.
- The system - The graph becomes a system: an HwSystem that states which modules are the design under test (the cut) and how to write and check a scenario. From that one object the system flow derives everything an RTL run needs -- a Verilog top with the kernel inside and a port for every connection that leaves it, a harness of C++ models answering those ports, the scenario files -- and compares what the RTL recorded with what pysim recorded.
- RTL simulation - The final rung: the system flow runs the synthesized kernel inside its system top, driven by the generated harness one clock at a time, then compares what the testbench recorded at RTL with what it recorded in pysim, word for word. The golden runs on the RTL's recordings, and the cycle the last completion landed (2908) is the number you would quote.
- Visualizing timing - Seeing where the cycles go: tracing the RTL run and rendering it, to show how the stages overlap and which one is the bottleneck. The pysim and the RTL agree on the steady-state period, about 187 cycles per job, because this design composes two already-calibrated framework components and Waveflow ships their timing for this platform — mem_copy itself calibrates nothing.