Slave adaptor views

A slave adaptor is made of views, each a way for a bus master to reach a free-running kernel. This page takes them one at a time. Each section says what the view is for, gives its constructor, then describes its two sides:

  • The kernel side is what the kernel’s code does: read or write a stream (or, for the BRAM window, a memory port). The kernel never sees an address.
  • The bus side is what a bus master — a host program, or a test standing in for one — does. It asks the adaptor for the view by name and gets an ordinary endpoint (Reaching the views from a bus master); the endpoint turns each call into bus reads and writes. The addresses it uses are in how it works.

All the constructors take name, sim and clk like any module, and these two:

parameter default meaning
mem_dwidth 64 the bus width in bits; one bus word
window 4096 the window size in bytes: a power of two, at least 4 KB. A queue, register bank or credit view is 4 KB; a BRAM window is its memory’s bytes (what build_mm_device gives it). Inside a MemSlaveAdaptor each view is placed by its size (Where each view sits)

How the views are built in RTL, and why they behave as they do, is in Slave adaptor — how it works.

Queue in

A queue in is an input FIFO for the kernel that a bus master fills. The bus master writes packets of words; the kernel reads them as an ordinary stream, one packet at a time.

qin = MemSlaveWStream(name="qin", sim=sim, depth=16, clk=clk)
parameter default meaning
depth 512 FIFO depth in words; a power of two, at least 2

The kernel side is the stream endpoint qin.m_out. Bind it to a stream whose depth equals the queue’s depth (that stream is the FIFO, and the simulation checks it at start), and give the kernel a StreamIFSlave on the other end. The kernel reads exactly as it would read any stream:

pkt = yield from self.s_in.get()        # one packet, as the bus master wrote it

Each packet ends with TLAST, so the kernel sees where the bus master’s packets begin and end.

The bus side is a StreamIFMaster, given the host’s end of the view’s interrupt line (qin.m_irq, see Interrupts):

qin_ep = mm.stream_master("qin", irq=qin_irq)
yield from qin_ep.write(samples)        # one packet; returns once the queue has taken it
  • One write is one packet, and the kernel’s get() returns it whole.
  • write waits for room on the interrupt — high while the free space is at least the threshold the endpoint sets — never by stalling the bus, and never by reading the free space. A packet goes in one piece once there is room for all of it.
  • The window’s upper half is control: a write there sets the interrupt threshold. Pushes go to the lower half (an AXI4 burst — at most 2 KB at 64 bits — from the base stays there).
  • A completed write means the queue took the words, not that the kernel has read them.
  • Kernel to kernel. A kernel that writes memory through MemWStream can feed another kernel’s queue by pointing its base address at the window and putting the packet’s length first — the format in how it works. That path stalls rather than waits, so it suits a master port that carries nothing else.

RTL: QueueView(name, kind="in", axis, depth=512, law=12), where axis names the kernel’s AXIS port and law is log2 of the window size; module mm_queue_in.v.

Queue out

A queue out is an output FIFO from the kernel that a bus master drains. The kernel writes words to a stream; the bus master reads them out.

qout = MemSlaveRStream(name="qout", sim=sim, depth=16, clk=clk)
parameter default meaning
depth 512 FIFO depth in words; a power of two, at least 2

The kernel side is the stream endpoint qout.s_in. Bind it to a stream whose depth equals the queue’s depth, and give the kernel a StreamIFMaster on the other end, declared has_tlast=False: queue out carries no packet boundaries (see below). The kernel writes as it would to any stream, and blocks when the queue is full:

yield from self.m_out.write(words)

The bus side is an MmStreamIFSlave — a StreamIFSlave declared has_tlast=False — given the host’s end of the view’s interrupt line (qout.m_irq):

qout_ep = mm.stream_slave("qout", irq=qout_irq)
y = yield from qout_ep.get(nwords_max=n)            # exactly n words
y = yield from qout_ep.get_array(Sample, count=n)   # n typed elements
  • Reads name their size. The bus cannot see where the kernel’s packets end (the RTL drops TLAST), so get() without a count is refused. get(nwords_max=n) returns exactly n words, waiting until they are all there — what an HLS read of n words does.
  • Reads wait on the interrupt. The endpoint sets the threshold to the words it wants, sleeps until the interrupt says they are there, and pops them. It never reads the count, and never pops an empty queue. A write to the upper half of the window sets the threshold.
  • The *_nb reads return None unless all the words are already there (the interrupt is high).

RTL: QueueView(name, kind="out", axis, depth=512, law=12); module mm_queue_out.v.

Register bank

A register bank holds a kernel’s configuration and status. A bus master writes configuration fields, then commits them; each commit reaches the kernel as one complete configuration message. The kernel, in turn, sends status messages, and the bus master reads the latest one. It is the free-running kernel’s counterpart of a register map; the two are compared below.

