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:

  1. Make a kernel master memory: its reads and writes go over two m_axi bundles through the framework’s MemRStream / MemWStream adaptors, with no memory logic of its own.
  2. 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.
  3. Put a memory model (MemoryMod, one shared arena) in the testbench, and check the golden on the words the RTL wrote into it.
  4. Read the generated hls::task top’s m_axi ports (offset=off and stable), and state the system as HwSystem(sim, dut): the kernel the DUT, the drivers and the memory the testbench.
  5. Draw the concurrent timing of a traced RTL run on an activity diagram: the pipeline overlap and where every cycle of the period goes.
  6. Reuse the platform’s pre-fit timing of the m_axi bus 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:

  1. Module overview — the three-stage design, the in-band forwarding protocol, and how it is wired.
  2. Python model — the schemas and the three FreeRunMod leaves + the composite.
  3. Testbench (Python) — the graph (wire_mem_copy), the MemCopySim procedure, and running the pysim step.
  4. DUT codegen — what an hls::task is, and how the design graph becomes the ap_ctrl_none top.
  5. 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.
  6. RTL simulation — running the system flow end to end, the RTL-vs-pysim comparison, and the golden at 3000 cycles.
  7. 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.