FPGA Group6 Final Project - Systolic Array as an CNN Accelerator
文章網址
Team Members
姓名 |
學號 |
課程 |
劉永勝 |
F94089032 |
FPGA / AOC |
蔡宗瑾 |
E14083137 |
FPGA / AOC |
謝懷頡 |
M16124172 |
AOC |
李宇洋 |
E24099025 |
FPGA |
The Convolutional Neural Network(CNN) is widly used both in image-processing domain and machine learning related field. CNN involves numerous MAC(multiply accumulate) operations, the amount of data a CNN model nowadays required to process is enormous, and the goal is to accelerate this process. Many ideas have been proposed, systolic array is one of them, the unique way of data flow in systolic array reduces the data movement from off-chip DRAM to on-chip buffer, it not only saves energy consumption but also increases the througput rate.
In our workshop, we implemented a systolic array of size 8 by 8, the main architecture is in reference of the Google TPU.
CNN Model
- CNN overview:
Input feature map(ifmap) of size convolves with filter(kernel) size of will get a output feature map(ofmap). In the figure belowed, is considered as 1, and can be obtained form , where is the padding number, and is the stride number.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Shape Parameter |
Description |
N |
Batch size of 3D ifmaps |
M |
# of 3D filters/ # of ofmap channels |
C |
# of ifmap/filter channels |
H/W |
ifmap plane hieght/width |
R/S |
filter plane height/width |
E/F |
ofmap plane height/width |
- Model Description:
Using Fashion Mnist as our targeted dataset and build a small model as followed:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Model summary:
We only aim at accelerating the convolutional layers for now, fully connected layers are left for future work.
Layers |
Input Activations |
Kernels |
Output Activations |
Layer1 |
|
|
|
Layer2 |
|
|
|
Layer3 |
|
|
|
Layer4 |
|
|
|
Layer5 |
|
|
|
Data load and Quantization(python)
-
data load
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
Quantization
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
weight value distributed
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
bias value distributed
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
GEMM
-
GEMM stands for GEneral Matrix to Matrix Multiplication. What is does is to flatten multi-dimensional data into 2-D matrices and do matrix multiplication.
-
Convolution applies each filter across the whole image. The diagram belowed shows how input image can be packed into multiple patches to form a 2-D matrix by im2col algorithm. The diagram is a example of stride equals to kernel width, meaning no overlapping pixels accross patches, however, with our simple model, stride number is set to 1, hence, there are planty of overlapping pixels. However, the overhead of replicating pixels can be diminished by the advantage of GEMM brings.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Reference: Why GEMM is at the heart of deep learning
-
Flattening visualization
Input flatten
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Kernel flatten
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Output flatten
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
Layers after im2col:
Layers |
Input Activations |
Kernels |
Output Activations |
Layer1 |
|
|
|
Layer2 |
|
|
|
Layer3 |
|
|
|
Layer4 |
|
|
|
Layer5 |
|
|
|
-
Taking layer 2 as an example, this is how input and kernels are flatten to form 2-D matrices, and do matrix multiplication to obtain output. A row of input activations(IA) does dot product with a column of weights(W) to obtain an element in output activations(OA), shown in blue color.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
col2im: After obtaing the output activations from GEMM method, we still need to convert the matrix back to the original image format. Here, we operate col2im algorithm to get the result.
Tiling
- Tiling is a technique used in CNN accelerators to partition the computation and memory access into smaller tasks that can be executed in parallel. Considered our one 8 by 8 systolic array as a tile on the hardware, it can only compute 1 block of output activations at a time, which size is also 8 by 8, therefore, the input data needed by a tile of hardware is a row of IA, and a column of W.
- In layer 2, IA is partitioned into 256/8 = 32 rows, and every row contains nine 8 by 8 matrix blocks. As for W, it is partitioned into 16/8 = 2 columns, each column also contains nine matrix blocks.
- Every matrix block is sent to Systolic Array for computation, and every 9 blocks are accumulated to get one 8 by 8 output block.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Systolic Array Architecture
-
We implemented the TPU (Tensor Processing Unit) weight stationary architecture shown in the diagram. Input activations are fed from the side, while weight parameters are input from the top. Each processing element (PE) has a weight buffer to temporarily store the weights. However, the main drawback of the TPU is that it requires waiting for weight preload to complete before the entire Systolic array can start operating.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
Therefore, we referred to another paper and implemented a double buffer, as shown in the diagram, in each processing element (PE) to store the current and next weight parameters. This allows the Systolic array to perform calculations without any delays.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
The control mechanism of the entire Systolic array is extremely simple, requiring only two control signals: "work" and "done." The "work" signal indicates the initiation of input activation and weight parameter inputs. It propagates from the side register, moving downward until it reaches the corner, where it serves as the starting signal for the output accumulator. Once the computation in the entire Systolic array is completed, with all values stored in the output accumulators, the last output accumulator emits a "done" signal.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
The diagram below illustrates an example of data flow in a tile. Each dot represents an 8-bit data, and the color of the dot corresponds to the tiling data on the left. It can be observed that the computation results are generated sequentially starting from the first column. Therefore, the completion signal of the entire Systolic array will be provided by the output accumulator of the last column.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Ideal Work Flow
PS is the ZYNQ processing system, and PL is the programmable logics. SA is systolic array, we can see that most of the computation is done on SA, some light tasks are distrubuted to PS done by CPU. The current work only covers quantization, im2col, SA output collecting and col2im. Other software computations are left for future work.