regs = MemSlaveRegBank(name="regs", sim=sim, cfg_type=Cfg, status_type=Status, clk=clk)
parameter default meaning
cfg_type required the configuration, a DataSchema. Its size in bus words is regs.ncfg; it must fit in half the window
status_type required the status, a DataSchema. Its size in bus words is regs.nstat; it must fit in a quarter of the window

The kernel side is two stream endpoints:

  • regs.m_cfg sends one config message per commit. Bind it to a stream of depth exactly regs.ncfg (one message; the simulation checks it), and give the kernel a StreamIFSlave. The kernel receives a whole configuration at once:

    cfg = yield from self.s_cfg.get_schema(Cfg)       # waits for the next commit
    cfg = yield from self.s_cfg.get_schema_nb(Cfg)    # or: check, and carry on if there is none
    
  • regs.s_status receives status messages. Give the kernel a StreamIFMaster and write whole status messages, as often as it likes:

    yield from self.m_status.write(Status(nsamp=self.nsamp))
    

The bus side is two endpoints, one per direction:

cfg_ep = mm.stream_master("regs")
yield from cfg_ep.write(make_cfg(...))   # one config message to the kernel

status_ep = mm.status("regs")
st = yield from status_ep.read()         # the latest status message, decoded
  • One write is one configuration. It writes the configuration registers (a staging copy the kernel never sees, the shadow), then COMMIT, which sends the shadow to the kernel as one message. The kernel never sees a half-written configuration.
  • A commit is never merged or dropped. If the kernel has not yet taken the previous configuration, the commit waits until it has. This is the one place the endpoint can stall the bus, because the bank reports how many commits it accepted, not how many the kernel took; the stall lasts until the kernel reads.
  • status.read() does not consume. Read it twice and you get the same message. It is a LatestValueIFSlave, the same endpoint a direct connection gets from a LatestValueIF.
  • Status is the latest complete message. A read never mixes words of two status messages.
  • The kernel chooses when a new configuration takes effect. Checking with get_schema_nb at a safe point — between packets, or between samples — means a configuration never changes mid computation. mm_fir does this, and goes further by naming the exact sample a configuration applies at.
  • A register bank has one owner. Two bus masters writing the same bank are each served whole, but one could commit the other’s half-written configuration. If two writers are needed, give each its own bank, or send complete configurations through a queue.
  • For a large table, use a BRAM window. The configuration is copied at each commit, which is cheap for a few dozen words. For a thousand filter taps or a lookup table, write the table into a BRAM window and announce it with a doorbell.

RTL: RegBankView(name, ncfg, nstat, cfg_axis, status_axis, law=12), with the word counts in place of the types; module mm_regbank.v.

Register bank or register map?

A register map is the same idea — a register file a host writes to configure a kernel — realized for the other kind of kernel:

  Register map (RegMap) Register bank (MemSlaveRegBank)
for a host-activated kernel free-running kernel
realized as Vitis-generated s_axilite, inside the kernel hand-written RTL (mm_regbank), beside the kernel
bus AXI-Lite: one word per transaction AXI4 through the adaptor and crossbar: bursts
layout named fields, each at its own offset one DataSchema in a shadow at offset 0; COMMIT and status at fixed offsets
the host writes a field at a time, straight into what the kernel uses into a shadow the kernel never sees
the kernel sees a change at its next launch, when ap_start latches its arguments when it takes the next config message, one per COMMIT
status output fields the host reads (typically after ap_done) the latest complete status message
per-field access modes (W1C, W1S, hooks) yes no: whole messages only

COMMIT plays the role ap_start plays for a host-activated kernel: the one moment the configuration changes hands. The bank exists because s_axilite is no use to a free-running kernel, which cannot see a write happen. The two share no code today; laying the bank’s shadow out with RegMap’s field offsets — so a host could write one field by name, and one generated host header could serve both — is a natural next step, not yet built.

BRAM window

A BRAM window is a block of memory that a bus master and the kernel share: the bus master reads and writes it by address through one port of a dual-port BRAM, and the kernel uses the other port. It is for data the kernel wants random access to — a table, a frame — rather than a stream.

bram = MemSlaveBramWindow(name="bram", sim=sim, nelem=256, clk=clk)
parameter default meaning
nelem 512 the memory’s size in bus words; a power of two, and nelem × bytes-per-word must fit in the window
bram_leaf "mm_bram_port" port A’s RTL leaf: "mm_bram_port" or "mm_bram_port_pipe" (which)
calib_dir None where the bus side’s timing record is looked up (timing); None: the bus side costs nothing
port_b_access "readwrite" what the kernel on port B does through it: "read", "write" or "readwrite"; its port must say the same
element_type None what a word holds on port B; None is a raw bus word, word_element(mem_dwidth). Another type must be mem_dwidth bits and stored as an unsigned word

