Benches That Could Go into an Emulator

A bench can be written so that its hardware side could go into an emulator, while its tests stay on a workstation. The rules are strict, and checkable without an emulator.

You Will Be Able To

  • Split a bench into an HDL top and a test top, and say what goes in each.
  • Split a transactor into an untimed proxy and a timed BFM that talk through tasks and functions.
  • Write hardware-side code with no delays, and check it with a synthesis tool.
  • Say what this site can check of an emulator-ready bench, and what it cannot.
Lesson
V13.6
Time
26 min
Runs on
Your browser
Check
5 questions

A team keeps one bench for simulation and plans to move its tests onto an emulator later. Every #10 in its drivers will have to go. The question is how to write the bench now so that day is easy.

A Bench Split into a Hardware Side and a Software SideThe HDL top holds the design, the clock and the timed BFMs. The test top holds untimed proxies that call the BFMs' tasks.
  • Test
  • Driver
  • Monitor
  • DUT
  • Clock / reset
  • Transaction / TLM
  • Analysis
  • Data
  • Clock
A Bench Split Into a Hardware Side and a Software SideThe HDL top holds the design, the clock and the timed BFMs. The test top holds untimed proxies that call the BFMs' tasks. test Test andsequences classes, no waits driver Driver proxy untimed monitor Monitor proxy untimed driver Driver BFM tasks, clock edges monitor Monitor BFM samples on edges dut Design RTL clock reset Clock, reset made here transactionstask callcall backpinspinsclk
  1. test Test and sequencesclasses, no waits
    • transactions → Driver proxy
  2. dut DesignRTL
    • pins → Monitor BFM
  3. clock reset Clock, resetmade here
    • clk → Design
  4. driver Driver proxyuntimed
    • task call → Driver BFM
  5. driver Driver BFMtasks, clock edges
    • pins → Design
  6. monitor Monitor proxyuntimed
  7. monitor Monitor BFMsamples on edges
    • call back → Monitor proxy
  1. Two tops

    The HDL top (right) could be compiled into an emulator. The test top (left) stays on a workstation.

  2. Split each transactor

    An untimed proxy on the left; a timed BFM, with every clock edge, on the right.

  3. Calls across the line

    Proxies call BFM tasks; a monitor BFM calls back into its proxy. Only transactions cross.

Read the diagram as text
  • Test and sequences: classes, no waits
  • Driver proxy: untimed
  • Monitor proxy: untimed
  • Driver BFM: tasks, clock edges
  • Monitor BFM: samples on edges
  • Design: RTL
  • Clock, reset: made here
  • Test and sequences → Driver proxy: transactions
  • Driver proxy → Driver BFM: task call
  • Monitor BFM → Monitor proxy: call back
  • Driver BFM → Design: pins
  • Design → Monitor BFM: pins
  • Clock, reset → Design: clk

The split described by UVM-CB, "Testbench Acceleration through Co-Emulation" (dual top, split transactors, back pointers). Drawn for this page.

Before You Start

Read Emulation, Honestly and Hybrid: a Model Core With RTL Peripherals first. Drivers, monitors and proxies are UVM words: see From a Layered Bench to UVM.

Five questions this page answers
Question
1Why must an emulator-ready bench have two tops?
2What is a split transactor?
3What may the test side not contain?
4How can we check the hardware side without an emulator?
5What does this site still not check?

The Idea: Time Lives on One Side Only

In co-emulation, the design runs in the box and the test runs on a workstation. The two are separate machines joined by a link. Neither can see the other's signals; they can only exchange messages.

So everything that waits for a clock edge must be in the box, beside the design. Everything on the workstation must be untimed: it decides what to do next and asks the box to do it.

A driver is cut in two. The timed part, the BFM, drives pins edge by edge and must synthesize. The untimed part, the proxy, turns a sequence item into a call of a BFM task. The same split works in plain simulation, so one bench serves both.

New Words