Communication Between PS & PL
CPU<->SA AXI interface definition
Input
CPU |
SA |
slv_reg0 |
cpu_enable |
slv_reg1 |
bnumin |
slv_reg2 |
tile_num |
slv_reg3 |
cpu_received |
slv_reg4 |
ps_rst |
Output
CPU |
SA |
slv_reg5 |
valid |
slv_reg6 |
outData0 |
slv_reg7 |
outData1 |
slv_reg8 |
outData2 |
slv_reg9 |
outData3 |
slv_reg10 |
outData4 |
slv_reg11 |
outData5 |
slv_reg12 |
outData6 |
slv_reg13 |
outData7 |
BRAM<->SA interface definition
Input
BRAM0 |
SA |
ADDRBWRADDR |
counter |
ENBWREN |
readenable |
BRAM1 |
SA |
ADDRBWRADDR |
counter |
ENBWREN |
readenable |
Output
- Systolic Array interface definition
Program running on PS
Step:
- PS will write data into BRAM0 & BRAM1 through AXI bus, where BRAM0 consists of input feature, and BRAM1 consists of weight.
Note: One thing to notice is that there are total 16 BRAMs, where each has I/O bandwith of 18-bits(2 parity bits + 16 data bits)
- When data write is completed on both BRAM, PS will set
cpu_enable
and ps_rst
to true through AXI bus, and then turn off the signal.
This step will inform Systolic Array controller to start input weight and ifeature from BRAM, and also start the computing.
- When the computing output are all push to FIFO and finished the accumulation, controller will set
valid
signal to true, and sent out the data out
to PS through AXI bus. Everytime when PS receive the data out
, PS will sent back the signal of received
to complete the handshake.
Note: This loop will repeat for the times of blocks number inside a tile in order to output the result of the matrix multiplication respectively in row.
- When all the data outputs are received, PS will proceed to the next loop to send new weights and input features. This process will continue for the number of tiles in the computing convoultion layer.
- Since we only have one tile on PL, only data needed by one tile is sent to PL at a time. Therefore, whenever one tile of computation is done, PS sends ps_rst signal to PL, makes it jump back to WAIT_PS state, and wait for cpu_enable signal when all data is written into BRAM.

Overall system FSM:

Pseudo code for a layer operation, here in layer 2, total_tile_number is 64. When one block of output is collected, ps_rst is raised high again, and PS starts to send data to PL. When data is written, cpu_enable is raised high, SA begins its computation.