The kernel side is the memory’s port B, bram.b_port: a BramIFSlave that a kernel’s BramIFMaster binds, exactly as it binds a T2pBram’s port (BRAM — memory between modules). A kernel written against T2pBram banks binds a window unchanged. In a device, the kernel’s class says which of its ports holds port B, in mm_views, and build_mm_device makes the window and the bind:

@dataclass
class Capture(FreeRunMod):
    mm_views: ClassVar[tuple] = (
        BramWindow("ring", nelem=256, port="ring_b", access="write", bram_leaf="mm_bram_port_pipe"),
    )

    def __post_init__(self) -> None:
        super().__post_init__()
        self.ring_b = BramIFMaster(name=f"{self.name}_ring_b", sim=self.sim,
                                   element_type=word_element(128), nelem=256, access="write")
        self.add_endpoint(self.ring_b)

Outside a device, bind it yourself, as for a T2pBram:

bi = BramIF(name="ring_if", sim=sim, clk=clk)
bi.bind(ep_name="master", endpoint=kernel.ring_b)
bi.bind(ep_name="slave", endpoint=bram.b_port)
  • The bind checks the two ends against each other, when it is made: the same element (so the same width – the bus width, since port A moves a bus word, and bram_t2p has one width on both ports), the same depth, the same access. A mismatch is refused there, not found at RTL.
  • The kernel reads and writes through its port as through any BramIFMaster: write / read untimed, write_pipelined / read_pipelined a word a cycle; a word wider than 64 bits is a row of uint64 chunks, lowest first. What the kernel writes, the bus reads, and the reverse. An address outside the memory is refused rather than wrapped. Port B is untimed in pysim: the kernel’s own model charges its accesses.
  • A model that holds the window itself can still call bram.port_b_read(i) and bram.port_b_write(i, value): untimed, the address wrapped modulo the depth, as the RTL’s mem[addr[AW-1:0]] does.
  • A banked memory is several windows: n banks of 1/n the width, one window each, all in the kernel’s adaptor, each on its own BramIFMaster. Each window is its memory’s size – 16,384 words of 128 bits is a 256 KB window – placed in the adaptor by size beside 4 KB views (Where each view sits). But behind one front the banks take turns: readers of four 128-bit banks share one 128-bit port, so a bank of the whole width reads a block faster than n narrow ones (the emitter example’s results).

What the system top wires. The kernel’s bram port goes to the window memory’s port B inside the device’s sub-top, as a wrapper wires a T2pBram: Vitis addresses a mode=bram port in bytes and enables bytes, so the kernel’s address is shifted to a word address (>> log2(W/8)) and its byte enables are reduced to the memory’s write enable; the B half of a ram_1wnr pair is left open, its Dout driven 0. A window no kernel holds keeps port B tied idle. The device also gets a hazard manifest: port B (the kernel) the write side, port A (the leaf) the read side, so a traced run can be scanned with waveflow.utils.bram_trace.find_read_during_write (the $error nobody hears); a traced run dumps the device’s sub-top. Gated at RTL by examples/bram_ring (a kernel writes a banked ring through port B while a MemRStream reads it back through port A over the crossbar; 1 bank of 512 bits and 4 of 128, each leaf, every word read back bit-exact, a deliberate collision seen and the normal run clean; xsim 2025.1, tests/examples/test_bram_ring_xsi.py), and windows larger than 4 KB by its wide ring (examples/bram_ring/wide_ring.py: four banks of 4 KB, 64 KB and 256 KB beside a 4 KB register view in one adaptor, each bank’s last word and the hole read back where the layout puts them; xsim 2025.1, tests/examples/test_wide_ring_xsi.py).

The bus side is a Region — the same element-indexed view of memory a kernel uses through its m_axi port:

buf = mm.region("bram", Sample)
yield from buf.write_slice(0, table)       # elements 0 .. len(table)-1
x = yield from buf.read_slice(16, 32)      # elements 16 .. 31

An access beyond nelem is an error: a write there is dropped, and a read returns 0 with SLVERR.

The kernel is not told when the data changes. This view moves data, not messages. To tell the kernel that new data is ready, the bus master writes the memory, then writes a doorbell — a packet to a queue in, or a commit to a register bank. For that order to hold, the BRAM window and the doorbell view must be in the same adaptor; see Ordering. The other way round is the same: a kernel that writes the window through port B tells the reader with a message once the words are in (examples/bram_ring’s writer sends its reader the read command after the block).

