Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe...

56
Verilog Simulation Tools &Verification

Transcript of Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe...

Page 1: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Verilog Simulation

Tools &Verification

Page 2: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Outline

NC-Verilog

nLint

nWave

Nicotb

2

Page 3: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

NC-Verilog

3

Page 4: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Introduction to NC-Verilog

The Cadence® NC-Verilog® simulator is a Verilog digital

logic simulator.

We can use NC-Verilog to

Compiles the Verilog source files.

Elaborates the design and generates a simulation snapshot.

Simulates the snapshot.

4

Page 5: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Before Using NC-Verilog

Source the environment settings of CAD tools.

If you try entering the command "ncverilog" but it turns

out "command not found," it means there's something

wrong with the "*.cshrc" file or the software license is out

of date.

tool 2

5

source /usr/cad/cadence/CIC/incisiv.cshrc

Page 6: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Running Verilog

Run the Verilog simulation:

"+access+r" is added to enable waveform file dumping.

*.fsdb has smaller file size than *.vcd. But $fsdbDumpfile

cannot work without sourcing verdi.cshrc.

6

ncverilog testbench.v design.v +access+r

or

Page 7: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Simulation Results

Check the simulation result to see if the Verilog design is

finished correctly.

7

Page 8: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

nLint

8

Page 9: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Introduction to nLint

nLint is a comprehensive HDL design rule checker fully

integrated with the Debussy debugging system

(Developed by SpringSoft).

We can use nLint to check the coding style of our design

and if it is synthesizable.

9

Page 10: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Start nLint

Type the following command:

The token "&" enable you to use the terminal while nLint is

running in the background.

No gui command

10

nLint -gui &

Just ignore this warning.

nLint design.sv -sv -out screen

Page 11: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Specify the Design File

11

1

Page 12: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

12

1

2

3

4

5

Page 13: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Start Checking

13

1

Page 14: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

14

Not all the warnings or errors are valuable.

Page 15: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

nWave

15

Page 16: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Introduction to nWave

nWave is one of the best waveform (*.vcd or *.fsdb)

viewer.

We can debug easily by checking the waveform file

dumped during simulation.

16

Page 17: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Start nWave

Type the following command:

Also, the token "&" enable you to use the terminal while

Verdi is running in the background.

17

nWave &

Just ignore this warning.

Page 18: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Open the FSDB File

18

1

Page 19: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

19

1

2

3

Page 20: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Choose Signals

20

1

Page 21: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

21

Choose signals we

are interested in.

1

2

3 4

Page 22: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Browse the Whole Waveform

22

1

Page 23: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Browse the Specified Interval

23

press & drag

Page 24: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

24

Page 25: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Search for Specified Signal

25

1

2 34,5,…

Page 26: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

26

cursor position

(Search by rising oe)

Jump to the cursor position (Used when we are lost)

Page 27: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Change Sign Representation

27

1

2

3

Page 28: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Change Radix Representation

28

2

1

3

4

Page 29: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Leading zeros

29

Page 30: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Change Signal Position

30

1

2

Press middle mouse button,

drag and then drop.

Page 31: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Signal Aliasing

31

1

2

3

4

Page 32: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

32

1

2

3

Note that signal aliasing is a strict one-to-

one correspondence so the value

represented in the viewer must exactly

represent what format your filter expects.

(e.g., binary, hexadecimal)

6

4

5

Page 33: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

33

Page 34: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Reload the Waveform

Remember to reload the waveform whenever finishing

another Verilog simulation.

Shift+L

34

1

Page 35: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Nicotb

35

Page 36: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

UVM (Universal Verfication Methodology).

(We usually call this overall platform as testbench.)

What Forms Verification?

36

https://verificationacademy.comGenerate Golden Data Your RTL

Drive data to input ports

Monitor output ports and collect data

Page 37: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

The non-RTL parts can be implemented without Verilog!

This is usuallyed called co-simulation (co-sim).

The Non-RTL Parts

37

Page 38: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Instantiate (make a copy of) your module.

Driver to send data.

Monitor to receive and collect them.

Driver and Monitor might follow specific protocols.

