Skip to content

Commit 44d6283

Browse files
committed
Updated examples_obsolete for the parallel pytest with xdist.
1 parent 592c46b commit 44d6283

25 files changed

+102
-76
lines changed

examples_obsolete/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ run:
1414

1515
.PHONY: clean
1616
clean:
17-
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
17+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v *.vcd
1818
find . -maxdepth 1 -type d | grep "./" | xargs -I {} make clean -C {}

examples_obsolete/dataflow_example/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ check:
2626

2727
.PHONY: clean
2828
clean:
29-
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v *.vcd

examples_obsolete/dataflow_example/dataflow_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def mkTest(numports=8):
6262
reset_stmt.append( yvalid(0) )
6363
reset_stmt.append( zready(0) )
6464

65-
simulation.setup_waveform(m, uut)
65+
vcd_name = os.path.splitext(os.path.basename(__file__))[0] + '.vcd'
66+
simulation.setup_waveform(m, uut, dumpfile=vcd_name)
6667
simulation.setup_clock(m, clk, hperiod=5)
6768
init = simulation.setup_reset(m, rst, reset_stmt, period=100)
6869

examples_obsolete/dataflow_example/test_dataflow_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
reg reset_done;
4242
4343
initial begin
44-
$dumpfile("uut.vcd");
44+
$dumpfile("dataflow_example.vcd");
4545
$dumpvars(0, uut);
4646
end
4747

examples_obsolete/dataflow_fft4/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ check:
2626

2727
.PHONY: clean
2828
clean:
29-
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v *.vcd

examples_obsolete/dataflow_fft4/dataflow_fft4.py

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@
1010
import veriloggen.dataflow as dataflow
1111
import veriloggen.types.fixed as fixed
1212

13-
#-------------------------------------------------------------------------------
13+
# -------------------------------------------------------------------------------
14+
15+
1416
def complex_add(x, y):
1517
a = x[0]
1618
b = x[1]
1719
c = y[0]
1820
d = y[1]
1921
return (a + c), (b + d)
2022

23+
2124
def complex_sub(x, y):
2225
a = x[0]
2326
b = x[1]
2427
c = y[0]
2528
d = y[1]
2629
return (a - c), (b - d)
2730

31+
2832
def complex_mult(x, y):
2933
a = x[0]
3034
b = x[1]
@@ -39,22 +43,25 @@ def complex_mult(x, y):
3943
im = ad + bc
4044
return re, im
4145

46+
4247
def radix2(x, y, c):
4348
d0 = complex_add(x, y)
4449
d1 = complex_sub(x, y)
45-
r0 = d0 # as-is
50+
r0 = d0 # as-is
4651
r1 = complex_mult(d1, c)
4752
return r0, r1
4853

49-
#-------------------------------------------------------------------------------
54+
# -------------------------------------------------------------------------------
55+
56+
5057
def fft4(din):
51-
w = [ (1, 0), (0, -1), (1, 0), (1, 0) ]
58+
w = [(1, 0), (0, -1), (1, 0), (1, 0)]
5259
a, b = radix2(din[0], din[2], w[0])
5360
c, d = radix2(din[1], din[3], w[1])
54-
61+
5562
rslt = []
56-
rslt.extend( radix2(a, c, w[2]) )
57-
rslt.extend( radix2(b, d, w[3]) )
63+
rslt.extend(radix2(a, c, w[2]))
64+
rslt.extend(radix2(b, d, w[3]))
5865

5966
# reorder by bit-inversed index
6067
ret = []
@@ -64,15 +71,17 @@ def fft4(din):
6471
index = int(fm.format(i)[::-1], 2)
6572
#print(i, '->', index)
6673
re, im = rslt[index]
67-
ret.append( (re, im) )
74+
ret.append((re, im))
6875

6976
return ret
7077

71-
#-------------------------------------------------------------------------------
78+
# -------------------------------------------------------------------------------
79+
80+
7281
def mkFFT4(datawidth=16, point=8):
73-
din = [ (dataflow.Variable('din' + str(i) + 're', width=datawidth, point=point, signed=True),
74-
dataflow.Variable('din' + str(i) + 'im', width=datawidth, point=point, signed=True))
75-
for i in range(4) ]
82+
din = [(dataflow.Variable('din' + str(i) + 're', width=datawidth, point=point, signed=True),
83+
dataflow.Variable('din' + str(i) + 'im', width=datawidth, point=point, signed=True))
84+
for i in range(4)]
7685

7786
# call software-defined method
7887
rslt = fft4(din)
@@ -87,60 +96,63 @@ def mkFFT4(datawidth=16, point=8):
8796
df = dataflow.Dataflow(*vars)
8897
m = df.to_module('fft4')
8998

