Skip to content

Commit 6cd1689

Browse files
committed
initval of _Accumulator, such as ReduceAdd and Counter can be a Variable.
1 parent aaf1a10 commit 6cd1689

File tree

10 files changed

+484
-64
lines changed

10 files changed

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