A memory reached three ways
Sharing memory between concurrent tasks arises in a multitude of applications — capture buffers, scoreboards, and storage of intermediate values. As the memory guide describes, there are three ways to share memory between hardware modules:
- External memory, typically DDR, that exists on the board and reaches the programmable logic over an AXI-MM interface.
- A ping-pong buffer (PIPO), which transfers blocks with a synchronization mechanism built in.
- A dedicated BRAM (Block RAM), instantiated in the top-level design in the programmable logic.
This example demonstrates implementing, modelling and using a BRAM, where two hardware modules share one true-dual-port memory. For shared DDR see the histogram example; for the ping-pong buffer, the interleaver example.
The interface itself is documented in BRAM — memory between modules; this page set is the worked example that uses it.
Why a dedicated BRAM?
A BRAM can be given dedicated access to a small number of hardware modules. DDR usually has to be shared with other modules and with the PS, which can add substantial delay.
A PIPO is also typically built from a two-port BRAM, but it comes with a synchronization mechanism you do not choose, and it requires one module to write a different buffer segment than another reads. A BRAM gives you the memory and leaves the correctness argument to you — which is the whole subject of this example.
The example
Two hardware modules share one BRAM, and the memory is reached three ways — which is where the name comes from, and which lines up with the three access cases that every Waveflow interface is organised by:
| transaction | access case | what it costs |
|---|---|---|
WRITE |
a timed transfer into the memory | 1 access per element, II=1 |
COMPUTE |
in place — no transfer at all | 2 accesses per element, II=2 |
READ |
a timed transfer out of the memory | 1 access per element, II=1 |
WRITE and COMPUTE go through the same port on the same task, so the only thing that differs
between them is the access shape. That makes the II a measurement in one waveform rather than an
argument, and it is why this example has two opcodes instead of two examples.
The nesting is the point. The memory is outside the kernel and inside the wrapper, because a
memory shared between two tasks has no expression inside a Vitis kernel at all —
the guide has the evidence,
including the two things Vitis does instead when you try. Every transaction takes a command and
answers with a (tid, status) response: a write has no return path of its own, and a refused read
returns zero words, which on a stream is indistinguishable from “not yet”. The messages are declared
once as schemas, and the C++ headers the kernel compiles against are generated from them.
Learning objectives
What this adds to the memory examples before it – memory over m_axi
(Free-running memory copy), blocks between stages
(Composite kernel interleaver), state inside a module
(Block FIR with state) – in the order the pages teach it:
- Put a memory outside the kernel, as hand-written Verilog (
rtl_module()) joined to the kernel by a generated wrapper, and connect two modules to it through aBramIFregistered withadd_rtl_ifrather thanadd_if. - Move a vector into it, compute over it in place without inventing a transfer, and measure what declaring a port read-write costs (II=2 against II=1).
- Answer every transaction, a write included, with a
(tid, status)response. - Read and write it from two tasks at once, and name what actually guards the hazard.
- Model the read path’s fill from the
READ_LATENCYthe memory’s Verilog declares, never from a number typed into Python, and record the timing in pysim. - Run the RTL with the real hand-written Verilog as the memory, no BFM standing in for it.
- Check throughput, overlap and the in-place cost on an activity diagram of the RTL trace.
Once you have this example, the same structure is what the RF shot buffer is built on.
The pages
- Python model — the three transactions, the schemas, the two task bodies, and the top level with the memory beside it.
- Python simulation — running it, the test vectors, and recording the timing.
- Code generation — the kernel,
bram_t2p.v, and the wrapper that joins them. - RTL simulation — running XSI, and producing the trace.
- Reading the trace — the activity diagram, the hazard scan, the in-place cost, and the comparison to pysim.
See also
- BRAM — memory between modules — the interface, the evidence for why the memory cannot be inside a kernel, and the addressing convention.
- A module realized as Verilog — the
rtl_module()hook, the port-name chain, and the latency single-source rule. - Free-running composite — where the wrapper
fits, and what
csynthdoes not count.
Table of contents
- Python model - The model: three transactions over one memory, each a command with a response. WRITE puts a payload at an address, COMPUTE rewrites that range in place as x*3 + 1, and READ returns it. WRITE and COMPUTE share a stream and a task because they share a port; READ is a second task on the other one.
- Python simulation - Running the design in SimPy, long before Vitis is invoked, and recording the timing the trace page later compares against RTL. The testbench is the DUT plus six stream BFMs — and the memory is deliberately not among them, because it lives inside the DUT's wrapper. That absence is what keeps the RTL harness small: the elaborated design's only pins are AXI-Stream.
- Code generation - Three artifacts from the one Python class: the Vitis HLS kernel, the hand-written memory placed beside it, and the wrapper that joins the two. The message headers are emitted first, from the same declarations the model reads through. Also the one thing that has to be reconciled between the kernel's ports and the memory's.
- RTL simulation - Running the design through the system flow under XSI, Vivado's shared-library simulation interface: the kernel and its memory as the DUT, the drivers and sinks answered by their own C++ models, all derived from the same graph the pysim testbench came from. Not cosim: this top is ap_ctrl_none with two hls::task bodies that never return, and Vitis cosim of such a design is unreliable — the generated top says so in its own header comment.
- Reading the trace - Reading the VCD the RTL run produced: what the design did, whether it did anything it was not allowed to, how long the memory really takes to answer, and how that compares with the Python model. Unlike the other timing pages here the lanes are the memory's own pins, so the picture shows the memory being used rather than inferring it from the streams at the boundary.