90-
#try:
99+
# try:
91100
# df.draw_graph()
92-
#except:
101+
# except:
93102
# print('Dataflow graph could not be generated.', file=sys.stderr)
94103

95104
return m
96105

97-
#-------------------------------------------------------------------------------
106+
# -------------------------------------------------------------------------------
107+
108+
98109
def mkTest(datawidth=16, point=8):
99110
m = Module('test')
100111

101112
main = mkFFT4(datawidth, point)
102-
113+
103114
params = m.copy_params(main)
104115
ports = m.copy_sim_ports(main)
105116

106117
clk = ports['CLK']
107118
rst = ports['RST']
108119

109-
din = [ (ports['din' + str(i) + 're'], ports['din' + str(i) + 'im']) for i in range(4) ]
110-
dout = [ (ports['dout' + str(i) + 're'], ports['dout' + str(i) + 'im']) for i in range(4) ]
120+
din = [(ports['din' + str(i) + 're'], ports['din' + str(i) + 'im']) for i in range(4)]
121+
dout = [(ports['dout' + str(i) + 're'], ports['dout' + str(i) + 'im']) for i in range(4)]
122+
123+
_din = [(m.WireLike(re, name='_' + re.name, width=datawidth - point),
124+
m.WireLike(im, name='_' + im.name, width=datawidth - point))
125+
for re, im in din]
126+
_dout = [(m.WireLike(re, name='_' + re.name, width=datawidth - point),
127+
m.WireLike(im, name='_' + im.name, width=datawidth - point))
128+
for re, im in dout]
111129

112-
_din = [ (m.WireLike(re, name='_' + re.name, width=datawidth-point),
113-
m.WireLike(im, name='_' + im.name, width=datawidth-point))
114-
for re, im in din ]
115-
_dout = [ (m.WireLike(re, name='_' + re.name, width=datawidth-point),
116-
m.WireLike(im, name='_' + im.name, width=datawidth-point))
117-
for re, im in dout ]
118-
119130
for (lre, lim), (rre, rim) in zip(_din, din):
120-
m.Assign( lre(fixed.fixed_to_int(rre, point)) )
121-
m.Assign( lim(fixed.fixed_to_int(rim, point)) )
122-
131+
m.Assign(lre(fixed.fixed_to_int(rre, point)))
132+
m.Assign(lim(fixed.fixed_to_int(rim, point)))
133+
123134
for (lre, lim), (rre, rim) in zip(_dout, dout):
124-
m.Assign( lre(fixed.fixed_to_int(rre, point)) )
125-
m.Assign( lim(fixed.fixed_to_int(rim, point)) )
126-
135+
m.Assign(lre(fixed.fixed_to_int(rre, point)))
136+
m.Assign(lim(fixed.fixed_to_int(rim, point)))
137+
127138
uut = m.Instance(main, 'uut',
128139
params=m.connect_params(main),
129140
ports=m.connect_ports(main))
130141

131142
reset_done = m.Reg('reset_done', initval=0)
132143
reset_stmt = []
133-
reset_stmt.append( reset_done(0) )
144+
reset_stmt.append(reset_done(0))
134145
for i, (re, im) in enumerate(din):
135-
reset_stmt.append( re(fixed.to_fixed(i, point)) )
136-
reset_stmt.append( im(fixed.to_fixed(i, point)) )
137-
138-
simulation.setup_waveform(m, uut, *(_din + _dout))
146+
reset_stmt.append(re(fixed.to_fixed(i, point)))
147+
reset_stmt.append(im(fixed.to_fixed(i, point)))
148+
149+
vcd_name = os.path.splitext(os.path.basename(__file__))[0] + '.vcd'
150+
simulation.setup_waveform(m, uut, *(_din + _dout), dumpfile=vcd_name)
139151
simulation.setup_clock(m, clk, hperiod=5)
140152
init = simulation.setup_reset(m, rst, reset_stmt, period=100)
141153

