Histogram with shared memory
The shared-memory pattern moves the data off the control plane and into
memory: the accelerator reads its inputs and writes its outputs over an AXI4
memory-mapped (m_axi) master, while a dedicated AXI4-Stream still carries the
command and the status response. It is the next step in the
examples progression after in-band stream control — control stays on a
stream, but the payload now lives in shared memory addressed by pointers in the
command.
The vehicle is a histogram accelerator (examples/shared_mem/, computation
files keep the hist name): given a command carrying three buffer addresses, it
reads ndata float samples and nbins-1 float bin edges from memory, bins the
samples, and writes nbins uint32 counts back to memory.
This makes it the first example to exercise, over one m_axi bundle:
- Multiple distinct buffers at independent addresses (
data_addr,bin_edges_addr,cnt_addr). - Two element types —
Float32inputs/edges andUint32counts. - Validation → status —
ndata/nbinsbounds checks select aHistErrorinto the response before any memory access.
Like the other full examples it walks all five stages — Python model → SimPy
simulation → code generation → C and RTL simulation → timing extraction — with
the kernel and testbench generated from the Python HistAccel component. It is
the reference design for AXI-MM (m_axi) codegen.
Learning Objectives
What this adds to the legacy examples before it (Register mapped simple function, Streaming polynomial), in the order the pages teach it:
- Move bulk data off the control plane and into shared DRAM over an AXI4
memory-mapped (
m_axi) master, addressed by pointers carried in the command — while control / status stays on a dedicated AXI4-Stream. - Drive multiple distinct buffers at independent addresses (
data_addr,bin_edges_addr,cnt_addr) and mixed element types (Float32in,Uint32out) over onem_axibundle. - Validate command bounds and select an error status into the response before any memory access.
- Use the
MMIFMaster(read_array/write_array) interface and the SimPyMemoryModharness to reach parity with the numpy golden. - Generate the multi-buffer
m_axikernel + testbench, run the four-case C-sim, C-synth, and RTL cosim, and extract multi-buffer burst timing.
Walkthrough
- Understanding AXI Memory-Mapped — what
m_axiis (burst transfers, byte-addressed pointers into shared DRAM), and the shared-memory architecture: bulk data in memory, command/response on a dedicated stream. - Python model — the
HistAccelcomponent, theHistCmd/HistResp/HistErrorschemas, and theMMIFMaster(read_array/write_array) interface. - Python simulation — the SimPy harness (
HistController+MemoryMod) and parity against the numpy golden. - Code generation — lowering
HistAccel/HistTBHlsto the multi-buffer m_axi Vitis HLS kernel and testbench. - C and RTL simulation — the four-case C-sim coverage, C-synthesis, RTL co-simulation, and multi-buffer burst extraction.
- Viewing timing and bursts — the committed timing/burst figures and the workflow for refreshing them.
Table of contents
- Understanding AXI Memory-Mapped - The first example whose data lives in memory rather than on the control bus or a stream: the accelerator is handed byte addresses into shared DRAM, reads its inputs over an m_axi master and writes its outputs back the same way. Introduces why bulk data needs a different interface from the control registers and the streams of the earlier examples.
- Python model - Writing the histogram accelerator as an HwModule: the command and response schemas that ride the streams, the kernel's three data ports, and the on_start body that validates, reads, computes and writes back. The concept page covers why the data lives in memory and the control on a stream; this is how.
- Python Simulation - Running the histogram in SimPy before ever invoking Vitis, and checking the counts against the numpy golden. Unlike the register-map example, where the host talks to the kernel over one AXI-Lite link, here there are two participants on the memory side — the host controller and a MemoryMod standing in for shared DRAM.
- Vitis HLS Code Generation - The same class that ran in SimPy is the source for the Vitis kernel. Waveflow emits everything mechanical — the m_axi signature, the interface pragmas, the multi-buffer burst calls, the validation-status plumbing — and leaves only the datapath hooks as hand-written C++. Walks the generated kernel, the generated testbench, and the seam between the two kinds of code.
- C and RTL Simulation - Driving the generated kernel through Vitis: C-simulation checked bit-exact against the numpy golden across four coverage cases, C-synthesis to RTL, RTL co-simulation for a measured cycle count and a waveform, and extraction of the AXI-MM read and write bursts from that waveform.
- Viewing Timing and Bursts - Turning the cosim waveform and burst report into two pictures: the multi-buffer burst layout at its byte addresses, and the transaction timeline. Both are rendered from the burst report, which is itself regenerable from the committed VCD with no Vitis run — so the figures can be refreshed without the toolchain.