Skip to content

Commit 399b80d

Browse files
reduce linter warns + add diagram
1 parent cb56794 commit 399b80d

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

docs/Block_Diagram.jpg

36.4 KB
Loading

docs/info.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ You can also include images in this folder and reference them in the markdown. E
1111

1212
The project is an AI chip inspired by Google's TPU. It multiply 8-bit floating-point valued matrices. It does so by tiling in 2x2 to fit on the chip's tiny area, so expect performance degradation compared to regular chips. However, the chip's I/O bandwidth will be fully utilized and saturated.
1313

14+
## High Level Block Diagram
15+
16+
Architecturally more simple than the [previous project](https://github.com/WilliamZhang20/ECE298A-TPU). The data moves through the blue, red, yellow, and green arrows.
17+
18+
![alt](Block_Diagram.jpg)
19+
1420
## How to test
1521

1622
Use cocotb and [pyuvm](https://github.com/pyuvm/pyuvm) to lean towards [IEEE-1800.2](https://blogs.sw.siemens.com/verificationhorizons/2015/07/30/uvm-the-next-ieee-standard-1800-2/).

src/control_unit.v

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module control_unit (
2525

2626
// Output interface
2727
output wire done,
28-
output reg [7:0] host_outdata
28+
output reg [7:0] data_out
2929
);
3030

3131
// STATES - Simplified to just IDLE and ACTIVE
@@ -149,19 +149,19 @@ module control_unit (
149149
end
150150
end
151151

152-
// Combinational logic for host_outdata
152+
// Combinational logic for data_out
153153
always @(*) begin
154-
host_outdata = 8'b0;
154+
data_out = 8'b0;
155155
if (data_valid) begin
156156
case (mem_addr)
157-
3'b000: host_outdata = c00[15:8];
158-
3'b001: host_outdata = c00[7:0];
159-
3'b010: host_outdata = c01[15:8];
160-
3'b011: host_outdata = c01[7:0];
161-
3'b100: host_outdata = c10[15:8];
162-
3'b101: host_outdata = c10[7:0];
163-
3'b110: host_outdata = c11[15:8];
164-
3'b111: host_outdata = tail_hold;
157+
3'b000: data_out = c00[15:8];
158+
3'b001: data_out = c00[7:0];
159+
3'b010: data_out = c01[15:8];
160+
3'b011: data_out = c01[7:0];
161+
3'b100: data_out = c10[15:8];
162+
3'b101: data_out = c10[7:0];
163+
3'b110: data_out = c11[15:8];
164+
3'b111: data_out = tail_hold;
165165
endcase
166166
end
167167
end

src/normalize_fp.v

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module int18_to_bf16_lzd #(
44
input wire signed [17:0] acc,
55
output reg [15:0] bf16
66
);
7-
localparam BF16_BIAS = 127;
7+
localparam BF16_BIAS = 8'd127;
88

99
reg sign;
1010
reg [17:0] mag;
@@ -18,12 +18,15 @@ module int18_to_bf16_lzd #(
1818
function [4:0] lzd;
1919
input [17:0] x;
2020
integer i;
21+
reg found;
2122
begin
22-
lzd = 5'd18; // Default: all zeros
23-
for (i=17; i>=0; i=i-1) begin
24-
if (x[i]==1'b1) begin
25-
lzd = 5'd17 - i;
26-
i = -1; // Break
23+
lzd = 5'd18;
24+
found = 1'b0;
25+
26+
for (i = 17; i >= 0; i = i - 1) begin
27+
if (!found && x[i]) begin
28+
lzd = 5'd17 - i[4:0]; // avoid width warnings
29+
found = 1'b1; // emulate break
2730
end
2831
end
2932
end
@@ -45,17 +48,17 @@ module int18_to_bf16_lzd #(
4548
lz = lzd(mag);
4649

4750
// MSB position is (17 - lz), binary point at FRAC_BITS
48-
exp_unbiased = (17 - lz) - FRAC_BITS;
51+
exp_unbiased = $signed({1'b0, (9'd17 - {4'd0,lz})}) - FRAC_BITS;
4952

50-
if (exp_unbiased + BF16_BIAS < 0) begin
53+
if ($signed(exp_unbiased) + $signed(BF16_BIAS) < 0) begin
5154
bf16 = {sign, 15'd0}; // underflow
52-
end else if (exp_unbiased + BF16_BIAS > 255) begin
55+
end else if ($signed(exp_unbiased) + $signed(BF16_BIAS) > 9'd255) begin
5356
bf16 = {sign, 8'hFF, 7'd0}; // overflow
5457
end else begin
55-
exp = exp_unbiased + BF16_BIAS;
58+
exp = exp_unbiased[7:0] + BF16_BIAS;
5659

5760
// normalize so MSB ends up at bit 17
58-
normalized = mag << (lz + 1);
61+
normalized = mag << (lz + 5'd1);
5962
mant = normalized[17:11];
6063

6164
bf16 = {sign, exp, mant};

src/tpu.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module tt_um_tpu (
5656
.data_valid(data_valid),
5757
.a0_sel(a0_sel), .a1_sel(a1_sel), .b0_sel(b0_sel), .b1_sel(b1_sel),
5858
.done(done),
59-
.host_outdata(out_data)
59+
.data_out(out_data)
6060
);
6161

6262
systolic_array_2x2 mmu (

0 commit comments

Comments
 (0)