The collected data are compared by Scoreboard.

Golden (Mostly text file in Verilog, or programmatically when co-simed.)

Generated by your RTL module and collected by Monitor.

Brief Conclusions - A Testbench Must

38

Page 39: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Verilog provide external C accesses through VPI.

https://en.wikipedia.org/wiki/Verilog_Procedural_Interface

Based on C, people develops Java, Python... versions.

AFAIK, there are quite a lot Python based frameworks.

myhdl: https://github.com/myhdl/myhdl

cocotb: https://github.com/potentialventures/cocotb

nicotb: https://github.com/johnjohnlin/nicotb

No Need for Verify RTL with Verilog

39

We focus on this today.

Page 40: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Bridging Python and Verilog (Events)

Add these lines in Python

○ rst_out_ev, ck_ev = CreateEvents(["rst_out", "ck_ev",])

Add this lines in Verilog

○ `Pos(rst_out, rst)`PosIf(ck_ev, clk, rst)

This means, whenever a clk posedge in Python, ck_ev is triggered

Mostly your submodules use 1 reset and clock and you just copy it.

That is,

Python yield ck_ev = Verilog @posedge clk

However, simply writing yield in Python doesn't make thing easier.

We will explain later.

40

Page 41: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Bridging Python and Verilog (Wires)

● API to connect Verilog wires

○ my_data_bus = CreateBus((

("", "a_signal", (4,2)),

("dut", "sig"),

))

The Verilog to be connected

○ logic [7:0] a_signal [4][2];

DUT my_dut(

.clk(clk),

.sig(sig)

)

41

hierarchy: toplevel → ""

name: a_signal

shape: (4,2)

Page 42: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Bridging Python and Verilog (Wires)

API to connect Verilog wires

○ my_data_bus = CreateBus((

("", "a_signal", (4,2)),

("dut", "sig"),

))

The Verilog to be connected

○ logic [7:0] a_signal [4][2];

DUT dut(

.clk(clk),

.sig(sig)

)

42

hierarchy: "dut" (nested: "dut.a.b")

name: sig

shape: not a array

Page 43: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Some Notes

Make use of Python unpack easily.

a = CreateBus(A)b = CreateBus(B)c = CreateBus(C)a, b, c = CreateBuses([A, B, C])

● This is the method of Nicotb, every framework has its method connecting

Verilog to Python (or whatever).

43

Page 44: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

For example, your code:

○ module Dut(

input clk,

input rst,

input irdy,

output logic iack,

input [10:0] iint,

output logic ordy,

input oack,

output logic [10:0] oint

);

You can test every module with the same API.

Interface Reuse → Testbench Reuse

44

DutInput Output

Dataflow graph.

Page 45: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

First, you need to create the buses

irdy = CreateBus((("dut", "irdy")))iack = CreateBus((("dut", "iack")))iint = CreateBus((("dut", "iint")))ordy = CreateBus((("dut", "ordy")))oack = CreateBus((("dut", "oack")))oint = CreateBus((("dut", "oint")))

Then, construct the classes in Python.

master = TwoWire.Master(irdy, iack, iint, ck_ev, A=1, B=5)slave = TwoWire.Slave(

ordy, oack, oint, ck_ev, callbacks=[test.Get])

Convert Bus into Protocol

45

Page 46: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Generate golden data for Scoreboard (not today's main issue).

Ns = np.array([0,8,7], dtype=np.int32)# this create a column vector [0, 0, 1, 2, ..., 8, 0, 1, ..., 7]golden = np.concatenate([

np.arange(N+1, dtype=np.int32) for N in Ns])[:,np.newaxis]test.Expect((golden,))

What should I Expect?

Check at Scoreboard

46

Page 47: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Look at the data bus.

ordy = CreateBus((("dut", "ordy")))oack = CreateBus((("dut", "oack")))oint = CreateBus((("dut", "oint")))

Slave put that to Scoreboard.

st = Stacker(1+9+8, [bg.Get]) # PS: 1+9+8+=18bg = BusGetter(callbacks=[st.Get])slave = TwoWire.Slave(

