Skip to content

Commit 12676e3

Browse files
committed
lib.dataflow supports the visualization of the dataflow by using pygraphviz.
1 parent 964bc38 commit 12676e3

File tree

11 files changed

+757
-20
lines changed

11 files changed

+757
-20
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,35 @@ Install on your platform. For exmple, on Ubuntu:
4242
sudo apt-get install iverilog
4343

4444
- Jinja2: 2.8 or later
45-
- pytest: 2.8.2 or later
46-
- pytest-pythonpath: 0.7 or later
4745

4846
Install on your python environment by using pip.
4947

50-
pip install jinja2 pytest pytest-pythonpath
48+
pip install jinja2
5149

5250
- Pyverilog: 1.0.1 or later
5351

5452
Install from pip:
5553

5654
pip install pyverilog
5755

56+
Options
57+
--------------------
58+
59+
- pytest: 2.8.2 or later
60+
- pytest-pythonpath: 0.7 or later
61+
62+
These softwares are required for the test of tests and examples.
63+
64+
pip install pytest pytest-pythonpath
65+
66+
- Graphviz: 2.38.0 or later
67+
- Pygraphviz: 1.3.1 or later
68+
69+
These softwares are required for graph visualization by lib.dataflow.
70+
71+
sudo apt-get install graphviz
72+
pip install pygraphviz
73+
5874
Install
5975
--------------------
6076

README.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,43 @@ Install on your platform. For exmple, on Ubuntu:
4646
sudo apt-get install iverilog
4747

4848
- Jinja2: 2.8 or later
49-
- pytest: 2.8.2 or later
50-
- pytest-pythonpath: 0.7 or later
5149

5250
Install on your python environment by using pip.
5351

5452
::
5553

56-
pip install jinja2 pytest pytest-pythonpath
54+
pip install jinja2
5755

58-
- Pyverilog: 1.0.0 or later
56+
- Pyverilog: 1.0.1 or later
5957

6058
Install from pip:
6159

6260
::
6361

6462
pip install pyverilog
6563

64+
Options
65+
-------
66+
67+
- pytest: 2.8.2 or later
68+
- pytest-pythonpath: 0.7 or later
69+
70+
These softwares are required for the test of tests and examples.
71+
72+
::
73+
74+
pip install pytest pytest-pythonpath
75+
76+
- Graphviz: 2.38.0 or later
77+
- Pygraphviz: 1.3.1 or later
78+
79+
These softwares are required for graph visualization by lib.dataflow.
80+
81+
::
82+
83+
sudo apt-get install graphviz
84+
pip install pygraphviz
85+
6686
Install
6787
-------
6888

examples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ run:
1414

1515
.PHONY: clean
1616
clean:
17-
rm -rf *.pyc __pycache__ parsetab.py *.out .cache
17+
rm -rf *.pyc __pycache__ parsetab.py *.out .cache tmp.v uut.vcd *.png *.dot
1818
find . -maxdepth 1 -type d |grep "./" | xargs -I {} make clean -C {}

examples/dataflow_example/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ check:
2626

2727
.PHONY: clean
2828
clean:
29-
rm -rf *.pyc __pycache__ parsetab.py *.out tmp.v uut.vcd
29+
rm -rf *.pyc __pycache__ parsetab.py *.out *.png *.dot tmp.v uut.vcd

examples/dataflow_example/dataflow_example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def mkMultAdd():
4545

4646
# generate always statement
4747
df.make_always()
48+
49+
# draw dataflow graph in png
50+
df.draw_graph()
4851

4952
return m
5053

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def read(filename):
2323
#package_data={ 'path' : ['*.*'], },
2424
install_requires=[ 'pyverilog>=1.0.1', 'Jinja2>=2.8' ],
2525
extras_require={
26+
'graph' : [ 'pygraphviz>=1.3.1' ],
2627
'test' : [ 'pytest>=2.8.2', 'pytest-pythonpath>=0.7' ],
2728
},
2829
)

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ run:
1414

