Skip to content

Commit a28706c

Browse files
committed
stream_ringbuffer_multi and stream_scratchpad_multi
1 parent 4be546e commit a28706c

File tree

7 files changed

+430
-9
lines changed

7 files changed

+430
-9
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_ringbuffer_multi
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_ringbuffer_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: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
buf = strm.RingBuffer(a, length=128)
33+
34+
a0 = a
35+
a1 = a0.prev(1)
36+
a2 = a1.prev(1)
37+
38+
a3 = buf.read(-img_width)
39+
a4 = a3.prev(1)
40+
a5 = a4.prev(1)
41+
42+
a6 = buf.read(-img_width - img_width)
43+
a7 = a6.prev(1)
44+
a8 = a7.prev(1)
45+
46+
b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
47+
48+
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
49+
50+
def comp_stream(size, offset):
51+
strm.set_source('a', ram_a, offset, size * 3)
52+
strm.set_sink('b', ram_b, offset, size)
53+
strm.set_constant('img_width', size)
54+
strm.run()
55+
strm.join()
56+
57+
def comp_sequential(size, offset):
58+
for i in range(size):
59+
a0 = ram_a.read(i + offset)
60+
a1 = ram_a.read(i + offset + 1)
61+
a2 = ram_a.read(i + offset + 2)
62+
a3 = ram_a.read(i + offset + size)
63+
a4 = ram_a.read(i + offset + size + 1)
64+
a5 = ram_a.read(i + offset + size + 2)
65+
a6 = ram_a.read(i + offset + size + size)
66+
a7 = ram_a.read(i + offset + size + size + 1)
67+
a8 = ram_a.read(i + offset + size + size + 2)
68+
b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
69+
ram_b.write(i + offset, b)
70+
71+
def check(size, offset_stream, offset_seq):
72+
all_ok = True
73+
for i in range(size):
74+
st = ram_b.read(i + offset_stream)
75+
sq = ram_b.read(i + offset_seq)
76+
if vthread.verilog.NotEql(st, sq):
77+
all_ok = False
78+
if all_ok:
79+
print('# verify: PASSED')
80+
else:
81+
print('# verify: FAILED')
82+
83+
def comp(size):
84+
# stream
85+
offset = 0
86+
myaxi.dma_read(ram_a, offset, 0, size * 3)
87+
comp_stream(size, offset)
88+
myaxi.dma_write(ram_b, offset, 1024, size)
89+
90+
# sequential
91+
offset = size * 4
92+
myaxi.dma_read(ram_a, offset, 0, size * 3)
93+
comp_sequential(size, offset)
94+
myaxi.dma_write(ram_b, offset, 1024 * 2, size)
95+
96+
# verification
97+
check(size, 0, offset)
98+
99+
vthread.finish()
100+
101+
th = vthread.Thread(m, 'th_comp', clk, rst, comp)
102+
fsm = th.start(32)
103+
104+
return m
105+
106+
107+
def mkTest(memimg_name=None):
108+
m = Module('test')
109+
110+
# target instance
111+
led = mkLed()
112+
113+
# copy paras and ports
114+
params = m.copy_params(led)
115+
ports = m.copy_sim_ports(led)
116+
117+
clk = ports['CLK']
118+
rst = ports['RST']
119+
120+
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name)
121+
memory.connect(ports, 'myaxi')
122+
123+
uut = m.Instance(led, 'uut',
124+
params=m.connect_params(led),
125+
ports=m.connect_ports(led))
126+
127+
#simulation.setup_waveform(m, uut)
128+
simulation.setup_clock(m, clk, hperiod=5)
129+
init = simulation.setup_reset(m, rst, m.make_reset(), period=100)
130+
131+
init.add(
132+
Delay(1000000),
133+
Systask('finish'),
134+
)
135+
136+
return m
137+
138+
139+
def run(filename='tmp.v', simtype='iverilog', outputfile=None):
140+
141+
if outputfile is None:
142+
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out'
143+
144+
memimg_name = 'memimg_' + outputfile
145+
146+
test = mkTest(memimg_name=memimg_name)
147+
148+
if filename is not None:
149+
test.to_verilog(filename)
150+
151+
sim = simulation.Simulator(test, sim=simtype)
152+
rslt = sim.run(outputfile=outputfile)
153+
lines = rslt.splitlines()
154+
if simtype == 'verilator' and lines[-1].startswith('-'):
155+
rslt = '\n'.join(lines[:-1])
156+
return rslt
157+
158+
159+
if __name__ == '__main__':
160+
rslt = run(filename='tmp.v')
161+
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_scratchpad_multi
7+
8+
9+
def test(request):
10+
veriloggen.reset()
11+
12+
simtype = request.config.getoption('--sim')
13+
14+
rslt = thread_stream_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')

0 commit comments

Comments
 (0)