BRAM
module bram0(
input clk,
input rst_a,
input [10:0] ADDRARDADDR,
input ENARDEN,
input ENBWREN,
input [3:0] WEA,
input [31:0] DIADI,
input [11:0] ADDRBWRADDR,
output [31:0] DOADO,
output [31:0] DOBDO
);
RAMB36E1 #(
.RDADDR_COLLISION_HWCONFIG("DELAYED_WRITE"),
.SIM_COLLISION_CHECK("ALL"),
.DOA_REG(0),
.DOB_REG(0),
.EN_ECC_READ("FALSE"),
.EN_ECC_WRITE("FALSE"),
.INITP_00(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_01(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_02(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_03(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_04(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_05(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_06(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_07(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_08(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_09(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INITP_0F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_00(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_01(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_02(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_03(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_04(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_05(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_06(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_07(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_08(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_09(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_0F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_10(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_11(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_12(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_13(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_14(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_15(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_16(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_17(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_18(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_19(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_1F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_20(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_21(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_22(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_23(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_24(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_25(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_26(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_27(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_28(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_29(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_2F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_30(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_31(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_32(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_33(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_34(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_35(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_36(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_37(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_38(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_39(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_3F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_40(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_41(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_42(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_43(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_44(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_45(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_46(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_47(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_48(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_49(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_4F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_50(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_51(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_52(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_53(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_54(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_55(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_56(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_57(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_58(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_59(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_5F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_60(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_61(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_62(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_63(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_64(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_65(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_66(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_67(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_68(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_69(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_6F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_70(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_71(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_72(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_73(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_74(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_75(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_76(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_77(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_78(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_79(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7A(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7B(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7C(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7D(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7E(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_7F(256'h0000000000000000000000000000000000000000000000000000000000000000),
.INIT_A(36'h000000000),
.INIT_B(36'h000000000),
.INIT_FILE("NONE"),
.RAM_MODE("TDP"),
.RAM_EXTENSION_A("NONE"),
.RAM_EXTENSION_B("NONE"),
.READ_WIDTH_A(18),
.READ_WIDTH_B(18),
.WRITE_WIDTH_A(18),
.WRITE_WIDTH_B(0),
.RSTREG_PRIORITY_A("RSTREG"),
.RSTREG_PRIORITY_B("RSTREG"),
.SRVAL_A(36'h000000000),
.SRVAL_B(36'h000000000),
.SIM_DEVICE("7SERIES"),
.WRITE_MODE_A("WRITE_FIRST"),
.WRITE_MODE_B("WRITE_FIRST")
)
RAMB36E1_inst (
.CASCADEOUTA(),
.CASCADEOUTB(),
.CASCADEINA(),
.CASCADEINB(),
.DBITERR(),
.ECCPARITY(),
.RDADDRECC(),
.SBITERR(),
.INJECTDBITERR(),
.INJECTSBITERR(),
.DOADO(DOADO),
.DOPADOP(),
.ADDRARDADDR({3'b0, ADDRARDADDR[10:2], 4'b0000}),
.CLKARDCLK(clk),
.ENARDEN(ENARDEN),
.REGCEAREGCE(1'b1),
.RSTRAMARSTRAM(),
.RSTREGARSTREG(),
.WEA(WEA),
.DIADI(DIADI),
.DIPADIP(),
.DOBDO(DOBDO),
.DOPBDOP(),
.ADDRBWRADDR({1'b0, ADDRBWRADDR[10:0], 4'b0000}),
.CLKBWRCLK(clk),
.ENBWREN(ENBWREN),
.REGCEB(1'b0),
.RSTRAMB(),
.RSTREGB(),
.WEBWE(),
.DIBDI(),
.DIPBDIP()
);
endmodule
- Note: Data R/W bandwidth is 16-bits, beacuse the data input to BRAM is one block(9-bits).
Block diagram





Implementation
Usage of LUTs and DSP
From the analysis, it can be observed that approximately 138 lookup tables (LUTs) are required to synthesize a single processing element (PE). However, if we use DSP, only two DSPs are needed. Therefore, in terms of computation, it will rely on DSP synthesis to achieve better FPGA hardware utilization.

Utilization





DSP ver.






Correctness of our design
Only one layer has been implemented so far(layer2), the functionality of the SA is proven to be correct by Modelsim. The result on FPGA is also correct, hence, as long as PS provides correct input data to PL, the output result is always correct.
- Simulation:

- Implementation on FPGA:

Our design shortcoming
1. DSP timing violation due to the lack of weight registers.
To ensure the opsum calculation is performed within a single clock cycle, we removed the weight input register. However, this resulted in the weight signal being broadcasted, which contradicts the design on the FPGA that avoids broadcasting. Each input of the DSP requires an input register, which conflicts with our design and causes a timing violation. To resolve this issue, we have decided to reintroduce the input weight register and change the weight buffer to a latch.

2. The interface definition of the Systolic array cannot be modified independently.
In the design process, the input and output interface bit widths of the Systolic array are fixed and cannot be modified. However, for quick verification of correct implementation, we added an additional control signal from the internal multiplexer of the processing element (PE) to the most significant bit (MSB) of the 8-bit data for input activation and weight parameters, resulting in 9-bit data. Although the entire system is self-designed, this approach of modifying the interface bit widths on our own is not a good design practice. Since the internal operation of the Systolic array follows a regular pattern, the solution is to incorporate additional registers internally to allow the control signals to flow according to the pattern.
3. BRAM 16-bit R/W issue.
The design of our PE requires a parity bit to control the data flow based on different tiles. This is why our input features and weights are 9 bits instead of 8 bits. However, this design leads to wastage of resources in our implementation. To accommodate the 9-bit input requirement, the BRAM I/O bandwidth API call needs to be changed from 8-bit to 16-bit, resulting in the presence of all-zero 7 bits in every transmission that occurs in the BRAM.
The solution we propose is to avoid adding the parity control bit to the input features and weights before data transmission between the PS and BRAM, as well as between the BRAM and the Systolic Array. Instead, we can incorporate the control signal through a simple hardware toggle generator. This generator will add a control bit to the most significant bit (MSB) of the data and toggle between 0 and 1 when the tile changes. The optimal location to add this generator in our current design is within the truncate module, which concatenates all the data from BRAM0 and BRAM1 before sending it to the Systolic Array.
Reference
1.Google TPU
2 PE double buffer