1515
.PHONY: clean
1616
clean:
17-
rm -rf *.pyc __pycache__ parsetab.py *.out .cache tmp.v uut.vcd
17+
rm -rf *.pyc __pycache__ parsetab.py *.out .cache tmp.v uut.vcd *.png *.dot
1818
find . -maxdepth 1 -type d |grep "./" | xargs -I {} make clean -C {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=*.py
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: test
12+
13+
.PHONY: run
14+
run:
15+
$(PYTHON) $(OPT) $(TARGET) $(ARGS)
16+
17+
.PHONY: test
18+
test:
19+
$(PYTHON) -m pytest -vv
20+
21+
.PHONY: check
22+
check:
23+
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v
24+
iverilog -tnull -Wall tmp.v
25+
rm -f tmp.v
26+
27+
.PHONY: clean
28+
clean:
29+
rm -rf *.pyc __pycache__ parsetab.py *.out *.png *.dot tmp.v uut.vcd
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import sys
2+
import os
3+
4+
# the next line can be removed after installation
5+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
6+
7+
from veriloggen import *
8+
9+
def mkLed():
10+
m = Module('blinkled')
11+
clk = m.Input('CLK')
12+
rst = m.Input('RST')
13+
14+
x = m.Input('x', 32)
15+
vx = m.Input('vx')
16+
rx = m.Output('rx')
17+
18+
y = m.Input('y', 32)
19+
vy = m.Input('vy')
20+
ry = m.Output('ry')
21+
22+
z = m.Output('z', 32)
23+
vz = m.Output('vz')
24+
rz = m.Input('rz')
25+
26+
df = lib.Dataflow(m, 'df', clk, rst)
27+
28+
px = df.input(x, valid=vx, ready=rx)
29+
py = df.input(y, valid=vy, ready=ry)
30+
pz = df(px + py)
31+
pz.output(z, valid=vz, ready=rz)
32+
33+
df.make_always()
34+
35+
df.draw_graph('out.png')
36+
37+
return m
38+
39+
def mkTest(numports=8):
40+
m = Module('test')
41+
42+
# target instance
43+
led = mkLed()
44+
45+
# copy paras and ports
46+
params = m.copy_params(led)
47+
ports = m.copy_sim_ports(led)
48+
49+
clk = ports['CLK']
50+
rst = ports['RST']
51+
52+
x = ports['x']
53+
vx = ports['vx']
54+
rx = ports['rx']
55+
y = ports['y']
56+
vy = ports['vy']
57+
ry = ports['ry']
58+
z = ports['z']
59+
vz = ports['vz']
60+
rz = ports['rz']
61+
62+
uut = m.Instance(led, 'uut',
63+
params=m.connect_params(led),
64+
ports=m.connect_ports(led))
65+
66+
reset_done = m.Reg('reset_done', initval=0)
67+
68+
reset_stmt = []
69+
reset_stmt.append( reset_done(0) )
70+
reset_stmt.append( x(0) )
71+
reset_stmt.append( y(0) )
72+
reset_stmt.append( vx(0) )
73+
reset_stmt.append( vy(0) )
74+
reset_stmt.append( rz(0) )
75+
76+
lib.simulation.setup_waveform(m, uut)
77+
lib.simulation.setup_clock(m, clk, hperiod=5)
78+
init = lib.simulation.setup_reset(m, rst, reset_stmt, period=100)
79+
80+
nclk = lib.simulation.next_clock
81+
82+
init.add(
83+
Delay(1000),
84+
reset_done(1),
85+
nclk(clk),
86+
Delay(10000),
87+
Systask('finish'),
88+
)
89+
90+
91+
x_count = m.TmpReg(32, initval=0)
92+
y_count = m.TmpReg(32, initval=0)
93+
z_count = m.TmpReg(32, initval=0)
94+
95+
96+
xfsm = lib.FSM(m, 'xfsm', clk, rst)
97+
xfsm.add(vx(0))
98+
xfsm.goto_next(cond=reset_done)
99+
xfsm.add(vx(1))
100+
xfsm.add(x.inc(), cond=rx)
101+
xfsm.add(x_count.inc(), cond=rx)
102+
xfsm.goto_next(cond=AndList(x_count==10, rx))
103+
xfsm.add(vx(0))
104+
xfsm.make_always()
105+
106+
107+
yfsm = lib.FSM(m, 'yfsm', clk, rst)
108+
yfsm.add(vy(0))
109+
yfsm.goto_next(cond=reset_done)
110+
yfsm.add(vy(1))
111+
yfsm.add(y.add(2), cond=ry)
112+
yfsm.add(y_count.inc(), cond=ry)
113+
yfsm.goto_next(cond=AndList(y_count==10, ry))
114+
yfsm.add(vy(0))
115+
yfsm.make_always()
116+
117+
118+
zfsm = lib.FSM(m, 'zfsm', clk, rst)
119+
zfsm.add(rz(0))
120+
zfsm.goto_next(cond=reset_done)
121+
zfsm.goto_next()
122+
zinit= zfsm.current()
123+
zfsm.add(rz(1), cond=vz)
124+
zfsm.goto_next(cond=vz)
125+
for i in range(10):
126+
zfsm.add(rz(0))
127+
zfsm.goto_next()
128+
zfsm.goto(zinit)
129+
zfsm.make_always()
130+
131+
132+
m.Always(Posedge(clk))(
133+
If(reset_done)(
134+
If(AndList(vx, rx))(
135+
Systask('display', 'x=%d', x)
136+
),
137+
If(AndList(vy, ry))(
138+
Systask('display', 'y=%d', y)
139+
),
140+
If(AndList(vz, rz))(
141+
Systask('display', 'z=%d', z)
142+
)
143+
)
144+
)
145+
146+
return m
147+
148+
if __name__ == '__main__':
149+
test = mkTest()
150+
verilog = test.to_verilog('tmp.v')
151+
print(verilog)

0 commit comments

Comments
 (0)