XSI simulation components

Python DES and XSI simulation

A concurrent design is typically simulated in two quite different ways.

  • Python DES (pysim). A discrete-event simulation of any collection of SimObjs: the HwModules of the design, and anything else the evaluation needs. A channel estimator, for example, can be simulated together with a wireless channel model and a traffic source. Time advances from event to event, not clock by clock, so it runs fast, and a module can be described at whatever level of detail the question needs. It is not meant to be cycle-accurate. It is where a design is explored, compared, and evaluated as part of a larger system.

  • XSI simulation. The hardware itself — the Verilog that Vitis synthesizes, plus any hand-written Verilog beside it — simulated cycle by cycle in Vivado’s simulator, xsim. XSI (the Xilinx Simulator Interface) loads the compiled design as a shared library, so a C++ program can set its input pins, advance the clock, and read its output pins. Everything outside the hardware is a bus-functional model (BFM): a C++ cycle model of one participant — a host, a stream source, a memory — that speaks the pin-level protocol (AXI-Stream valid/ready handshakes, AXI4 bursts) on every cycle.

Why XSI rather than Vitis C/RTL co-simulation: co-simulation drives a kernel through its ap_start / ap_done handshake, and a free-running kernel has none — it never starts and never returns. Driving the pins directly works for any design, measures exact cycle counts, and lets the models around the hardware run concurrently with it, as they would on a board.

The price is that an XSI simulation is more restricted and slower than pysim: every object in it needs a cycle-level realization. The rest of this page is about what those realizations are and how they fit together.

What an XSI simulation is made of

An XSI simulation runs a DUT and a testbench around it, cut from one Python graph:

  • The DUT is what will be synthesized. Its Verilog, the RTL top, is one module, and it is what xsim elaborates. The same hardware can later be packaged as one or more IP blocks and included in, say, a Vivado project.
  • The testbench is every model around the DUT, each driving or answering some of its pins. These modules are not synthesized.

mem_copy as a system with no crossbar. A dotted box, the HwSystem mem_copy_system(), holds everything. Inside it, a solid box is the DUT: the MemCopy kernel alone, one sub-top in a dashed box, made of three blue Vitis HLS tasks -- a Sequencer feeding a MemRStream and a MemWStream, with a data stream from the reader to the writer. Outside the DUT, in tan, the testbench: a command driver (StreamDriver) whose stream enters the Sequencer, a completion sink (StreamSink) fed by the MemWStream, and a memory (MemoryMod) answering the reader's m0_axi and the writer's m1_axi. A caption says each port leaving the DUT is answered by a testbench model: AxisMaster and AxisSlave for the driver and sink, one FlatMemory behind both m_axi groups.

The picture is mem_copy, the kernel-scale twin of the system picture in Waveflow Architecture, in the same colours. At either scale the graph is an HwSystem whose dut() names the DUT, and everything else is testbench. mem_copy is one kernel and no crossbar: its kernel’s four ports (two streams, two m_axi bundles) leave the top, and each is answered by a testbench model. It runs through the system flow (mem_copy_system_build.py) and reproduces the single-kernel gate exactly: 3000 cycles.

mem_copy builds its modules directly on one simulation and names the kernel as the DUT, HwSystem(sim, dut) (The system), as every curated example now does. A few demos still describe their graph the older way, a GraphSystem: one composite FreeRunMod testbench class whose children the cut splits. The roles below are the same in both.

Which modules are inside the DUT is decided per build: that is the cut. How the graph becomes a running simulation is the flow steps page.

Three kinds of module

Every module in the XSI simulation top plays exactly one of three roles, and each role has its own realization in the XSI simulation:

Python role the module declares target in the XSI simulation
kernel module a run_iter body, or a hand-written body via kernel_task() composite_kernel a task in the Vitis kernel: generated HLS C++, synthesized to Verilog
RTL module rtl_module(), naming a .v rtl_module hand-written Verilog, used as is
BFM module bfm_model(), naming a C++ model class xsi_bfm_model a C++ BFM

Kernel modules and RTL modules make up the RTL top; BFM modules make up the testbench.

A role is not a property of a class. The same class can be a kernel module in one build and a BFM module in another — which is the cut.

