A memory-mapped FIR

The polynomial on a bus put a stream-only kernel behind memory-mapped queues, reached by a host over a crossbar. This example keeps that shape and adds what a kernel the host configures needs: a register bank beside the queues, an order between a config and the samples it applies to, and a choice of how the views sit on the bus. A host writes the FIR’s taps into registers, pushes samples into a queue, and reads results out of another queue — all through one AXI slave address range, the way a processor talks to a peripheral.

Vitis HLS cannot generate that slave side. So the kernel stays a stream-only FreeRunMod — and a memory-mapped slave adaptor in the RTL top does the translation: bus transactions in, stream messages out. This example is the worked design for that adaptor, and for the components of the XSI simulation a design with one has.

Learning objectives

What this adds to The polynomial on a bus (views declared in mm_views, build_mm_device, a crossbar, a host on interrupts and its C++ twin), in the order the pages teach it:

  1. Choose a view for each kind of traffic: a register bank for configuration (shadow and commit) and for status (the latest value), queues for the samples, the results and the responses.
  2. Lay out the views’ local address regions as the kernel type’s layout (MemSlaveLayout, a 4 KB window each in declaration order), give the slave a global base with assign_address_ranges, and hand both to the C++ host as a per-type layout header and a per-system bases header, combined as at(view, base).
  3. Carry the order between two streams in the messages: a config id (cfg_id) the host puts in each config and names in each packet’s header, a kernel that waits for that config, and a response FIFO that echoes which config each packet was filtered with – the command-response pattern for a config.
  4. Build the device in two adaptor topologies – a front per view (per_view) or every view behind one front and a generated decoder (one_front) – with one address map and the same host program.
  5. Find where pysim’s cycles and the RTL’s differ with handshake probes, and calibrate pysim’s timing against the RTL.

Pages

  • Protocol — what the host and the kernel say to each other: a config, then per packet a header naming its config and its samples, the results and a response; why the config id is needed, and what the example demonstrates.
  • Slave adaptor — the adaptor that carries it: why it is needed, its views, constructing it from the kernel’s declaration, the local memory map and the global base, and reaching the views from the host.
  • Python model — the schemas, the kernel’s run_iter, the host program, the golden.
  • Python simulation — the system wired in pysim, the tap switch, the negative control, and how close pysim’s timing is.
  • Build flow — the build DAG (mm_fir_build.py) for both topologies: which steps are the example’s (codegen and the scenario), which are the framework’s, the CLI, and what a second run skips.
  • Code generation — what each pysim object generates (Fig. 1), the generated top and headers, the hand-written HLS body, and why it had to change to pipeline.
  • Synthesis — csynth of the kernel, the crossbar IP, and the Verilog top walked from the graph in both topologies, with the generated decoder (Fig. 2).
  • XSI testbench — the RTL under a testbench (Fig. 3): the C++ host program, the conformance gate, and the bus master that overlaps a read and a write.
  • RTL simulation — the results: both topologies bit-exact, 618 and 611 cycles, and how the numbers got there.

The code is in examples/mm_fir.


Table of contents

  • Protocol - What the host and the FIR kernel say to each other, and in what order: commit a config named by a cfg_id, send each packet as a header naming the config it needs and its tx_id followed by its samples in-band, take the results and a response that echoes both. Why the config id is needed -- two streams have no order between them -- why it is carried rather than counted, the protocol's limits, and what the example demonstrates.
  • Slave adaptor - The memory-mapped slave adaptor that carries the protocol, in front of a stream-only kernel: why it is needed, its views and what each is for, how the kernel declares them (mm_views) and build_mm_device constructs the adaptor, how the local memory map (the type's layout) and the global base give every view its address, and how the host reaches the views through endpoints and interrupts.
  • Python model - The Python side of mm_fir: four DataList messages (the packet header, the response, the config and the status) that also generate the C++ structs, typed int16 samples and int64 results packed by the serializer, a vectorized exact-integer golden, the kernel as a FreeRunMod whose run_iter is one packet -- header, the config it names, samples, response -- and the host program: a writer that commits configs and sends tagged packets, and a reader that takes the results and checks each response.
  • Python simulation - The whole system in pysim, in three wirings with one host class: each view on its own crossbar slot, all four behind one adaptor port, and the host joined straight to the kernel. Bit-exact through a mid-stream tap switch in all three, including one inside a packet; a config committed after its packets is waited for; the wrong-tag negative control is exposed by the responses. Cycle counts against RTL, and the three model fixes -- found by lining up both backends' bus operations -- that bring pysim within 4.4% of it.
  • Build flow - The example's whole build -- from its generated sources to the RTL trace gate, for both adaptor topologies -- as one BuildDag in mm_fir_build.py. Only codegen and the scenario (system(topology): 200 samples, a tap switch at sample 101) are the example's; add_system_steps, called once per topology with a prefix, adds the framework's steps, sharing one csynth. The CLI (--through, --status, --synth check, --probes), what a second run skips, and where a run's results land. The next three pages take the steps in order: Code generation, Synthesis, XSI testbench.
  • Code generation - The codegen step: what each pysim object generates (Fig. 1). What becomes the Vitis kernel, and what does not. The message structs and the free-running top are generated; the task body is hand-written and declared with kernel_task(). The memory-mapped side is not in the kernel at all — it is RTL beside it. And the lessons of the body: a first version with no pipelined loop ran at one sample per ten cycles; a single-firing state machine reached II=1 and never drained between packets; the body now is straight-line per packet with a pipelined sample loop -- the twin of run_iter -- at a measured ~15% cost on short packets.
  • Synthesis - The csynth and system_rtl steps: how the system becomes Verilog (Fig. 2). csynth runs Vitis on the one HLS top, mm_fir -- re-run only when its source stamp no longer matches, built or only checked (synth=build|check) -- shared by both topologies. Each topology's system_rtl generates its crossbar IP with create_ip and walks the pysim graph, cut at the kernel, to mm_fir_top.v: the kernel, the framework's view leaves behind one front per view (per_view) or one front and a generated decoder (one_front), and the host's bus and interrupts as top ports.
  • XSI testbench - The last four steps of the build flow -- scenario, pysim, system_xsi and compare, per topology -- put the RTL from Synthesis under a testbench and check it against pysim (Fig. 3). The host's C++ twin in mm_fir_host.h -- two threads on generated endpoints, the same program as FirHost -- runs from the same scenario file as the pysim host, sleeps on the queue views' interrupts, and its bus master overlaps a read and a write; every host endpoint's trace must be byte-identical between the two runs.
  • RTL simulation - The results of the whole system as RTL under XSI (built and run by the three pages before: Build flow, Synthesis, XSI testbench): AMD's axi_crossbar, the hand-written adaptor leaves, and the csynth'd mm_fir kernel in one generated Verilog top, driven by the pysim host program written against C++ endpoints, with an address map generated from the pysim system. Two adaptor shapes — one view per crossbar slot, and all four behind one front with a generated decoder — both bit-exact against the numpy golden through a mid-stream tap switch, every response checked, no polling (the host sleeps on the queue views' interrupts), at 618 and 611 cycles.