Skip to content

Commit 188b7b2

Browse files
committed
AxiMemoryModery supports a narrower bit-width than 8 in initial data configuration and set_memory method.
1 parent 3d590d0 commit 188b7b2

File tree

13 files changed

+580
-112
lines changed

13 files changed

+580
-112
lines changed

examples/thread_matmul/thread_matmul.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import veriloggen.thread as vthread
1313
import veriloggen.types.axi as axi
1414

15-
axi_wordsize = 4
16-
data_wordsize = 4
15+
axi_datawidth = 32
16+
datawidth = 32
1717

1818
a_offset = 0
1919
b_offset = 4096
@@ -31,7 +31,6 @@ def mkLed(matrix_size=16):
3131
timer.inc()
3232
)
3333

34-
datawidth = 32
3534
addrwidth = 10
3635
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
3736
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
@@ -106,11 +105,9 @@ def mkTest(memimg_name=None):
106105
n_raw_a = axi.shape_to_length(a_shape)
107106
n_raw_b = axi.shape_to_length(b_shape)
108107

109-
n_a = axi.memory_word_length(a_shape, data_wordsize)
110-
n_b = axi.memory_word_length(b_shape, data_wordsize)
108+
n_a = axi.shape_to_memory_size(a_shape, datawidth)
109+
n_b = axi.shape_to_memory_size(b_shape, datawidth)
111110

112-
#a = np.arange(n_raw_a, dtype=np.int32).reshape(a_shape)
113-
#b = np.arange(n_raw_b, dtype=np.int32).reshape(b_shape) + [n_a]
114111
a = np.zeros(a_shape, dtype=np.int64)
115112
b = np.zeros(b_shape, dtype=np.int64)
116113

@@ -131,13 +128,13 @@ def mkTest(memimg_name=None):
131128
b[y][x] = 0
132129

133130
a_addr = a_offset
134-
size_a = n_a * data_wordsize
131+
size_a = n_a * datawidth // 8
135132
b_addr = b_offset
136-
size_b = n_b * data_wordsize
133+
size_b = n_b * datawidth // 8
137134

