Skip to content

Commit ce6d3d1

Browse files
committed
thread_stream_matmul
1 parent 778e8db commit ce6d3d1

File tree

12 files changed

+4007
-1561
lines changed

12 files changed

+4007
-1561
lines changed

examples/thread_matmul/test_thread_matmul.py

Lines changed: 253 additions & 207 deletions
Large diffs are not rendered by default.

examples/thread_matmul/thread_matmul.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
import veriloggen.types.axi as axi
1313

1414

15-
def mkLed():
15+
def mkLed(matrix_size=16):
1616
m = Module('blinkled')
1717
clk = m.Input('CLK')
1818
rst = m.Input('RST')
1919

20+
seq = Seq(m, 'seq', clk, rst)
21+
timer = m.Reg('timer', 32, initval=0)
22+
seq(
23+
timer.inc()
24+
)
25+
2026
datawidth = 32
2127
addrwidth = 10
2228
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
@@ -25,7 +31,11 @@ def mkLed():
2531
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth)
2632

2733
def matmul(matrix_size, a_offset, b_offset, c_offset):
34+
start_time = timer
2835
comp(matrix_size, a_offset, b_offset, c_offset)
36+
end_time = timer
37+
time = end_time - start_time
38+
print("Time (cycles): %d" % time)
2939
check(matrix_size, a_offset, b_offset, c_offset)
3040

3141
def comp(matrix_size, a_offset, b_offset, c_offset):
@@ -60,8 +70,10 @@ def check(matrix_size, a_offset, b_offset, c_offset):
6070
v = ram_c.read(j)
6171
if i == j and v != (i + 1) * 2:
6272
all_ok = False
73+
print("NG [%d,%d] = %d" % (i, j, v))
6374
if i != j and v != 0:
6475
all_ok = False
76+
print("NG [%d,%d] = %d" % (i, j, v))
6577
c_addr += matrix_size * (datawidth // 8)
6678

6779
if all_ok:
@@ -70,16 +82,18 @@ def check(matrix_size, a_offset, b_offset, c_offset):
7082
print("NG")
7183

7284
th = vthread.Thread(m, 'th_matmul', clk, rst, matmul)
73-
fsm = th.start(16, 0, 1024, 2048)
85+
fsm = th.start(matrix_size, 0, 1024, 2048)
7486

7587
return m
7688

7789

7890
def mkTest():
7991
m = Module('test')
8092

93+
matrix_size = 16
94+
8195
# target instance
82-
led = mkLed()
96+
led = mkLed(matrix_size)
8397

8498
# copy paras and ports
8599
params = m.copy_params(led)
@@ -102,8 +116,8 @@ def fwrite(f, value):
102116
# ram_a
103117
addr = 0
104118
nv = 1
105-
for x in range(16):
106-
for y in range(16):
119+
for x in range(matrix_size):
120+
for y in range(matrix_size):
107121
addr += 4
108122
if x == y:
109123
value = nv
@@ -117,8 +131,8 @@ def fwrite(f, value):
117131

118132
# ram_b
119133
addr = 1024
120-
for x in range(16):
121-
for y in range(16):
134+
for x in range(matrix_size):
135+
for y in range(matrix_size):
122136
addr += 4
123137
if x == y:
124138
value = 2
@@ -131,8 +145,8 @@ def fwrite(f, value):
131145

132146
# ram_c
133147
addr = 2048
134-
for x in range(16):
135-
for y in range(16):
148+
for x in range(matrix_size):
149+
for y in range(matrix_size):
136150
addr += 4
137151
value = 100
138152
fwrite(f, value)
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

0 commit comments

Comments
 (0)