rtl design in python - eindhoven university of technologyjhuisken/mmips/mmips_in_myhdl.pdf ·...

33
RTL design in python: porting the mMIPS Jos Huisken June 25 th , 2013

Upload: others

Post on 21-Feb-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

RTL design in python:porting the mMIPS

Jos Huisken

June 25th, 2013

Page 2: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

What is Python?

Page 3: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

What is Python?

• A general purpose programming language

• Growing in popularity

• Interpreted language (bytecode-interpretive)

• Multi-paradigm

• Clean object-oriented

• Functional – in the LISP tradition

• Structural (procedural-imperative)

• Extremely readable syntax

• Very high-level

• Lists

• Dictionaries (associative arrays)

• Extensive documentation

Page 4: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

What is MyHDL?

• A Python package which enables hardware description

• Open-source project

• Batteries included (more on this later)

Page 5: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Extends Python

• MyHDL is Python

• Using Python constructs to extend

• Object Oriented

• Signal, intbv

• Generators

• Micro-thread like, enables concurrency behavior

• Resumable functions that maintain state

• Decorators

• Meta-programming

• “Macro” mechanism

• Modifies a function / generator

• @always_seq and @always_comb

Page 6: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Why use MyHDL

• Manage Complex Designs

• New to Digital Hardware Design

• Scripting Languages Intensively Used

• Modern Software Development Techniques for Hardware Design

• Algorithm Development and HDL Design in a Single Environment

• Require Both Verilog and VHDL

• VHDL Too Verbose

• SystemVerilog Too Complicated

• You Been TCL’d too much

Page 7: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

What MyHDL is NOTNOTNOTNOT

• Not arbitrary Python to silicon

• Not a radically new approach

• Not a synthesis tool

• Not an IP block library

• Not only for implementation

• Not well suited for accurate time simulation

Page 8: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Abstraction Levels

System Level Algorithmic Level Register Transfer

Logic Level Transistor Level Geometry Level

x

x

NCO

Decimation

Filter

Decimation

FilterADC

ADC

sin cos

I

Q

@always_seq(clock.posedge,

reset=reset)

def hdl():

sum.next = a + b

AND

OR

Page 9: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Register Transfer

• Register Transfer Level (RTL) abstraction

• This is the commonly excepted description of mainstream HDLs: Verilog and VHDL

• Describes the operations between registers

• MyHDL operates at the Register Transfer Level (RTL)

• MyHDL extends Python for hardware description

Page 10: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Types

• intbv

• Bit vector type, an integer with bit vector properties

• Signal

• Deterministic communication, see it as a VHDL signal

• Convertible types• intbv

• bool

• int

• tuple of int

• list of bool and list of intbv

Page 11: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Generators

• A Python generator is a resumable function

• Generators are the core of MyHDL

• Provide the similar functionality as a VHDL process or Verilog always block

• yield in a generator

Page 12: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Python generator: Fibonacci

7 # function version

8 def fibon(n):

9 a = b = 1

10 result = []

11 for i in xrange(n):

12 result.append(a)

13 a, b = b, a + b

14 return result

15 fibon(8)

16 [1, 1, 2, 3, 5, 8, 13, 21]

7 # generator version

8 def fibon(n):

9 a = b = 1

10 result = []

11 for i in xrange(n):

12 yield a

13 a, b = b, a + b

14 for x in fibon(8):

15 print x,

16 1 1 2 3 5 8 13 21

Page 13: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Decorators

• MyHDL Decorators

“creates ready-to-simulate generators from local function definitions”

• @instance

• @always(sensitivity list)

• @always_seq(clock,reset)

• @always_comb

Page 14: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Python decorator7 @mydecorator

8 def myfunc():

9 return

10 # is equivalent to

11 def myfunc():

12 return

13 myfunc = mydecorator(myfunc)

7 def verbose(origfunc):

8 # make new func

9 def newfunc(*args, **kwargs):

10 print “entering”, origfunc.__name__

11 origfunc(*args, **kwargs)

12 print “exiting”, origfunc.__name__

13 return newfunc

14 @verbose

15 def myfunc(s):

16 print s

17 myfunc(‘hoi’)

18 entering myfunc

19 hoi

20 exiting myfunc

A decorator is a function (mydecorator)

that takes a function object as an

argument, and returns a function object

as a return value.

@mydecorator: just syntactic sugar

A decorator is a function (mydecorator)

that takes a function object as an

argument, and returns a function object

as a return value.

@mydecorator: just syntactic sugar

Page 15: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Flow

myhdl package

myhdl

