Board from entry to the master series (eight)

Finally arrived at the HLS section. HLS is an abbreviation of High Level Synthesis, a tool that can integrate high-level programming languages ​​C, C++, and SystemC into RTL code. The development of productivity drives the design pattern. In the initial stage of electronic technology, people pay attention to the RLC circuit to solve the circuit response by establishing differential equations. The gate-level circuit is the initial package of RLC, and people use Boolean algebra and Karnaugh map for circuit design and analysis. Later, as the integrated circuit is further developed, the gate circuit can be integrated into macrocells such as registers, flip-flops, and ROM, and the design tools become more highly modular. Algorithm-level circuit design has never been a particularly good tool until HLS appears. HLS can directly map algorithms to RTL circuits, achieving high-level synthesis. At this level, System Generator is also a high-level synthesis tool because it integrates the matlab algorithm description into RTL code. If machine learning and artificial intelligence make a major breakthrough in the future, there may be a tool to integrate human natural language into RTL code. I wonder if we can witness its appearance. HLS learning resources can be referenced. This section gives a more general example of matrix and vector multiplication, from step-by-step optimization from full serial to full parallel. Matrix Lab Matlab is a relatively common mathematical simulation software. This blog is based on the R2013a version. In order to verify the correctness of matrix vector multiplication, we first use Matlab to generate test matrices and vectors, and use matlab to calculate the results. The code is as follows: [plain]

View the code snippet on CODE

Derived to my code piece


Clear;

Clc;

Close all;

N = 5;

A = randi([1,100],N,N);

b = randi(100,N,1);

c = A*b;

KKK_SaveToCHeaderFile(A,'A.h');

KKK_SaveToCHeaderFile(b, 'b.h');

KKK_SaveToCHeaderFile(c,'c.h');

Here is a simple example of A*b = c, where A is a 5X5 matrix, b is a 5X1 vector, and the result c is a 5X1 vector. Where KKK_SaveToCHeaderFile() is a subfunction that saves the matrix and vector as a C language array, defined as follows: [plain]

View the code snippet on CODE

Derived to my code piece


funcTIon [] = KKK_SaveToCHeaderFile(var,fn)

Fid = fopen(fn,'w');

Var = reshape(var.',1,[]);

Fprintf(fid, '%d,', var);

Fclose(fid);

Given the test routine, A is as follows: [plain]

View the code snippet on CODE

Derived to my code piece


82 10 16 15 66

91 28 98 43 4

13 55 96 92 85

92 96 49 80 94

64 97 81 96 68

b is as follows: [plain]

View the code snippet on CODE

Derived to my code piece


76

75

40

66

18

The obtained c is as follows: After running the matlab script, three files are generated: Ah, bh, ch, which are input data and reference results of the HLS program. Below we use the HLS tool to implement the functions of the above matrix X vector. The first step is to run Vivado HLS.

Board from entry to the master series (eight)

Select the first item, Create New Project, and create a new project MatrixMulTIply

Board from entry to the master series (eight)

After entering the path and project name, click Next.

Board from entry to the master series (eight)

Add a top-level module file. Here we enter MatrixMulTIply, then New File..., create a new .c file, name it MatrixMultiply.c (suffix not to omit!), then click Next to add the top-level file test script. Here a New file TestMatrixMultiply.c (suffix not to be omitted!), then add the Ah, bh, ch generated in front of Matlab, as shown below:

Board from entry to the master series (eight)

Click Next to select the solution configuration, as shown below

Board from entry to the master series (eight)

The rest remain the default, only modify the Part Selection section and change to ZedBoard. After the change, Finish will enter the main interface, as shown below

Board from entry to the master series (eight)

It can be seen that the Vivado HLS interface is very similar to the Xilinx SDK. The difference is that the former is responsible for the development of the PL part, and the latter is responsible for the preparation of the PS software. The different positioning determines that the future of the two will inevitably lead to differences. Change the MatrixMultiply.c content to: [cpp]

View the code snippet on CODE

Derived to my code piece


Typedef int data_type;

#define N 5

Void MatrixMultiply(data_type AA[N*N],data_type bb[N],data_type cc[N])

{

Int i,j;

For(i = 0;i

{

Data_type sum = 0;

For(j = 0;j

{

Sum += AA[i*N+j]*bb[j];

}

Cc[i] = sum;

}

}

Grating-based External Cavity Tunable Laser

Grating-Based External Cavity Tunable Laser,Red Grating Laser,Laser Grating Reflection,Grating Reflector Laser

AcePhotonics Co.,Ltd. , https://www.cgphotonics.com