New words on this page
WordMeaning
Co-emulationA simulator and an emulator running one test together, joined by a link.
HDL topThe top module of the hardware side: the design, clocks, resets and BFMs.
Test topThe top module of the software side: the untimed test and the proxies.
BFMBus-functional model: here the timed half of a transactor, with tasks the proxy calls.
ProxyThe untimed half of a transactor, on the test side.
Back pointerA handle by which a BFM calls a function of its proxy, for example to send a monitored transaction.
UntimedWith no delay and no wait on a clock edge or a fixed time; waits on abstract events are allowed.

The Smallest Example: Which Side Is Each Line On?

Sort these lines of a bench. Each belongs on one side only.

One driver, split
LineSideWhy
always #5 clk = ~clk;HDL topclock generation belongs with the design
req = item; bfm.write(req.addr, req.data);test top (proxy)a call, no time passes here
@(posedge clk) pin <= 1;HDL top (BFM task)a wait on an edge and a pin
#20 sel = 0;neithera fixed delay; rewrite as edges in the BFM
if (DUT.u_core.pc == 32'h80) ...neithera cross-domain signal reference

The Rules

  1. Rule 1: Two tops, two files.

    Synthesizable code in the HDL top; everything else in the test top. Shared parameters go in a package both import.

  2. Rule 2: The test side is untimed.

    No # delay, no wait on a clock edge, no wait for a fixed time on the test side.

  3. Rule 3: Split every transactor.

    A timed BFM with tasks and functions on the HDL side; an untimed proxy that calls them on the test side.

  4. Rule 4: Cross the line only through the BFM's calls.

    No signal or module reference across the two domains.

  5. Rule 5: Make the hardware side synthesize.

    Every BFM, monitor and generator on the HDL side follows synthesis rules, so a compiler can put it in the box.

  6. Rule 6: Keep the traffic small.

    Pass packed data, not objects, and as few calls as the protocol allows.

Sources for These Rules

UVM-CB, "Testbench Acceleration through Co-Emulation": the requirements, separate top levels, split transactors, back pointers and the BFM API.

The requirements are untimed verification code, two domains, no cross-domain references, packed data and small traffic.

That article describes one vendor's flow, with its own pragmas. Its subset also accepts some behavioural clock and reset code. This page keeps to the general rules.

Transactors must synthesize into the box to stay in step with the design: MEHTA-DV 12.4.

The transactor and its synthesis gate: tools/soc/fast-platforms/README.md, "The hybrid boundary". The synthesis flow: tools/synth-runner.mjs.

The Lab: Ask a Synthesis Tool

This site has no emulator compiler, but it has a synthesis tool. The hybrid's transactor, transactor.sv, went through the site's Yosys flow: accepted, 271 cells, 105 of them flip-flops.

Then the same file with one change, a delay on line 46:

The changed line, then what Yosys said.
done <= 1;

line 46: unsynthesizable timing control (ignore with '--ignore-timing')
Design elaboration failed; see full log for details

Rule 5 at work: the delay describes time no gate can hold, and the tool refuses the file. The co-emulation flow in the Cookbook allows behavioural delays only in marked clock and reset blocks. A transactor's logic must keep to its synthesizable subset.

The example below runs a two-top bench in Icarus. The test top only calls pulse() and read_count() of the BFM; every edge is inside the HDL top. The site's simulator elaborates one root module, so here the test top instantiates the HDL top. In co-emulation the two are separate roots; rule 4 is the same.

Why It Is Built This Way

Why may the test side not wait on a clock? Because in co-emulation the clock is in the box. A test-side wait on an edge needs a message every clock. The box would then run at the speed of the link.

Why tasks with clock waits in the BFM, when synthesis refuses waits? The emulator compiler in the Cookbook accepts a wider subset than plain synthesis. Its BFM tasks are written as implicit state machines. Our Yosys accepts no such task, so this site checks BFM tasks in simulation and plain modules, like the transactor, with Yosys.

Why one bench for both? Two benches drift apart. With the split, the same test runs in simulation today and could run in co-emulation later.

Traps

The first trap is a test that peeks at a design signal through a hierarchical path. It works in simulation. In co-emulation that signal is inside the box, and the path means nothing.

The second is a #1 left in a driver "to avoid a race". The test side must have no delay at all; the race must be solved by sampling on edges in the BFM.

The third is a monitor that sends every sample across the link. The link fills, and the box waits. A monitor in the box should send whole transactions.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. None of it ran here.

  1. Standard links

    The Accellera SCE-MI standard defines the link between the two sides; the book names it.

  2. UVM on both

    Large benches keep UVM on the test side and put every agent's BFM in the HDL top.

  3. Memories in the box

    Memory models for DDR and flash are written to run in the box beside the design.

Try It

Run it: the test top calls pulse(3) and pulse(2), and reads the counter after each.

Find every # in the file. Which top is each one in?

Change the pulse counts. Does the test top ever wait on a clock itself?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: after pulse(3): count 3 at time 105 after pulse(2): count 5 at time 165

Check Yourself

Predict the outputThe test now calls pulse(1) then pulse(4). What is the last line printed?
// The HDL side: clock, the design and a BFM whose tasks hold every wait on a clock edge.
module edge_counter(input logic clk, resetn, pin, output logic [7:0] count);
  logic last;
  always_ff @(posedge clk or negedge resetn)
    if (!resetn) begin last <= 0; count <= 0; end
    else begin last <= pin; if (pin && !last) count <= count + 1; end
endmodule

module pin_bfm(input logic clk, resetn, output logic pin, input logic [7:0] count);
  initial pin = 0;
  task automatic wait_reset();
    do @(posedge clk); while (!resetn);
  endtask
  task automatic pulse(input int n);             // n pulses, each one clock high and one clock low
    repeat (n) begin @(posedge clk) pin <= 1; @(posedge clk) pin <= 0; end
    @(posedge clk);                              // one more edge, so the counter has seen the last one
  endtask
  task automatic read_count(output logic [7:0] c);
    @(posedge clk) c = count;
  endtask
endmodule

module hdl_top;
  logic clk = 0, resetn = 0, pin;
  logic [7:0] count;
  always #5 clk = ~clk;                            // clock and reset belong to the HDL side
  initial #22 resetn = 1;
  edge_counter dut(.clk, .resetn, .pin, .count);
  pin_bfm bfm(.clk, .resetn, .pin, .count);
endmodule

// The test side: no delay, no clock edge. It only calls tasks of the BFM.
// (In co-emulation the two tops are separate roots. The site's simulator elaborates one root, so this one holds the other.)
module tb;
  hdl_top hdl();
  logic [7:0] seen;
  initial begin
    hdl.bfm.wait_reset();
    hdl.bfm.pulse(1);
    hdl.bfm.read_count(seen);
    $display("after pulse(1): count %0d at time %0t", seen, $time);
    hdl.bfm.pulse(4);
    hdl.bfm.read_count(seen);
    $display("after pulse(4): count %0d at time %0t", seen, $time);
    $finish;
  end
endmodule
ConceptWhy two tops?
ConceptWhat may the test side contain?
ConceptIn the lab, why did Yosys refuse the changed transactor?
ConceptWhat does this site not check?

Common Mistakes

Wrong Leave a # delay in a driver.

The test side must be untimed, and the hardware side must synthesize.

Fix Wait on clock edges inside a BFM task.

Wrong Read a design signal from the test through a hierarchical path.

In co-emulation the signal is inside the box.

Fix Have a monitor BFM call back into its proxy.

Wrong Keep two benches, one for each platform.

They drift apart.

Fix Split the transactors once; run the same bench in both.

Remember

  • An emulator-ready bench has an HDL top (design, clocks, BFMs) and an untimed test top.
  • Each transactor is split into a timed BFM and an untimed proxy that calls it.
  • Nothing crosses between the tops except calls of the BFM's tasks and functions.
  • Hardware-side modules must synthesize; Yosys checks that here. An emulator compiler is not available.

Practice

Report a problem with this page