RTL: BramView(name, kport, baw=9, law=12), where baw is log2 of the memory’s size in words and kport names port B’s nets (system_top names them for b_port, <window>_b_*); modules mm_bram_port.v and bram_t2p.v. BramViewP1 and BramViewPipe are the same with the other two leaves. A kernel on port B is a BramPortB of the system top’s spec (SystemTopSpec.bram_b).

Which leaf

Port A is one of three hand-written leaves on the same front and the same bram_t2p. They differ in how a read word gets out:

leaf read words a cycle the response the front’s reads outstanding chosen by
mm_bram_port.v ½: one read in flight, LAT + 1 = 2 cycles each a register (synthesis moves it into the BRAM’s own output register) 1 the default; MemoryMod; BramView
mm_bram_port_p1.v 1 the BRAM’s output, unregistered, straight to the read channel 1 PipelinedMemoryMod; BramViewP1
mm_bram_port_pipe.v 1 a register: no timing path from the memory to the read data 2 (RD_OUTST) bram_leaf="mm_bram_port_pipe"; FullRateMemoryMod; BramViewPipe

An N-beat read, the slot straight on an AXI port, takes 2N + 2 cycles with mm_bram_port and N + 3 with the pipelined leaf, from the address presented to the last beat (xsim 2025.1, tests/build/test_mm_bram_pipe_xsi.py). All three close timing at 4 ns on xczu48dr (Vivado 2025.1, 16 KB window, placed and routed with a register on every port; tests/build/test_mm_bram_timing_vitis.py):

leaf bits alone: WNS (ns) LUT FF behind a 4-master axi_crossbar: WNS (ns)
mm_bram_port 128 / 512 +1.878 / +1.219 141 / 343 38 / 41 –
mm_bram_port_p1 128 / 512 +2.013 / +0.994 130 / 334 29 / 31 +1.035 / +0.319
mm_bram_port_pipe 128 / 512 +1.818 / +1.052 402 / 1,379 423 / 1,596 +1.077 / +0.520

When to choose which. A window read in bursts by streaming readers – a ring several units read block by block – wants a word a cycle: mm_bram_port halves its port’s bandwidth. Of the two full-rate leaves, mm_bram_port_pipe is the one that keeps the memory’s output off the read data’s path altogether, so it holds wherever the read data goes next; mm_bram_port_p1 closes as measured above, where the next stop (a flop of the crossbar’s read channel, here) registers it, and costs about three words of flip-flops less. A window written and read a word at a time (a table, a mailbox) gains nothing from either: keep mm_bram_port.

The bus side’s timing

In pysim the bus side costs what its RTL does once the window has a record: with calib_dir set (a platform such as xczu48dr_250mhz_vitis2025_1), the window loads the timing record of window_memory(bram_leaf, mem_dwidth) – the MemoryMod (mm_bram_port) or FullRateMemoryMod (mm_bram_port_pipe) of the same width, whose RTL slot is the window’s port A. A read or write then costs init + per_word × n cycles of the window’s clock beyond the bus’s own cycle a word, the window serves one transaction at a time, and it stays busy the record’s turnaround after each (1 cycle, both leaves, fitted from HLS readers that request ahead). Measured (xsim 2025.1, 128 and 512 bits alike): a read 1 + 1·n with mm_bram_port, 2 + 0·n with mm_bram_port_pipe; a write 1 + 0·n with either. See Modeling for how the record is made. Without a record the bus side costs nothing, and the crossbar’s settings are all a read takes.

Credit in

A credit in is the producer end of a credit stream routed over the bus. The consumer kernel’s bus writer writes its cumulative count of words consumed here; the producer kernel receives each new count on its credit stream and knows how much room the consumer’s queue in has before it writes. You will rarely build one by hand: a kernel declares it, with CreditIn("u_crd", port="m_u") in its mm_views, and MmCreditStreamIF does the wiring.

crd = MemSlaveCreditIn(name="u_crd", sim=sim, clk=clk)
parameter default meaning
ctr_bits 16 the counter’s width; the stream to the kernel is this wide

The kernel side is the stream endpoint crd.m_out, joined to the credit half (crd_ep) of the kernel’s CreditStreamMasterIF. The kernel does nothing new: its write sleeps on that stream until the credit covers the burst.

The bus side is a single word written anywhere in the window — by a writer, not a host program, so there is no host endpoint for it.

  • A write never waits. The view is a latest-value register, not a queue: a count is cumulative, so the newest value is the whole truth and may replace one the kernel has not taken yet. (Contrast a register bank’s COMMIT, which waits for the kernel to take the previous config.) That is what lets a consumer return credit over a shared bus without ever stalling it.
  • The kernel sees fewer values when it lags, never older ones.
  • A read returns the current value — for debugging; nothing needs it.

RTL: CreditInView(name, axis, law=12); module mm_credit_in.v.