check(obj, target) reports whether a module can take a given role.

So a module can be a BFM module exactly when it has a C++ BFM — and in principle that is any module someone is willing to write a cycle model for. The BFMs are XsiSimObjs in xsi_bfm.h, and each implements the same per-cycle protocol:

phase when what a model does
sample() clock low read the design’s outputs; decide which handshakes complete this cycle
update() after the rising edge apply those handshakes; advance its state machine
drive() after update present its outputs for the next cycle

Splitting sample from update is what lets every model see the same cycle: a handshake is decided from values sampled before the edge and applied after it, whatever order the models run in.

Where each pysim object lands

Each kind of object has a usual role:

pysim object usual role in the XSI simulation
a FreeRunMod kernel (e.g. MmFir) kernel module an hls::task in the Vitis kernel
MemRStream / MemWStream kernel module an hls::task owning an m_axi port
T2pBram RTL module bram_t2p
MemSlaveWStream / MemSlaveRStream / MemSlaveRegBank / MemSlaveBramWindow RTL module an adaptor leaf (mm_queue_in, …)
MemSlaveAdaptor RTL module one axi_slave_front and a generated decoder
MemoryMod BFM module FlatMemory serving AxiMmReadSlave / AxiMmWriteSlave
StreamDriver / StreamSink BFM module AxisMaster / AxisSlave
a host process holding an MMIFMaster BFM module AxiMmMaster

One thing in an RTL top is not a module: the AXI crossbar. In pysim it is an interface, AXIMMCrossBarIF, joining modules; in the RTL top it becomes vendor IP, AMD’s axi_crossbar, generated by create_ip — beside the hand-written Verilog, not part of it.

Moving the cut: what it costs today

Which modules are inside the Vitis kernel is a property of the build, not of the class — so in principle a module moves between the kernel and the testbench by changing only the cut. The capability is real in the graph and not yet real in the artifact, and it is worth being precise about which is which.

MemRStream genuinely is generated at two cuts: as its own top (examples/interleaver/gen/mem_r_stream.cpp, XSI gate 151) and as a task inside mem_copy (examples/mem_copy/gen/mem_copy.cpp, gate 3000). But those two are two protocols, not one module at two cuts: the standalone one reads an MRCmd and bursts; the composite one reads a MemRCmd and relays fwd_bursts opaque bursts first. inband is a HwParam — a build-time parameter of the design — precisely because it selects a protocol, and the framing follows from the protocol rather than the other way round.

Holding the protocol fixed and moving only the cut does not work yet. Ask the generator for the in-band reader as a standalone top and it will emit this:

void mem_r_stream(hls::stream<ap_uint<64> >& s_cmd, ...) {          // plain words at the boundary
    hls_thread_local hls::task t0(mem_r_stream_framed_task<64>, s_cmd, m_mem, m_out);
}                                          // ...but the body's signature demands framed_word<64>

That does not compile, and nothing in Python catches it. The task body’s argument word types are not part of kernel_task()’s contract, so the generator cannot check them — and the obvious proxy does not work either: mem_copy’s own s_done endpoint is has_tlast=True in Python while mem_w_stream_framed_done_task declares it a plain ap_uint stream, and that design is the 3000 gate. The Python framing flag and the C++ word type already disagree on a working design.

Making the cut free in the artifact means teaching kernel_task() about the cut, and for framed ports that is built: KernelTask(..., framed=ports) makes each listed port’s word type a template parameter the generator supplies – axi4s_word at a top, framed_word inside a composite – so one body serves a module alone and inside a composite (One body, wherever it sits). The in-band reader above predates it.

See also

  • Memory-mapped slave adaptor — the adaptor’s views, their semantics, and the ordering guarantee.
  • MM Interfaces — AXIMMCrossBarIF in pysim, and axi_crossbar at RTL.
  • Flow steps — how the XSI simulation top becomes a running simulation.
  • mm_fir — every piece in one design: a Vitis kernel, an adaptor and a crossbar in the RTL top, a host program in the testbench.
  • Memory-mapped slave adaptor — why a kernel can drive the bus from inside the Vitis kernel but is reached through an adaptor in the RTL top.