simulator

myhdl

conversion

Verilog / VHDL

Verilog simulation

RTL synthesis

gates

ICFPGA

cosimVCD

wave

modeling RTLverification

import myhdl

python source

python run-time (cpython, pypy)

python compiler tools

verificationresults

architecturetrade-offs

statistics

Page 16: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

MyHDL Conversion

• MyHDL has a convertible subset

• Convert to Verilog

• Convert to VHDL

• Pragmatic

• Standard FPGA / ASIC flow after conversion

Page 17: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Anatomy of a MyHDL Module

ports and parametersmodule name

sequential block

return list of generators

generator name

logic for the block

event definition

elaboration code

Page 18: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Simple adder in myhdl

Page 19: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

A register

Page 20: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

ALU waveform, using gtkwave

Page 21: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Verilog co-simulation

• Icarus Verilog

• Cadence ncsim

• Cadence ncsim, CMOS90 netlist

Select icarus/verilog implementation:

Page 22: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Generated: add.v

Page 23: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Single cycle mini-mini MIPS Multi cycle mini MIPS

mMIPS in MyHDL

……

Page 24: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Ecosystem

import pylab

import matplotlib

Page 25: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Digital Filter

z-1

z-1

z-1

z-1

+x[n] y[n]b0

b1

b2

a1

a2

1.23T

2.46

2.46

2.46

2.46

2.46

1.232.46

Page 26: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

IIR Type I Digital Filter1 def m_iir_type1(clock,reset,x,y,ts,B=None,A=None):

2 # make sure B and A are ints and make it a ROM (tuple of ints)

3 b0,b1,b2 = map(int,B)

4 a0,a1,a2 = map(int,A)

5

6 ffd = [Signal(intbv(0, min=x.min, max=x.max)) for ii in (0,0)]

7 fbd = [Signal(intbv(0, min=x.min, max=x.max)) for ii in (0,0)]

8 # intermidiate result, resize from here

9 ysop = Signal(intbv(0, min=dmin, max=dmax))

10

11 @always_seq(clock.posedge, reset=reset)

12 def hdl():

13 if ts:

14 ffd[1].next = ffd[0]

15 ffd[0].next = x

16

17 fbd[1].next = fbd[0]

18 fbd[0].next = ysop//Am # truncate (>>)

19

20 # extra pipeline on the output at clock

21 ysop.next = (b0*x) + (b1*ffd[0]) + (b2*ffd[1]) - \

22 (a1*fbd[0]) - (a2*fbd[1])

23

24 # truncate to the output word format

25 y.next = ysop//Am # truncate (>>)

26

27 return hdl

Page 27: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Simulation

Page 28: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Test Frameworks

• Test frameworks are easy

• Enables new levels or reuse

• Test Driven Design (TDD)

• Existing test environments

• py.test

• nose

• unittest

Page 29: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Example: fpgalink

• Test code

• Application code

• Host interface software

• Connect the host software to the DUT

• Host driver + USB controller

• FPGA logic (HDL)

• External models and checkers

• Physical transducers

https://github.com/cfelton/minnesota

FPGA Logic

test

app

host SW

adapters+

models

fgpalink

logic

models

libfpgalinkUSB

controller

checkerslogic

logic

logic

5 6

7

4

32

1

transducers

8

Page 30: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Conclusion

• Python • Easy to learn

• Batteries included

• MyHDL• Hardware description in Python

• Powerful environment, ecosystem

• Verification simplified and fun

• mMIPS• Ported from SystemC

• Simulated and Co-Simulated, not fully verified

• Synthesized: ISE (untested) and Cadence rc (co-simulated)

• Python: allows (…) matlab style interaction

Page 31: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Short MyHDL History

• Jan Decaluwe

• Creator of MyHDL

• Founder & Board Member Easic

• Created MyHDL between 2002-2003

• First Release on SourceForge Sep 30, 2003

www.programmableplanet.com

MyHDL ASIC

http://www.jandecaluwe.com/hdldesig

n/digmac.html

Page 32: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Acknowledgement

• You guys

• for hosting and providing the mMips

• Christopher Felton

• Several slides came from him!

Page 33: RTL design in python - Eindhoven University of Technologyjhuisken/mmips/mMips_in_Myhdl.pdf · python run-time (cpython, pypy) python compiler tools verification results architecture

Resources

• http://www.myhdl.org

• http://www.fpgarelated.com/blogs-1/nf/Christopher_Felton.php

• And an invitation to join (still) password protected:

https://[email protected]/huisken/mmips

?? Any Further Questions ??