Skip to content

Commit dbd6a1b

Browse files
tests pass locally
1 parent c1fec47 commit dbd6a1b

6 files changed

Lines changed: 158 additions & 29 deletions

File tree

test/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ test-top:
6060
WAVES_DIR=$(WAVES_ROOT)/tpu/wave \
6161
COMPILE_ARGS='$(COMPILE_ARGS) -DVCD_PATH="\"$(WAVES_ROOT)/tpu/wave/tpu_tb_$(TIMESTAMP).vcd\""'
6262

63+
test-systolic-array:
64+
$(MAKE) clean
65+
$(MAKE) sim \
66+
TOPLEVEL=systolic_array_tb \
67+
MODULE=test_systolic_array \
68+
VERILOG_SOURCES="$(WAVES_ROOT)/systolic_array/systolic_array_tb.v $(SRC_DIR)/systolic_array_2x2.v $(SRC_DIR)/PE.v" \
69+
PYTHONPATH=$(WAVES_ROOT)/systolic_array \
70+
WAVES_DIR=$(WAVES_ROOT)/systolic_array/wave \
71+
COMPILE_ARGS='$(COMPILE_ARGS) -DVCD_PATH="\"$(WAVES_ROOT)/systolic_array/wave/systolic_array_tb_$(TIMESTAMP).vcd\""'
72+
6373
test-memory:
6474
$(MAKE) clean
6575
$(MAKE) sim \

test/memory/memory_tb.v

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
`default_nettype none
22
`timescale 1ns / 1ps
33

4-
module memory_tb;
4+
module memory_tb ();
55