142154
nclk = simulation.next_clock
143-
155+
144156
init.add(
145157
Delay(1000),
146158
reset_done(1),
@@ -151,56 +163,57 @@ def mkTest(datawidth=16, point=8):
151163

152164
def dump(name, v, point):
153165
return Systask('display', name + '= %f', fixed.fixed_to_real(v, point))
154-
166+
155167
send_fsm = FSM(m, 'send_fsm', clk, rst)
156168
send_fsm.goto_next(cond=reset_done)
157169

158170
for i, (re, im) in enumerate(din):
159-
send_fsm.add( re(fixed.to_fixed(i, point)) )
160-
send_fsm.add( im(fixed.to_fixed(i, point)) )
171+
send_fsm.add(re(fixed.to_fixed(i, point)))
172+
send_fsm.add(im(fixed.to_fixed(i, point)))
161173
# send_fsm.add( dump('din[%d]re' % i, re, point), delay=1 )
162174
# send_fsm.add( dump('din[%d]im' % i, im, point), delay=1 )
163-
175+
164176
send_fsm.goto_next()
165177

166178
for i, (re, im) in enumerate(din):
167-
send_fsm.add( re(fixed.to_fixed(0, point)) )
168-
send_fsm.add( im(fixed.to_fixed(0, point)) )
169-
179+
send_fsm.add(re(fixed.to_fixed(0, point)))
180+
send_fsm.add(im(fixed.to_fixed(0, point)))
181+
170182
send_fsm.goto_next()
171183

172184
for _ in range(100):
173-
#for i, (re, im) in enumerate(dout):
185+
# for i, (re, im) in enumerate(dout):
174186
# send_fsm.add( dump('dout[%d]re' % i, re, point), delay=1 )
175187
# send_fsm.add( dump('dout[%d]im' % i, im, point), delay=1 )
176-
188+
177189
send_fsm.goto_next()
178190

179-
send_fsm.add( Systask('finish') )
191+
send_fsm.add(Systask('finish'))
180192

181193
send_fsm.make_always()
182194

183195
return m
184196

197+
185198
if __name__ == '__main__':
186199
n = 4
187200
point = 8
188201
test = mkTest(point=point)
189202
verilog = test.to_verilog('tmp.v')
190-
#print(verilog)
203+
# print(verilog)
191204

192205
# run simulator (Icarus Verilog)
193206
sim = simulation.Simulator(test)
194207
rslt = sim.run()
195208
print(rslt)
196209

197-
## only target RTL
210+
# only target RTL
198211
#main = mkFFT4()
199212
#verilog = main.to_verilog('tmp.v')
200-
#print(verilog)
213+
# print(verilog)
201214

202-
din = [ (0, 0), (1, 1), (2, 2), (3, 3) ]
215+
din = [(0, 0), (1, 1), (2, 2), (3, 3)]
203216
rslt = fft4(din)
204217
for r in rslt:
205-
print( complex(round(r[0] * (2 ** point), 5), round(r[1] * (2 ** point), 5)), ':',
206-
complex(round(r[0], 5), round(r[1], 5)) )
218+
print(complex(round(r[0] * (2 ** point), 5), round(r[1] * (2 ** point), 5)), ':',
219+
complex(round(r[0], 5), round(r[1], 5)))

examples_obsolete/dataflow_fft4/test_dataflow_fft4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
reg reset_done;
8888
8989
initial begin
90-
$dumpfile("uut.vcd");
90+
$dumpfile("dataflow_fft4.vcd");
9191
$dumpvars(0, uut, _din0re, _din0im, _din1re, _din1im, _din2re, _din2im, _din3re, _din3im, _dout0re, _dout0im, _dout1re, _dout1im, _dout2re, _dout2im, _dout3re, _dout3im);
9292
end
9393

examples_obsolete/dataflow_fftN/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ check:
2626

2727
.PHONY: clean
2828
clean:
29-
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd
29+
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v *.vcd

examples_obsolete/dataflow_fftN/dataflow_fftN.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ def mkTest(n=8, datawidth=16, point=8):
226226
reset_stmt.append(re(fixed.to_fixed(wr, point)))
227227
reset_stmt.append(im(fixed.to_fixed(wi, point)))
228228

229-
simulation.setup_waveform(m, uut, *(_din + _dout + _weight))
229+
vcd_name = os.path.splitext(os.path.basename(__file__))[0] + '.vcd'
230+
simulation.setup_waveform(m, uut, *(_din + _dout + _weight), dumpfile=vcd_name)
230231
simulation.setup_clock(m, clk, hperiod=5)
231232
init = simulation.setup_reset(m, rst, reset_stmt, period=100)
232233

examples_obsolete/dataflow_fftN/test_dataflow_fftN.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
reg reset_done;
248248

249249
initial begin
250-
$dumpfile("uut.vcd");
250+
$dumpfile("dataflow_fftN.vcd");
251251
$dumpvars(0, uut, _din0re, _din0im, _din1re, _din1im, _din2re, _din2im, _din3re, _din3im, _din4re, _din4im, _din5re, _din5im, _din6re, _din6im, _din7re, _din7im, _dout0re, _dout0im, _dout1re, _dout1im, _dout2re, _dout2im, _dout3re, _dout3im, _dout4re, _dout4im, _dout5re, _dout5im, _dout6re, _dout6im, _dout7re, _dout7im, _weight0re, _weight0im, _weight1re, _weight1im, _weight2re, _weight2im, _weight3re, _weight3im, _weight4re, _weight4im, _weight5re, _weight5im, _weight6re, _weight6im, _weight7re, _weight7im, _weight8re, _weight8im, _weight9re, _weight9im, _weight10re, _weight10im, _weight11re, _weight11im);
252252
end
253253

0 commit comments

Comments
 (0)