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.
- Test
- Driver
- Monitor
- DUT
- Clock / reset
- Transaction / TLM
- Analysis
- Data
- Clock
- Two tops
The HDL top (right) could be compiled into an emulator. The test top (left) stays on a workstation.
- Split each transactor
An untimed proxy on the left; a timed BFM, with every clock edge, on the right.
- 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.
| Question | |
|---|---|
| 1 | Why must an emulator-ready bench have two tops? |
| 2 | What is a split transactor? |
| 3 | What may the test side not contain? |
| 4 | How can we check the hardware side without an emulator? |
| 5 | What 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
| Word | Meaning |
|---|---|
| Co-emulation | A simulator and an emulator running one test together, joined by a link. |
| HDL top | The top module of the hardware side: the design, clocks, resets and BFMs. |
| Test top | The top module of the software side: the untimed test and the proxies. |
| BFM | Bus-functional model: here the timed half of a transactor, with tasks the proxy calls. |
| Proxy | The untimed half of a transactor, on the test side. |
| Back pointer | A handle by which a BFM calls a function of its proxy, for example to send a monitored transaction. |
| Untimed | With 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.
| Line | Side | Why |
|---|---|---|
| always #5 clk = ~clk; | HDL top | clock 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; | neither | a fixed delay; rewrite as edges in the BFM |
| if (DUT.u_core.pc == 32'h80) ... | neither | a cross-domain signal reference |
The Rules
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.
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.
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.
Rule 4: Cross the line only through the BFM's calls.
No signal or module reference across the two domains.
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.
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:
done <= 1;
line 46: unsynthesizable timing control (ignore with '--ignore-timing')
Design elaboration failed; see full log for detailsRule 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
This section looks ahead. None of it ran here.
Standard links
The Accellera SCE-MI standard defines the link between the two sides; the book names it.
UVM on both
Large benches keep UVM on the test side and put every agent's BFM in the HDL top.
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?
after pulse(3): count 3 at time 105 after pulse(2): count 5 at time 165Check Yourself
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.