Skip to content

Commit 1865310

Browse files
committed
Merge branch 'feature_stream_update' into develop
2 parents 8757668 + fe82996 commit 1865310

File tree

11 files changed

+880
-22
lines changed

11 files changed

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

0 commit comments

Comments
 (0)