66
// Dump the signals to a VCD file. You can view it with gtkwave or surfer.
77
initial begin
@@ -11,6 +11,7 @@ module memory_tb;
1111
$dumpfile("memory_tb.vcd");
1212
`endif
1313
$dumpvars(0, memory_tb);
14+
#1;
1415
end
1516

1617
// Inputs
@@ -26,23 +27,19 @@ module memory_tb;
2627

2728
// Instantiate the memory module
2829
memory dut (
29-
`ifdef GL_TEST
30-
.VPWR(VPWR),
31-
.VGND(VGND),
32-
`endif
33-
.clk(clk),
34-
.rst(rst),
35-
.write_en(write_en),
36-
.addr(addr),
37-
.in_data(in_data),
38-
.weight0(weight0),
39-
.weight1(weight1),
40-
.weight2(weight2),
41-
.weight3(weight3),
42-
.input0(input0),
43-
.input1(input1),
44-
.input2(input2),
45-
.input3(input3)
30+
.clk(clk),
31+
.rst(rst),
32+
.write_en(write_en),
33+
.addr(addr),
34+
.in_data(in_data),
35+
.weight0(weight0),
36+
.weight1(weight1),
37+
.weight2(weight2),
38+
.weight3(weight3),
39+
.input0(input0),
40+
.input1(input1),
41+
.input2(input2),
42+
.input3(input3)
4643
);
4744

4845
endmodule
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
`default_nettype none
2+
`timescale 1ns / 1ps
3+
4+
module systolic_array_tb;
5+
6+
initial begin
7+
`ifdef VCD_PATH
8+
$dumpfile(`VCD_PATH);
9+
`else
10+
$dumpfile("systolic_array_tb.vcd");
11+
`endif
12+
$dumpvars(0, systolic_array_tb);
13+
#1;
14+
end
15+
16+
// Inputs
17+
reg clk;
18+
reg rst;
19+
reg clear;
20+
reg activation;
21+
reg signed [7:0] a_data0;
22+
reg signed [7:0] a_data1;
23+
reg signed [7:0] b_data0;
24+
reg signed [7:0] b_data1;
25+
26+
// Outputs
27+
wire signed [11:0] c00;
28+
wire signed [11:0] c01;
29+
wire signed [11:0] c10;
30+
wire signed [11:0] c11;
31+
32+
// Instantiate the systolic array module
33+
systolic_array_2x2 #(.WIDTH(8)) dut (
34+
.clk(clk),
35+
.rst(rst),
36+
.clear(clear),
37+
.activation(activation),
38+
.a_data0(a_data0),
39+
.a_data1(a_data1),
40+
.b_data0(b_data0),
41+
.b_data1(b_data1),
42+
.c00(c00),
43+
.c01(c01),
44+
.c10(c10),
45+
.c11(c11)
46+
);
47+
48+
endmodule
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import cocotb
2+
from cocotb.clock import Clock
3+
from cocotb.triggers import RisingEdge, Timer, ClockCycles
4+
5+
@cocotb.test()
6+
async def test_systolic_array_basic(dut):
7+
"""Test basic 2x2 matrix multiplication"""
8+
9+
cocotb.log.info("Starting systolic array test")
10+
11+
clock = Clock(dut.clk, 10, units="ns") # 100 MHz
12+
cocotb.start_soon(clock.start())
13+
14+
# Reset
15+
dut.rst.value = 1
16+
dut.clear.value = 1
17+
dut.activation.value = 0
18+
dut.a_data0.value = 0
19+
dut.a_data1.value = 0
20+
dut.b_data0.value = 0
21+
dut.b_data1.value = 0
22+
await Timer(20, units="ns")
23+
24+
dut.rst.value = 0
25+
dut.clear.value = 1
26+
await RisingEdge(dut.clk)
27+
28+
dut.clear.value = 0
29+
await RisingEdge(dut.clk)
30+
31+
matrix_A = [[1, 2], [3, 4]]
32+
matrix_B = [[5, 6], [7, 8]]
33+
34+
weights = [matrix_A[0][0], matrix_A[0][1], matrix_A[1][0], matrix_A[1][1]] # weight0..3
35+
inputs = [matrix_B[0][0], matrix_B[1][0], matrix_B[0][1], matrix_B[1][1]] # input0..3
36+
37+
# Drive cycle 0: mmu_cycle = 3'b000
38+
dut.a_data0.value = weights[0] # weight0
39+
dut.a_data1.value = 0
40+
dut.b_data0.value = inputs[0] # input0
41+
dut.b_data1.value = 0
42+
await RisingEdge(dut.clk)
43+
44+
# Drive cycle 1: mmu_cycle = 3'b001
45+
dut.a_data0.value = weights[1] # weight1
46+
dut.a_data1.value = weights[2] # weight2
47+
dut.b_data1.value = inputs[2] # input2 (not transposed)
48+
dut.b_data0.value = inputs[1] # input1
49+
await RisingEdge(dut.clk)
50+
51+
# Drive cycle 2: mmu_cycle = 3'b010
52+
dut.a_data0.value = 0
53+
dut.a_data1.value = weights[3] # weight3
54+
dut.b_data0.value = 0
55+
dut.b_data1.value = inputs[3] # input3
56+
await RisingEdge(dut.clk)
57+
58+
# Clear inputs for subsequent cycles (3'b011..3'b101)
59+
dut.a_data0.value = 0
60+
dut.a_data1.value = 0
61+
dut.b_data0.value = 0
62+
dut.b_data1.value = 0
63+
64+
# Wait for 2 more cycles to let systolic array process
65+
await ClockCycles(dut.clk, 2)
66+
67+
# Read outputs
68+
c00 = dut.c00.value.signed_integer
69+
c01 = dut.c01.value.signed_integer
70+
c10 = dut.c10.value.signed_integer
71+
c11 = dut.c11.value.signed_integer
72+
73+
cocotb.log.info(f"Output matrix C:")
74+
cocotb.log.info(f"C00 = {c00}")
75+
cocotb.log.info(f"C01 = {c01}")
76+
cocotb.log.info(f"C10 = {c10}")
77+
cocotb.log.info(f"C11 = {c11}")
78+
79+
# Check results
80+
assert c00 == 19, f"C00 expected 19 but got {c00}"
81+
assert c01 == 22, f"C01 expected 22 but got {c01}"
82+
assert c10 == 43, f"C10 expected 43 but got {c10}"
83+
assert c11 == 50, f"C11 expected 50 but got {c11}"
84+
85+
cocotb.log.info("Systolic array multiplication test passed")

test/tpu/tb.v

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,9 @@ module tb ();
2222
wire [7:0] uo_out;
2323
wire [7:0] uio_out;
2424
wire [7:0] uio_oe;
25-
`ifdef GL_TEST
26-
wire VPWR = 1'b1;
27-
wire VGND = 1'b0;
28-
`endif
2925

3026
// Replace tt_um_example with your module name:
3127
tt_um_tpu tpu_project (
32-
33-
// Include power ports for the Gate Level test:
34-
`ifdef GL_TEST
35-
.VPWR(VPWR),
36-
.VGND(VGND),
37-
`endif
38-
3928
.ui_in (ui_in), // Dedicated inputs
4029
.uo_out (uo_out), // Dedicated outputs
4130
.uio_in (uio_in), // IOs: Input path

0 commit comments

Comments
 (0)