ordy, oack, oint, ck_ev, callbacks=[bg.Get])

oint is a bus with one scalar (aka, not an array), so you get a tuple of size ([18,

1],).

Data Format in Nicotb

47

The actual code is slightly more

complex than above pages, while

you can just copy and modify.

Page 48: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Look at the data bus.

oint = CreateBus((("dut", "aaa")("dut", "bbb", (1,))("dut", "ccc", (12,3))

))

In this example, the tuple size is ([18, 1], [18, 1], [18, 12, 3]).

Data Format in Nicotb

48

Page 49: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Look at the data bus.

golden = np.concatenate([np.arange(N+1, dtype=np.int32) for N in Ns

])[:,np.newaxis]test.Expect((golden,))

golden is a tuple of size ([18, 1],).

np.concatenate generate a array of size [18,], namely a row vector.

The [:, np.newaxis] is the standard method converting Numpy row vector to a

column vector (vertical one).

Back to Our Example

49

Page 50: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Prepare the RTL for design under test (DUT).

Script for loading Python automatically (Makefile).

SystemVerilog wrapper.

Python testbench.

Prepare input data and golden (it's your task).

Send the data.

Check the data at scoreboard.

We are Almost Done!

50

OO

O

OX

O

OX

O O

O

Page 51: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Drive Verilog Wire In Python (Quite Easy!)

master = TwoWire.Master(irdy, iack, iint, ck_ev, A=1, B=5)values = master.valuesdef it():

for N in Ns:values.iint[0] = Nyield values

yield from master.SendIter(it())

yield from master.SendIter(it(), latency=100)

51

Access data bus by name

values.iint is a Numpy array of size (1,)

This randomly drive the input.

This drive data every 100 cycles.

Probability = A/B (default = 1/5)

Page 52: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Note

values = master.valuesdef it():

for N in Ns:values.iint[0] = Nyield values

yield from master.SendIter(it())yield from master.SendIter(it(), latency=100)

52

This part is only Python generator syntax,

it has no relationship with waiting Verilog

posedge!!!

Every 100 cycles (ignore probability)

Page 53: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

Prepare a Verilog Wrapper

`Pos(rst_out, rst)`PosIf(ck_ev, clk, rst)

always #1 clk = ~clk;initial begin

clk = 0;rst = 1;#1 $NicotbInit();#11 rst = 0;#10 rst = 1;#1000 $display("Timeout");$NicotbFinal();$finish;

end

assign oack = ordy && ocanack;Dut dut(clk,rst,irdy,iack,iint,ordy,oack,oint);

53

Declare your module here!

While you might not understand it,

this template requires almost no

modifications!

Declare your module here!

Page 54: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

(Prepare a Makefile)

NICOTB=~/nicotb/libIRUN=/opt/CAD/INCISIV/cur/tools.lnx86/bin/64bit/irun

%: %.svGLOG_logtostderr=1 \TEST=$(if $(TEST),$(TEST),$@) \TOPMODULE=$(if $(TOPMODULE),$(TOPMODULE),$@) \PYTHONPATH=$(NICOTB)/python:`pwd` \$(IRUN) +access+rw -loadvpi $(NICOTB)/cpp/nicotb.so:VpiBoot \$(NICOTB)/verilog/Utils.sv $<

54

Modify according to your path

(irun = ncverilog)

You must prepare XXX_test.py and XXX_test.sv under current directory

(see previous pages). Also, the top level testbench module is XXX_test.

Then, just type make XXX. The lab in these days is an example.

Page 55: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

● Introduce the idea behind SystemVerilog UVM.

With Python, you can do the same thing much easily.

We introduce Nicotb today.

Document: https://johnjohnlin.github.io/nicotb/

And there are many choices.

myhdl: https://github.com/myhdl/myhdl

cocotb: https://github.com/potentialventures/cocotb

Conclusions

55

Page 56: Verilog Simulation & Debugging Toolsmedia.ee.ntu.edu.tw/Crash_course/2019/RTL_verification.pdfThe collected data are compared by Scoreboard. Golden (Mostly text file in Verilog, or

The End