138-
mem = np.zeros([1024 * 1024 // axi_wordsize], dtype=np.int64)
139-
axi.set_memory(mem, a, axi_wordsize, data_wordsize, a_addr)
140-
axi.set_memory(mem, b, axi_wordsize, data_wordsize, b_addr)
135+
mem = np.zeros([1024 * 1024 * 8 // axi_datawidth], dtype=np.int64)
136+
axi.set_memory(mem, a, axi_datawidth, datawidth, a_addr)
137+
axi.set_memory(mem, b, axi_datawidth, datawidth, b_addr)
141138

142139
led = mkLed(matrix_size)
143140

@@ -148,9 +145,9 @@ def mkTest(memimg_name=None):
148145
rst = ports['RST']
149146

150147
memory = axi.AxiMemoryModel(m, 'memory', clk, rst,
151-
mem_datawidth=8 * axi_wordsize,
148+
mem_datawidth=axi_datawidth,
152149
memimg=mem, memimg_name=memimg_name)
153-
150+
154151
memory.connect(ports, 'myaxi')
155152

156153
uut = m.Instance(led, 'uut',

examples/thread_matmul_ipcore/thread_matmul_ipcore.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import veriloggen.types.axi as axi
1414
import veriloggen.types.ipcore as ipcore
1515

16-
axi_wordsize = 4
17-
data_wordsize = 4
16+
axi_datawidth = 32
17+
datawidth = 32
1818

1919
matrix_size = 16
2020
a_offset = 0
@@ -28,9 +28,7 @@ def mkLed():
2828
rst = m.Input('RST')
2929
led = m.OutputReg('led', 8, initval=0)
3030

31-
datawidth = 32
3231
addrwidth = 10
33-
3432
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
3533
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
3634
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth)
@@ -86,11 +84,9 @@ def mkTest(memimg_name=None):
8684
n_raw_a = axi.shape_to_length(a_shape)
8785
n_raw_b = axi.shape_to_length(b_shape)
8886

89-
n_a = axi.memory_word_length(a_shape, data_wordsize)
90-
n_b = axi.memory_word_length(b_shape, data_wordsize)
87+
n_a = axi.shape_to_memory_size(a_shape, datawidth)
88+
n_b = axi.shape_to_memory_size(b_shape, datawidth)
9189

92-
#a = np.arange(n_raw_a, dtype=np.int32).reshape(a_shape)
93-
#b = np.arange(n_raw_b, dtype=np.int32).reshape(b_shape) + [n_a]
9490
a = np.zeros(a_shape, dtype=np.int64)
9591
b = np.zeros(b_shape, dtype=np.int64)
9692

@@ -111,13 +107,13 @@ def mkTest(memimg_name=None):
111107
b[y][x] = 0
112108

113109
a_addr = a_offset
114-
size_a = n_a * data_wordsize
110+
size_a = n_a * datawidth // 8
115111
b_addr = b_offset
116-
size_b = n_b * data_wordsize
112+
size_b = n_b * datawidth // 8
117113

118-
mem = np.zeros([1024 * 1024 // axi_wordsize], dtype=np.int64)
119-
axi.set_memory(mem, a, axi_wordsize, data_wordsize, a_addr)
120-
axi.set_memory(mem, b, axi_wordsize, data_wordsize, b_addr)
114+
mem = np.zeros([1024 * 1024 * 8 // axi_datawidth], dtype=np.int64)
115+
axi.set_memory(mem, a, axi_datawidth, datawidth, a_addr)
116+
axi.set_memory(mem, b, axi_datawidth, datawidth, b_addr)
121117

122118
led = mkLed()
123119

@@ -128,7 +124,7 @@ def mkTest(memimg_name=None):
128124
rst = ports['RST']
129125

130126
memory = axi.AxiMemoryModel(m, 'memory', clk, rst,
131-
mem_datawidth=8 * axi_wordsize,
127+
mem_datawidth=axi_datawidth,
132128
memimg=mem, memimg_name=memimg_name)
133129

134130
memory.connect(ports, 'maxi')
@@ -183,7 +179,7 @@ def ctrl():
183179
for y in range(matrix_size):
184180
for x in range(matrix_size):
185181
v = memory.read(
186-
c_offset + (y * matrix_size + x) * data_wordsize)
182+
c_offset + (y * matrix_size + x) * datawidth // 8)
187183
if y == x and vthread.verilog.NotEql(v, (y + 1) * 2):
188184
all_ok = False
189185
print("NG [%d,%d] = %d" % (y, x, v))
@@ -241,7 +237,7 @@ def run(filename='tmp.v', simtype='iverilog', outputfile=None):
241237
rslt = run(filename='tmp.v')
242238
print(rslt)
243239

244-
memname = '_memory_memimg_.out'
240+
memname = 'memimg_thread_matmul_ipcore.out'
245241
simcode = """
246242
reg [31:0] counter;
247243
always @(posedge sim_clk) begin

examples/thread_matmul_narrow/thread_matmul_narrow.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import veriloggen.thread as vthread
1313
import veriloggen.types.axi as axi
1414

15-
axi_wordsize = 4
16-
data_wordsize = 8
15+
axi_datawidth = 32
16+
datawidth = 64
1717

1818
a_offset = 0
1919
b_offset = 4096
@@ -31,13 +31,12 @@ def mkLed(matrix_size=16):
3131
timer.inc()
3232
)
3333

34-
datawidth = 64
3534
addrwidth = 10
3635
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
3736
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
3837
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth)
3938
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth //
40-
(data_wordsize // axi_wordsize))
39+
(datawidth // axi_datawidth))
4140

4241
def matmul(matrix_size, a_offset, b_offset, c_offset):
4342
start_time = timer
@@ -107,11 +106,9 @@ def mkTest(memimg_name=None):
107106
n_raw_a = axi.shape_to_length(a_shape)
108107
n_raw_b = axi.shape_to_length(b_shape)
109108

110-
n_a = axi.memory_word_length(a_shape, data_wordsize)
111-
n_b = axi.memory_word_length(b_shape, data_wordsize)
109+
n_a = axi.shape_to_memory_size(a_shape, datawidth)
110+
n_b = axi.shape_to_memory_size(b_shape, datawidth)
112111

113-
#a = np.arange(n_raw_a, dtype=np.int32).reshape(a_shape)
114-
#b = np.arange(n_raw_b, dtype=np.int32).reshape(b_shape) + [n_a]
115112
a = np.zeros(a_shape, dtype=np.int64)
116113
b = np.zeros(b_shape, dtype=np.int64)
117114

@@ -132,13 +129,13 @@ def mkTest(memimg_name=None):
132129
b[y][x] = 0
133130

134131
a_addr = a_offset
135-
size_a = n_a * data_wordsize
132+
size_a = n_a * datawidth // 8
136133
b_addr = b_offset
137-
size_b = n_b * data_wordsize
134+
size_b = n_b * datawidth // 8
138135

139-
mem = np.zeros([1024 * 1024 // axi_wordsize], dtype=np.int64)
140-
axi.set_memory(mem, a, axi_wordsize, data_wordsize, a_addr)
141-
axi.set_memory(mem, b, axi_wordsize, data_wordsize, b_addr)
136+
mem = np.zeros([1024 * 1024 * 8 // axi_datawidth], dtype=np.int64)
137+
axi.set_memory(mem, a, axi_datawidth, datawidth, a_addr)
138+
axi.set_memory(mem, b, axi_datawidth, datawidth, b_addr)
142139

143140
led = mkLed(matrix_size)
144141

@@ -149,7 +146,7 @@ def mkTest(memimg_name=None):
149146
rst = ports['RST']
150147

151148
memory = axi.AxiMemoryModel(m, 'memory', clk, rst,
152-
mem_datawidth=8 * axi_wordsize,
149+
mem_datawidth=axi_datawidth,
153150
memimg=mem, memimg_name=memimg_name)
154151

155152
memory.connect(ports, 'myaxi')

examples/thread_matmul_wide/thread_matmul_wide.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import veriloggen.thread as vthread
1313
import veriloggen.types.axi as axi
1414

15-
axi_wordsize = 8
16-
data_wordsize = 4
15+
axi_datawidth = 64
16+
datawidth = 32
1717

1818
a_offset = 0
1919
b_offset = 4096
@@ -31,12 +31,12 @@ def mkLed(matrix_size=16):
3131
timer.inc()
3232
)
3333

34-
datawidth = 32
3534
addrwidth = 10
3635
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
3736
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
3837
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth)
39-
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth * (axi_wordsize // data_wordsize))
38+
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth *
39+
(axi_datawidth // datawidth))
4040

4141
def matmul(matrix_size, a_offset, b_offset, c_offset):
4242
start_time = timer
@@ -106,11 +106,9 @@ def mkTest(memimg_name=None):
106106
n_raw_a = axi.shape_to_length(a_shape)
107107
n_raw_b = axi.shape_to_length(b_shape)
108108

109-
n_a = axi.memory_word_length(a_shape, data_wordsize)
110-
n_b = axi.memory_word_length(b_shape, data_wordsize)
109+
n_a = axi.shape_to_memory_size(a_shape, datawidth)
110+
n_b = axi.shape_to_memory_size(b_shape, datawidth)
111111

112-
#a = np.arange(n_raw_a, dtype=np.int32).reshape(a_shape)
113-
#b = np.arange(n_raw_b, dtype=np.int32).reshape(b_shape) + [n_a]
114112
a = np.zeros(a_shape, dtype=np.int64)
115113
b = np.zeros(b_shape, dtype=np.int64)
116114

@@ -131,13 +129,13 @@ def mkTest(memimg_name=None):
131129
b[y][x] = 0
132130

133131
a_addr = a_offset
134-
size_a = n_a * data_wordsize
132+
size_a = n_a * datawidth // 8
135133
b_addr = b_offset
136-
size_b = n_b * data_wordsize
134+
size_b = n_b * datawidth // 8
137135

138-
mem = np.zeros([1024 * 1024 // axi_wordsize], dtype=np.int64)
139-
axi.set_memory(mem, a, axi_wordsize, data_wordsize, a_addr)
140-
axi.set_memory(mem, b, axi_wordsize, data_wordsize, b_addr)
136+
mem = np.zeros([1024 * 1024 * 8 // axi_datawidth], dtype=np.int64)
137+
axi.set_memory(mem, a, axi_datawidth, datawidth, a_addr)
138+
axi.set_memory(mem, b, axi_datawidth, datawidth, b_addr)
141139

142140
led = mkLed(matrix_size)
143141

@@ -148,8 +146,8 @@ def mkTest(memimg_name=None):
148146
rst = ports['RST']
149147

150148
memory = axi.AxiMemoryModel(m, 'memory', clk, rst,
151-
datawidth=8 * axi_wordsize,
152-
mem_datawidth=8 * axi_wordsize,
149+
datawidth=axi_datawidth,
150+
mem_datawidth=axi_datawidth,
153151
memimg=mem, memimg_name=memimg_name)
154152

155153
memory.connect(ports, 'myaxi')

examples/thread_stream_matmul/thread_stream_matmul.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import veriloggen.thread as vthread
1313
import veriloggen.types.axi as axi
1414

15-
axi_wordsize = 4
16-
data_wordsize = 4
15+
axi_datawidth = 32
16+
datawidth = 32
1717

1818
a_offset = 0
1919
b_offset = 4096
@@ -31,7 +31,6 @@ def mkLed(matrix_size=16):
3131
timer.inc()
3232
)
3333

34-
datawidth = 32
3534
addrwidth = 10
3635
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth)
3736
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth)
@@ -116,11 +115,9 @@ def mkTest(memimg_name=None):
116115
n_raw_a = axi.shape_to_length(a_shape)
117116
n_raw_b = axi.shape_to_length(b_shape)
118117

119-
n_a = axi.memory_word_length(a_shape, data_wordsize)
120-
n_b = axi.memory_word_length(b_shape, data_wordsize)
118+
n_a = axi.shape_to_memory_size(a_shape, datawidth)
119+
n_b = axi.shape_to_memory_size(b_shape, datawidth)
121120

122-
#a = np.arange(n_raw_a, dtype=np.int32).reshape(a_shape)
123-
#b = np.arange(n_raw_b, dtype=np.int32).reshape(b_shape) + [n_a]
124121
a = np.zeros(a_shape, dtype=np.int32)
125122
b = np.zeros(b_shape, dtype=np.int32)
126123

@@ -141,13 +138,13 @@ def mkTest(memimg_name=None):
141138
b[y][x] = 0
142139

143140
a_addr = a_offset
144-
size_a = n_a * data_wordsize
141+
size_a = n_a * datawidth // 8
145142
b_addr = b_offset
146-
size_b = n_b * data_wordsize
143+
size_b = n_b * datawidth // 8
147144

148-
mem = np.zeros([1024 * 1024 // axi_wordsize], dtype=np.int64)
149-
axi.set_memory(mem, a, axi_wordsize, data_wordsize, a_addr)
150-
axi.set_memory(mem, b, axi_wordsize, data_wordsize, b_addr)
145+
mem = np.zeros([1024 * 1024 * 8 // axi_datawidth], dtype=np.int64)
146+
axi.set_memory(mem, a, axi_datawidth, datawidth, a_addr)
147+
axi.set_memory(mem, b, axi_datawidth, datawidth, b_addr)
151148

152149
led = mkLed(matrix_size)
153150

@@ -158,7 +155,7 @@ def mkTest(memimg_name=None):
158155
rst = ports['RST']
159156

160157
memory = axi.AxiMemoryModel(m, 'memory', clk, rst,
161-
mem_datawidth=8 * axi_wordsize,
158+
mem_datawidth=axi_datawidth,
162159
memimg=mem, memimg_name=memimg_name)
163160

164161
memory.connect(ports, 'myaxi')

tests/extension/thread_/memorymodel_readwrite_narrow/thread_memorymodel_readwrite_narrow.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,9 @@ def body(size, offset):
106106
return m
107107

108108

109-
def mkTest(memimg_name=None):
109+
def mkTest(memimg_name=None, axi_datawidth=32, datawidth=4, addrwidth=10):
110110
m = Module('test')
111111

112-
axi_datawidth = 32
113-
datawidth = 4
114-
addrwidth = 10
115-
116112
# target instance
117113
led = mkLed(axi_datawidth, datawidth, addrwidth)
118114

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)