-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSpMM.sv
111 lines (102 loc) · 3.21 KB
/
SpMM.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
`ifndef N
`define N 16
`endif
`define W 8
`define lgN ($clog2(`N))
`define dbLgN (2*$clog2(`N))
typedef struct packed { logic [`W-1:0] data; } data_t;
module add_(
input logic clock,
input data_t a,
input data_t b,
output data_t out
);
always_ff @(posedge clock) begin
out.data <= a.data + b.data;
end
endmodule
module mul_(
input logic clock,
input data_t a,
input data_t b,
output data_t out
);
always_ff @(posedge clock) begin
out.data <= a.data * b.data;
end
endmodule
module RedUnit(
input logic clock,
reset,
input data_t data[`N-1:0],
input logic split[`N-1:0],
input logic [`lgN-1:0] out_idx[`N-1:0],
output data_t out_data[`N-1:0],
output int delay,
output int num_el
);
// num_el 总是赋值为 N
assign num_el = `N;
// delay 你需要自己为其赋值,表示电路的延迟
assign delay = 0;
generate
for(genvar i = 0; i < `N; i++) begin
assign out_data[i] = 0;
end
endgenerate
endmodule
module PE(
input logic clock,
reset,
input logic lhs_start,
input logic [`dbLgN-1:0] lhs_ptr [`N-1:0],
input logic [`lgN-1:0] lhs_col [`N-1:0],
input data_t lhs_data[`N-1:0],
input data_t rhs[`N-1:0],
output data_t out[`N-1:0],
output int delay,
output int num_el
);
// num_el 总是赋值为 N
assign num_el = `N;
// delay 你需要自己为其赋值,表示电路的延迟
assign delay = 0;
generate
for(genvar i = 0; i < `N; i++) begin
assign out[i] = 0;
end
endgenerate
endmodule
module SpMM(
input logic clock,
reset,
/* 输入在各种情况下是否 ready */
output logic lhs_ready_ns,
lhs_ready_ws,
lhs_ready_os,
lhs_ready_wos,
input logic lhs_start,
/* 如果是 weight-stationary, 这次使用的 rhs 将保留到下一次 */
lhs_ws,
/* 如果是 output-stationary, 将这次的结果加到上次的 output 里 */
lhs_os,
input logic [`dbLgN-1:0] lhs_ptr [`N-1:0],
input logic [`lgN-1:0] lhs_col [`N-1:0],
input data_t lhs_data[`N-1:0],
output logic rhs_ready,
input logic rhs_start,
input data_t rhs_data [3:0][`N-1:0],
output logic out_ready,
input logic out_start,
output data_t out_data [3:0][`N-1:0],
output int num_el
);
// num_el 总是赋值为 N
assign num_el = `N;
assign lhs_ready_ns = 0;
assign lhs_ready_ws = 0;
assign lhs_ready_os = 0;
assign lhs_ready_wos = 0;
assign rhs_ready = 0;
assign out_ready = 0;
endmodule