void MAT_Multiply(int A[50][50], int B[50][50], long C[50][50], unsigned char mA, unsigned char nA, unsigned char mB, unsigned char nB, unsigned char mC, unsigned char nC) { _ssdm_SpecArrayDimSize(A,50); _ssdm_SpecArrayDimSize(B,50); _ssdm_SpecArrayDimSize(C,50); _ssdm_op_SpecInterface(C, "ap_fifo", 0, 0, 0, 100, "", "", ""); # 8 "parta_2/matrixmath.c" _ssdm_op_SpecInterface(B, "ap_fifo", 0, 0, 0, 100, "", "", ""); # 8 "parta_2/matrixmath.c" _ssdm_op_SpecInterface(A, "ap_fifo", 0, 0, 0, 100, "", "", ""); # 8 "parta_2/matrixmath.c" unsigned char i, j, k; long temp; int A_cached_row[50]; int B_cached[50][50]; if ((nA == mB)&(mA == mC)&(nB==nC))//Multiplication only when the dimensions are suitable { Row: for (i=0; i<50; i++) Col: for (j=0; j<50; j++) { //Make sure the data is fully cached to avoid multiple read. temp = 0; if ((i<mC)&(j<nC)) { if (j==0) { //Cache the whole row of matrix A RowCaching: for (k=0; k<50; k++) A_cached_row[k]=A[i][k]; } //Cache all the columns of matrix B, see Fig. 7.21. B will be read only once if (i==0) { ColCaching: for (k=0; k<50; k++) B_cached[k][j]=B[k][j]; } Product: for (k=0; k<50; k++) { if (k<nA) temp += A_cached_row[k] * B_cached[k][j]; } } C[i][j] = temp; } } }
/** * output_000: The maximum value of an integer in the system. */ int targeted_function (int* output_000) { _ssdm_op_SpecInterface(output_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #31 "./targeted_functions/int_max/targeted_function.c" _ssdm_op_SpecInterface(0, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #31 "./targeted_functions/int_max/targeted_function.c" *output_000 = 2147483647; return 0; }
int multi_axim(int *x, int *y){ _ssdm_op_SpecInterface(y, "m_axi", 0, 0, 0, 10, "", "slave", ""); _ssdm_op_SpecInterface(x, "m_axi", 0, 0, 0, 10, "", "slave", ""); _ssdm_op_SpecInterface(0, "s_axilite", 0, 0, 0, 0, "", "", ""); for (int i=0; i<10; i++){ _ssdm_op_SpecPipeline(1, 1, 1, 0, ""); y[i] = x[i] * (x[i] + 1); } return 0; }
void acc_vadd(int *sI1, int *sI2, int *mO1) { _ssdm_op_SpecInterface(0, "ap_ctrl_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(sI1, "axis", 0, 0, 0, 16, "", "", ""); _ssdm_op_SpecInterface(sI2, "axis", 0, 0, 0, 16, "", "", ""); _ssdm_op_SpecInterface(mO1, "axis", 0, 0, 0, 16, "", "", ""); *mO1 = *sI1 + *sI2; }
void top(int out[1], int w[1000*1], int b[1000*1], int x[1000]) {_ssdm_SpecArrayDimSize(b,1000*1);_ssdm_SpecArrayDimSize(w,1000*1);_ssdm_SpecArrayDimSize(x,1000);_ssdm_SpecArrayDimSize(out,1); _ssdm_op_SpecInterface(out, "ap_memory", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(w, "ap_memory", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(b, "ap_memory", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(x, "ap_memory", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecResource(out, "", "RAM_1P", "", -1, "", "", ""); _ssdm_op_SpecResource(w, "", "RAM_1P", "", -1, "", "", ""); _ssdm_op_SpecResource(b, "", "RAM_1P", "", -1, "", "", ""); _ssdm_op_SpecResource(x, "", "RAM_1P", "", -1, "", "", ""); fully_connected_layer(out, w, b, x, 1000, 1); }
/** * output_000: The quotient of input_000 divided by 2. */ int targeted_function (int input_000, int* output_000) { _ssdm_op_SpecInterface(output_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/bitwise_right_shift/targeted_function.c" _ssdm_op_SpecInterface(input_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/bitwise_right_shift/targeted_function.c" _ssdm_op_SpecInterface(0, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/bitwise_right_shift/targeted_function.c" *output_000 = input_000 >> 1; return 0; }
int adders(int in1, int in2, int in3) { _ssdm_op_SpecInterface(0, "ap_ctrl_none", 0, 0, 0, 0, "", "", ""); // Prevent IO protocols on all input ports _ssdm_op_SpecInterface(in3, "ap_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(in2, "ap_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(in1, "ap_none", 0, 0, 0, 0, "", "", ""); int sum; sum = in1 + in2 + in3; return sum; }
/** * output_000: The product of input_000 and input_001. */ int targeted_function (int input_000, int input_001, int* output_000) { _ssdm_op_SpecInterface(output_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/multiplier/targeted_function.c" _ssdm_op_SpecInterface(input_001, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/multiplier/targeted_function.c" _ssdm_op_SpecInterface(input_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/multiplier/targeted_function.c" _ssdm_op_SpecInterface(0, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); #25 "./targeted_functions/multiplier/targeted_function.c" *output_000 = input_000 * input_001; return 0; }
void adder_top(int *a, int *b, int *c, int n) { _ssdm_op_SpecInterface(a, "ap_fifo", 0, 0, 0, 0, "", "", ""); #5 "hls_demo/.settings/adder.c" _ssdm_op_SpecInterface(a, "ap_fifo", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(b, "ap_fifo", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(c, "ap_fifo", 0, 0, 0, 0, "", "", ""); int i; int arrayA[1000]; _ssdm_SpecArrayPartition( arrayA, 1, "CYCLIC", 10, ""); #10 "hls_demo/.settings/adder.c" int arrayB[1000]; _ssdm_SpecArrayPartition( arrayB, 1, "CYCLIC", 10, ""); #11 "hls_demo/.settings/adder.c" int arrayC[1000]; _ssdm_SpecArrayPartition( arrayC, 1, "CYCLIC", 10, ""); #12 "hls_demo/.settings/adder.c" loop_read: for (i=0;i<1000;i++) { if (i<n) { arrayA[i] = a[i]; arrayB[i] = b[i]; arrayC[i] = 0; } } loop_add: for (i=0;i<1000;i++) { _ssdm_Unroll(1, 0, 10, ""); _ssdm_op_SpecPipeline(1, 1, 1, 0, ""); if (i<n) arrayC[i] = (arrayA[i]+arrayB[i]); } loop_write: for (i=0;i<1000;i++) { _ssdm_op_SpecPipeline(1, 1, 1, 0, ""); if (i<n) c[i] = arrayC[i]; } }
/** * output_000: The sum of input_000 and input_001. * output_001: The absolute value of the difference between input_000 and input_001. */ int targeted_function (int input_000, int input_001, int* output_000, int* output_001) { _ssdm_op_SpecInterface(output_001, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); # 26 "./targeted_functions/adder_subtractor/targeted_function.c" _ssdm_op_SpecInterface(output_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); # 26 "./targeted_functions/adder_subtractor/targeted_function.c" _ssdm_op_SpecInterface(input_001, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); # 26 "./targeted_functions/adder_subtractor/targeted_function.c" _ssdm_op_SpecInterface(input_000, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); # 26 "./targeted_functions/adder_subtractor/targeted_function.c" _ssdm_op_SpecInterface(0, "s_axilite", 0, 0, 0, 0, "rm", "", "", ""); # 26 "./targeted_functions/adder_subtractor/targeted_function.c" *output_000 = input_000 + input_001; *output_001 = input_000 - input_001 < 0 ? input_001 - input_000 : input_000 - input_001; return 0; }
void acc_vadd_hls ( volatile int *cmd, volatile int *resp, int a[4096], int b[4096], int result[4096] ) {_ssdm_SpecArrayDimSize(result,4096);_ssdm_SpecArrayDimSize(b,4096);_ssdm_SpecArrayDimSize(a,4096); _ssdm_op_SpecInterface(0, "ap_ctrl_none", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(cmd, "axis", 0, 0, 0, 16, "", "", ""); _ssdm_op_SpecInterface(resp, "axis", 0, 0, 0, 16, "", "", ""); _ssdm_op_SpecInterface(a, "bram", 0, 0, 0, 1024, "", "", ""); _ssdm_op_SpecInterface(b, "bram", 0, 0, 0, 1024, "", "", ""); _ssdm_op_SpecInterface(result, "bram", 0, 0, 0, 1024, "", "", ""); _ssdm_op_SpecResource(a, "", "RAM_1P_BRAM", "", "", "", ""); _ssdm_op_SpecResource(b, "", "RAM_1P_BRAM", "", "", "", ""); _ssdm_op_SpecResource(result, "", "RAM_1P_BRAM", "", "", "", ""); int i,op, start,end; // Accumulate each channel op = *cmd; //get the start command end = *cmd; start = *cmd; if (op == 1) add_Loop: for (i = start; i < end; i++) {_ssdm_op_SpecLoopName("add_Loop");_ssdm_RegionBegin("add_Loop"); result[i]= a[i] + b[i]; if (i == end-1) { *resp= 1; //means I am done. } _ssdm_RegionEnd("add_Loop");} else if (op == 2) sub_Loop: for (i = start; i < end; i++) {_ssdm_op_SpecLoopName("sub_Loop");_ssdm_RegionBegin("sub_Loop"); result[i]= b[i] + a[i]; if (i == end-1) { *resp= 1; //means I am done. } _ssdm_RegionEnd("sub_Loop");} }
void fir ( data_t *y, coef_t c[11], data_t x ) {_ssdm_SpecArrayDimSize(c,11); _ssdm_op_SpecResource(c, "", "RAM_1P_BRAM", "", -1, "", "", ""); # 52 "fir.c" _ssdm_op_SpecInterface(y, "ap_vld", 0, 0, 0, 0, "", "", ""); _ssdm_op_SpecInterface(x, "ap_vld", 0, 0, 0, 0, "", "", ""); static data_t shift_reg[11]; _ssdm_SpecArrayPartition( shift_reg, 1, "COMPLETE", 0, ""); # 59 "fir.c" acc_t acc; data_t data; int i; acc=0; Shift_Accum_Loop: for (i=11 -1;i>=0;i--) { _ssdm_Unroll(0,0,0, ""); # 65 "fir.c" if (i==0) { shift_reg[0]=x; data = x; } else { shift_reg[i]=shift_reg[i-1]; data = shift_reg[i]; } acc+=data*c[i];; } *y=acc; }
void MAT_Multiply(int A[100][100], int B[100][100], long C[100][100], unsigned char mA, unsigned char nA, unsigned char mB, unsigned char nB, unsigned char mC, unsigned char nC) {_ssdm_SpecArrayDimSize(A,100);_ssdm_SpecArrayDimSize(B,100);_ssdm_SpecArrayDimSize(C,100); _ssdm_op_SpecInterface(C, "ap_fifo", 0, 0, 0, 0, "", "", ""); #8 "parta_2/matrixmath.c" _ssdm_op_SpecInterface(B, "ap_fifo", 0, 0, 0, 0, "", "", ""); #8 "parta_2/matrixmath.c" _ssdm_op_SpecInterface(A, "ap_fifo", 0, 0, 0, 0, "", "", ""); #8 "parta_2/matrixmath.c" unsigned char i, j, k; long temp; int A_cached_row[100]; _ssdm_SpecArrayPartition( A_cached_row, 1, "CYCLIC", 10, ""); #11 "parta_2/matrixmath.c" int B_cached[100][100]; _ssdm_SpecArrayPartition( B_cached, 1, "COMPLETE", 10, ""); #12 "parta_2/matrixmath.c" if ((nA == mB)&(mA == mC)&(nB==nC))//Multiplication only when the dimensions are suitable { Row: for (i=0; i<100; i++) Col: for (j=0; j<100; j++) { //Make sure the data is fully cached to avoid multiple read. if ((i<mC)&(j<nC)) { temp = 0; if (j==0) { //Cache the whole row of matrix A RowCaching: for (k=0;k<100;k++) _ssdm_Unroll(1, 0, 20, ""); #28 "parta_2/matrixmath.c" A_cached_row[k]=A[i][k]; } //Cache all the columns of matrix B, see Fig. 7.21. B will be read only once if (i==0) { ColCaching: for (k=0;k<100;k++) _ssdm_Unroll(1, 0, 20, ""); #35 "parta_2/matrixmath.c" B_cached[k][j]=B[k][j]; } Product: for (k=0; k<100; k++) { _ssdm_Unroll(1, 0, 20, ""); #39 "parta_2/matrixmath.c" if (k<nA) temp += A_cached_row[k] * B_cached[k][j]; } C[i][j] = temp; } } } }