Skip to content

Commit d566a7a

Browse files
committed
A bug fix for Async stream execution via source_join()
1 parent 623f02a commit d566a7a

File tree

10 files changed

+420
-79
lines changed

10 files changed

+420
-79
lines changed

tests/extension/stream_/reduceadd/test_stream_reduceadd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@
194194
_reduceadd_data_6 <= _reduceadd_data_6 + _plus_data_3;
195195
end
196196
if(__delay_data_10) begin
197-
_reduceadd_count_6 <= (_reduceadd_count_6 == 5'sd8 - 1)? 0 : _reduceadd_count_6 + 1;
197+
_reduceadd_count_6 <= (_reduceadd_count_6 >= 5'sd8 - 1)? 0 : _reduceadd_count_6 + 1;
198198
end
199199
if(__delay_data_10 && (_reduceadd_count_6 == 0)) begin
200200
_reduceadd_data_6 <= 1'sd0 + _plus_data_3;
201201
end
202202
if(__delay_data_10) begin
203-
_pulse_data_9 <= _pulse_count_9 == 5'sd8 - 1;
203+
_pulse_data_9 <= _pulse_count_9 >= 5'sd8 - 1;
204204
end
205205
if(__delay_data_10) begin
206-
_pulse_count_9 <= (_pulse_count_9 == 5'sd8 - 1)? 0 : _pulse_count_9 + 1;
206+
_pulse_count_9 <= (_pulse_count_9 >= 5'sd8 - 1)? 0 : _pulse_count_9 + 1;
207207
end
208208
if(__delay_data_10 && (_pulse_count_9 == 0)) begin
209-
_pulse_data_9 <= _pulse_count_9 == 5'sd8 - 1;
209+
_pulse_data_9 <= _pulse_count_9 >= 5'sd8 - 1;
210210
end
211211
end
212212
end

tests/extension/stream_/reduceadd_valid/test_stream_reduceadd_valid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,19 @@
208208
_reduceadd_data_5 <= _reduceadd_data_5 + _plus_data_2;
209209
end
210210
if(_ivalid_0) begin
211-
_reduceadd_count_5 <= (_reduceadd_count_5 == 5'sd8 - 1)? 0 : _reduceadd_count_5 + 1;
211+
_reduceadd_count_5 <= (_reduceadd_count_5 >= 5'sd8 - 1)? 0 : _reduceadd_count_5 + 1;
212212
end
213213
if(_ivalid_0 && (_reduceadd_count_5 == 0)) begin
214214
_reduceadd_data_5 <= 1'sd0 + _plus_data_2;
215215
end
216216
if(_ivalid_0) begin
217-
_pulse_data_8 <= _pulse_count_8 == 5'sd8 - 1;
217+
_pulse_data_8 <= _pulse_count_8 >= 5'sd8 - 1;
218218
end
219219
if(_ivalid_0) begin
220-
_pulse_count_8 <= (_pulse_count_8 == 5'sd8 - 1)? 0 : _pulse_count_8 + 1;
220+
_pulse_count_8 <= (_pulse_count_8 >= 5'sd8 - 1)? 0 : _pulse_count_8 + 1;
221221
end
222222
if(_ivalid_0 && (_pulse_count_8 == 0)) begin
223-
_pulse_data_8 <= _pulse_count_8 == 5'sd8 - 1;
223+
_pulse_data_8 <= _pulse_count_8 >= 5'sd8 - 1;
224224
end
225225
end
226226
end

tests/extension/stream_/reduceadd_validready/test_stream_reduceadd_validready.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@
237237
_reduceadd_data_5 <= _reduceadd_data_5 + _plus_data_2;
238238
end
239239
if(_ivalid_0 && _tmp_0) begin
240-
_reduceadd_count_5 <= (_reduceadd_count_5 == 5'sd8 - 1)? 0 : _reduceadd_count_5 + 1;
240+
_reduceadd_count_5 <= (_reduceadd_count_5 >= 5'sd8 - 1)? 0 : _reduceadd_count_5 + 1;
241241
end
242242
if(_ivalid_0 && _tmp_0 && (_reduceadd_count_5 == 0)) begin
243243
_reduceadd_data_5 <= 1'sd0 + _plus_data_2;
244244
end
245245
if(_ivalid_0 && _tmp_0) begin
246-
_pulse_data_8 <= _pulse_count_8 == 5'sd8 - 1;
246+
_pulse_data_8 <= _pulse_count_8 >= 5'sd8 - 1;
247247
end
248248
if(_ivalid_0 && _tmp_0) begin
249-
_pulse_count_8 <= (_pulse_count_8 == 5'sd8 - 1)? 0 : _pulse_count_8 + 1;
249+
_pulse_count_8 <= (_pulse_count_8 >= 5'sd8 - 1)? 0 : _pulse_count_8 + 1;
250250
end
251251
if(_ivalid_0 && _tmp_0 && (_pulse_count_8 == 0)) begin
252-
_pulse_data_8 <= _pulse_count_8 == 5'sd8 - 1;
252+
_pulse_data_8 <= _pulse_count_8 >= 5'sd8 - 1;
253253
end
254254
end
255255
end

tests/extension/stream_/substream/test_stream_substream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,19 @@
269269
_reduceadd_data_14 <= _reduceadd_data_14 + __substreamoutput_data_11;
270270
end
271271
if(__delay_data_29) begin
272-
_reduceadd_count_14 <= (_reduceadd_count_14 == 5'sd8 - 1)? 0 : _reduceadd_count_14 + 1;
272+
_reduceadd_count_14 <= (_reduceadd_count_14 >= 5'sd8 - 1)? 0 : _reduceadd_count_14 + 1;
273273
end
274274
if(__delay_data_29 && (_reduceadd_count_14 == 0)) begin
275275
_reduceadd_data_14 <= 1'sd0 + __substreamoutput_data_11;
276276
end
277277
if(__delay_data_29) begin
278-
_pulse_data_17 <= _pulse_count_17 == 5'sd8 - 1;
278+
_pulse_data_17 <= _pulse_count_17 >= 5'sd8 - 1;
279279
end
280280
if(__delay_data_29) begin
281-
_pulse_count_17 <= (_pulse_count_17 == 5'sd8 - 1)? 0 : _pulse_count_17 + 1;
281+
_pulse_count_17 <= (_pulse_count_17 >= 5'sd8 - 1)? 0 : _pulse_count_17 + 1;
282282
end
283283
if(__delay_data_29 && (_pulse_count_17 == 0)) begin
284-
_pulse_data_17 <= _pulse_count_17 == 5'sd8 - 1;
284+
_pulse_data_17 <= _pulse_count_17 >= 5'sd8 - 1;
285285
end
286286
_plus_data_18 <= _reduceadd_data_14 + 11'sd1000;
287287
__delay_data_30 <= _pulse_data_17;

tests/extension/thread_/stream_pattern/thread_stream_pattern.py

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

veriloggen/stream/stypes.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,13 +1897,6 @@ def __init__(self, right, size=None, initval=None,
18971897
enable=None, reset=None, width=32, signed=True):
18981898

18991899
self.size = _to_constant(size) if size is not None else None
1900-
1901-
if (self.size is not None and
1902-
not isinstance(self.size, _Constant) and
1903-
not isinstance(self.size, _ParameterVariable)):
1904-
raise TypeError("size must be _Constant or _ParameterVariable, not '%s'" %
1905-
str(type(self.size)))
1906-
19071900
self.initval = (_to_constant(initval)
19081901
if initval is not None else _to_constant(0))
19091902

@@ -1957,7 +1950,7 @@ def _implement(self, m, seq, svalid=None, senable=None):
19571950
if self.size is not None:
19581951
count = m.Reg(self.name('count'),
19591952
size_data.bit_length() + 1, initval=0)
1960-
next_count_value = vtypes.Mux(count == size_data - 1,
1953+
next_count_value = vtypes.Mux(count >= size_data - 1,
19611954
0, count + 1)
19621955
count_zero = (count == 0)
19631956

@@ -1982,7 +1975,7 @@ def _implement(self, m, seq, svalid=None, senable=None):
19821975

19831976
# for Pulse
19841977
if not self.ops and self.size is not None:
1985-
value = (count == (size_data - 1))
1978+
value = (count >= (size_data - 1))
19861979

19871980
if self.reset is not None or self.size is not None:
19881981
reset_value = initval_data
@@ -1999,7 +1992,7 @@ def _implement(self, m, seq, svalid=None, senable=None):
19991992
% (str(op), str(type(reset_value))))
20001993

20011994
if not self.ops and self.size is not None:
2002-
reset_value = (count == (size_data - 1))
1995+
reset_value = (count >= (size_data - 1))
20031996

20041997
if self.enable is not None:
20051998
enable_cond = _and_vars(svalid, senable, enabledata)

0 commit comments

Comments
 (0)