1313import veriloggen .types .axi as axi
1414import veriloggen .types .ipcore as ipcore
1515
16- axi_wordsize = 4
17- data_wordsize = 4
16+ axi_datawidth = 32
17+ datawidth = 32
1818
1919matrix_size = 16
2020a_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 = """
246242reg [31:0] counter;
247243always @(posedge sim_clk) begin
0 commit comments