Skip to content

Commit bda51d7

Browse files
committed
draw_graph is upgraded for latest thread.stream
1 parent d0ccc09 commit bda51d7

File tree

18 files changed

+848
-61
lines changed

18 files changed

+848
-61
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.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 .cache *.out *.png *.dot tmp.v uut.vcd
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
4+
import os
5+
import veriloggen
6+
import thread_stream_graph_scratchpad_multi
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_graph_scratchpad_multi.run(filename=None, simtype=simtype,
15+
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out')
16+
17+
verify_rslt = rslt.splitlines()[-1]
18+
assert(verify_rslt == '# verify: PASSED')
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import sys
4+
import os
5+
6+
# the next line can be removed after installation
7+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
8+
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))))
9+
10+
from veriloggen import *
11+
import veriloggen.thread as vthread
12+
import veriloggen.types.axi as axi
13+
14+
15+
def mkLed():
16+
m = Module('blinkled')
17+
clk = m.Input('CLK')
18+
rst = m.Input('RST')
19+
20+
datawidth = 32
21+
addrwidth = 10
22+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth)
23+
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
24+
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
25+
26+
strm = vthread.Stream(m, 'mystream', clk, rst)
27+
img_width = strm.constant('img_width')
28+
29+
counter = strm.Counter()
30+
31+
a = strm.source('a')
32+
a_addr = strm.Counter() - 1
33+
sp = strm.Scratchpad(a, a_addr, length=128)
34+
35+
a0 = a
36+
a1 = a0.prev(1)
37+
a2 = a1.prev(1)
38+
39+
a3_addr = a_addr - img_width
40+
a3 = sp.read(a3_addr)
41+
a4 = a3.prev(1)
42+
a5 = a4.prev(1)
43+
44+
a6_addr = a3_addr - img_width
45+
a6 = sp.read(a6_addr)
46+
a7 = a6.prev(1)
47+
a8 = a7.prev(1)
48+
49+
#b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
50+
b = strm.AddN(a0, a1, a2, a3, a4, a5, a6, a7, a8)
51+
52+
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
53+
54+
def comp_stream(size, offset):
55+
strm.set_source('a', ram_a, offset, size * 3)
56+
strm.set_sink('b', ram_b, offset, size - 2)
57+
strm.set_constant('img_width', size)
58+
strm.run()
59+
strm.join()
60+
61+
def comp_sequential(size, offset):
62+
for i in range(size - 2):
63+
a0 = ram_a.read(i + offset)
64+
a1 = ram_a.read(i + offset + 1)
65+
a2 = ram_a.read(i + offset + 2)
66+
a3 = ram_a.read(i + offset + size)
67+
a4 = ram_a.read(i + offset + size + 1)
68+
a5 = ram_a.read(i + offset + size + 2)
69+
a6 = ram_a.read(i + offset + size + size)
70+
a7 = ram_a.read(i + offset + size + size + 1)
71+
a8 = ram_a.read(i + offset + size + size + 2)
72+
b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
73+
ram_b.write(i + offset, b)
74+
75+
def check(size, offset_stream, offset_seq):
76+
all_ok = True
77+
for i in range(size - 2):
78+
st = ram_b.read(i + offset_stream)
79+
sq = ram_b.read(i + offset_seq)
80+
if vthread.verilog.NotEql(st, sq):
81+
all_ok = False
82+
if all_ok:
83+
print('# verify: PASSED')
84+
else:
85+
print('# verify: FAILED')
86+
87+
def comp(size):
88+
# stream
89+
offset = 0
90+
myaxi.dma_read(ram_a, offset, 0, size * 3)
91+
comp_stream(size, offset)
92+
myaxi.dma_write(ram_b, offset, 1024, size)
93+
94+
# sequential
95+
offset = size * 4
96+
myaxi.dma_read(ram_a, offset, 0, size * 3)
97+
comp_sequential(size, offset)
98+
myaxi.dma_write(ram_b, offset, 1024 * 2, size)
99+
100+
# verification
101+
check(size, 0, offset)
102+
103+
vthread.finish()
104+
105+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
106+
fsm = th.start(32)
107+
108+
try:
109+
strm.draw_graph()
110+
except:
111+
pass
112+
113+
return m
114+
115+
116+
def mkTest(memimg_name=None):
117+
m = Module('test')
118+
119+
# target instance
120+
led = mkLed()
121+
122+
# copy paras and ports
123+
params = m.copy_params(led)
124+
ports = m.copy_sim_ports(led)
125+
126+
clk = ports['CLK']
127+
rst = ports['RST']
128+
129+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
130+
memory.connect(ports, 'myaxi')
131+
132+
uut = m.Instance(led, 'uut',
133+
params=m.connect_params(led),
134+
ports=m.connect_ports(led))
135+
136+
#simulation.setup_waveform(m, uut)
137+
simulation.setup_clock(m, clk, hperiod=5)
138+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
139+
140+
init.add(
141+
Delay(1000000),
142+
Systask('finish'),
143+
)
144+
145+
return m
146+
147+
148+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
149+
150+
if outputfile is None:
151+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
152+
153+
memimg_name = 'memimg_' + outputfile
154+
155+
test = mkTest(memimg_name=memimg_name)
156+
157+
if filename is not None:
158+
test.to_verilog(filename)
159+
160+
sim = simulation.Simulator(test, sim=simtype)
161+
rslt = sim.run(outputfile=outputfile)
162+
lines = rslt.splitlines()
163+
if simtype == 'verilator' and lines[-1].startswith('-'):
164+
rslt = '\n'.join(lines[:-1])
165+
return rslt
166+
167+
168+
if __name__ == '__main__':
169+
rslt = run(filename='tmp.v')
170+
print(rslt)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.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 .cache *.out *.png *.dot tmp.v uut.vcd
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
4+
import os
5+
import veriloggen
6+
import thread_stream_graph_substream
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_graph_substream.run(filename=None, simtype=simtype,
15+
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out')
16+
17+
verify_rslt = rslt.splitlines()[-1]
18+
assert(verify_rslt == '# verify: PASSED')

0 commit comments

Comments
 (0)