Interleaver — a gather accelerator with a custom compute stage

This example builds on mem_copy. Where the data mover copies a buffer unchanged, interleaver computes a gather — Y[i] = X[P[i]], reordering X under an index vector P — so it adds the two things a pure data mover never needs: a real compute stage, and on-chip random access (holding X in block RAM so the index-driven reads are single-cycle). It is the same concurrent free-running flow: a composite of ap_ctrl_none hls::tasks, wired by internal streams and stream-of-blocks, driven by a command stream and reporting on a done stream.

mem_copy reuses only pre-calibrated infrastructure and so calibrates nothing itself. The interleaver is the counterpart: its il_compute gather is the design’s own kernel, whose timing does not ship — so this is the example where you fit a custom component’s timing, the half of the calibration story mem_copy has none of. It still reuses the shipped infrastructure — the m_axi bus law is loaded from the platform exactly as before — and layers its own compute model on top.

Learning Objectives

What this adds to Free-running memory copy, in the order the pages teach it:

  1. Give a compute stage random access to a buffer (X[P[i]]) with a stream of blocks, and overlap the next job’s load with this job’s compute.
  2. Frame two reads (P and X) through one MemRStream with an in-band descriptor, which also paces the free-running pipeline (one job in flight, no deadlock) and returns a done timed at the commit.
  3. Write a custom compute stage (il_compute) and declare its own loop timing model, latency + ii·(n − 1).
  4. Draw the six-stage pipeline from pysim on an activity diagram, and compare pysim’s timing with the RTL’s, measured from a trace.
  5. Fit the compute stage’s two parameters from a size sweep of RTL runs (the direct fit), and store the fit in the platform library so a build loads it with no re-fit.

In this example

The pages build the design up from Python, parallel to mem_copy:

  • Module overview — the gather, the six stages, the stream-of-blocks for random access, and the per-job token forwarding.
  • Python — building the design in Python: the descriptor split, the two-reads forwarding chain, the stream-of-blocks, the hand-written leaves, and the composite.
  • Testbench (Python) — the graph that surrounds the design and drives it in pysim, and the Y = X[P] golden check.
  • DUT codegen — how the graph becomes the ap_ctrl_none hls::task top, and why every task body is hand-written.
  • The system — the testbench graph cut at the kernel, and the top, harness and scenario the system flow derives from it.
  • RTL simulation — running the harness in xsim: no deadlock, and bit-exact through real RTL.
  • The timing model — declaring il_compute’s own loop model: where it plugs into the stage, the latency + ii·(n − 1) formula, and what the parameters mean.
  • Timing in the pysim — what the loosely-timed pysim measures and the six-stage pipeline activity plot it produces (from the pysim → figure build DAG).
  • RTL timing and the comparison — the RTL cadence measured from a trace, the generated RTL-vs-pysim table, and the ≈0.7% agreement (including the reader residual the interleaver forced into existence).
  • Fitting the timing model — the capstone: measure il_compute’s per-firing cost from a full-pipeline XSI run (the span, gated on no stall), fit the two parameters, and ship the fit to the platform library — a recipe for fitting a custom stage of your own.

Table of contents

  • Module Overview - What the module computes — a gather, Y[i] = X[P[i]] — and why it follows the data mover. Where mem_copy copies a buffer unchanged, this reorders it under a permutation, so it has a real compute stage, and that stage needs random access to the source, which shapes the whole design. Coordinates are element and word indices throughout, never byte addresses.
  • Python - Building the design in Python: four hand-written FreeRunMod leaves, the two framework mem-streams they compose with, and the composite that wires all six. Shows how to write each kind of block for a gather, starting from the two descriptor types — one plain boundary command the host sends, one framed internal descriptor the pipeline forwards.
  • Testbench (Python) - The graph that surrounds the design and drives it in pysim, with no toolchain: a participant on every boundary port, wired by the same Interface objects the design uses internally, checking the gather golden bit-exact. This is the functional golden, and the RTL simulation later drives the same scenario through real Verilog.
  • DUT codegen - Lowering the six-leaf graph to a free-running Vitis HLS top — the same lowering mem_copy uses, with nothing added for the gather. Explains what an hls::task top is: bodies the runtime re-fires on their own whenever their input streams have data, so there is no host handshake and the stages overlap rather than running in sequence.
  • The system - The testbench graph that ran in pysim, with one more fact stated: which part of it is the design. interleaver_inband_system() cuts the graph at the interleaver kernel; from that the system flow derives the Verilog top around the synthesized kernel, the harness of the participants' BFM models answering its ports, and the scenario, so the RTL run cannot drift from the model it is checked against.
  • RTL simulation - The rung that proves the one thing only RTL can show for a free-running design: the six-stage pipeline runs to completion without deadlock, and running, is bit-exact. Nothing but the in-band descriptor throttles these un-paced tasks, so a wiring bug that dropped a token would not give a wrong answer — it would hang, and the pysim can miss that class entirely.
  • The timing model - The framework mem-streams ship their timing; the gather stage is the design's own kernel, so the design gives it one. In pysim the gather is instantaneous, so without a model the compute looks free and the timeline runs ahead of the RTL. Declares where the model lives on the stage, the formula it evaluates and what its parameters mean.
  • Timing in the pysim - What the loosely-timed pysim measures, and the pipeline-activity plot it produces. Each stage's cost is a loaded model — the bus law per m_axi transfer, the mem-streams' own control residuals, and the gather's own cycle count — with backpressure emerging from the bounded FIFOs between stages rather than being modelled.
  • RTL timing and the comparison - Measuring the actual RTL timing from a trace and putting it beside the pysim's modelled timeline; they agree on the steady-state period to about 1%. Every stage fires once per job except the reader, which fires twice — P then X — so the pipeline is reader-bound: moving both vectors over one m_axi bus is the critical path.
  • Fitting the timing model - Recovering the compute stage's latency and initiation interval from the RTL by the direct method: run the kernel at a range of sizes, record the cycles, fit a line, and ship the result to the platform library so any build loads it. The half of the calibration story mem_copy has none of, because the gather is the design's own kernel — read it as a recipe for fitting your own stage.