mirror of
https://github.com/Steffo99/unimore-hpc-assignments.git
synced 2024-11-22 08:04:25 +00:00
HLS code solutions
This commit is contained in:
parent
7983403734
commit
41bd48d575
14 changed files with 85 additions and 0 deletions
47
hls/lab1/SOL_exercise_3_4_5_matrix_mult.cpp
Normal file
47
hls/lab1/SOL_exercise_3_4_5_matrix_mult.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_SIZE 64
|
||||
|
||||
const unsigned int max_size = MAX_SIZE;
|
||||
|
||||
void mmult( int *in1,
|
||||
int *in2,
|
||||
int *out,
|
||||
int dim
|
||||
)
|
||||
{
|
||||
#pragma HLS INTERFACE m_axi port=in1 offset=slave bundle=in1_mem
|
||||
#pragma HLS INTERFACE m_axi port=in2 offset=slave bundle=in2_mem
|
||||
#pragma HLS INTERFACE m_axi port=out offset=slave bundle=out_mem
|
||||
|
||||
#pragma HLS INTERFACE s_axilite port=dim bundle=params
|
||||
#pragma HLS INTERFACE s_axilite port=return bundle=params
|
||||
|
||||
int in_1_loc [MAX_SIZE][MAX_SIZE];
|
||||
int in_2_loc [MAX_SIZE][MAX_SIZE];
|
||||
int out_loc [MAX_SIZE][MAX_SIZE];
|
||||
|
||||
#pragma HLS ARRAY_PARTITION variable=in_1_loc dim=2 complete
|
||||
#pragma HLS ARRAY_PARTITION variable=in_2_loc dim=1 complete
|
||||
|
||||
memcpy_1: memcpy(in1, in_1_loc, MAX_SIZE*MAX_SIZE*sizeof(int));
|
||||
memcpy_2: memcpy(in2, in_2_loc, MAX_SIZE*MAX_SIZE*sizeof(int));
|
||||
|
||||
loop_1: for (int i = 0; i < dim; i++){
|
||||
#pragma HLS LOOP_TRIPCOUNT max=max_size min=max_size
|
||||
loop_2: for (int j = 0; j < dim; j++){
|
||||
|
||||
#pragma HLS PIPELINE
|
||||
#pragma HLS LOOP_TRIPCOUNT max=max_size min=max_size
|
||||
|
||||
loop_3: for (int k = 0; k < MAX_SIZE; k++){
|
||||
|
||||
#pragma HLS LOOP_TRIPCOUNT max=max_size min=max_size
|
||||
|
||||
out_loc[i][j] += in_1_loc[i][k] * in_2_loc[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy_3: memcpy(out_loc, out, MAX_SIZE*MAX_SIZE*sizeof(int));
|
||||
}
|
38
hls/lab1/SOL_exercise_7_fir_filter_sreg.cpp
Normal file
38
hls/lab1/SOL_exercise_7_fir_filter_sreg.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#define SIZE 128
|
||||
#define N 10
|
||||
|
||||
void fir(int * input, int * output) {
|
||||
|
||||
#pragma HLS INTERFACE m_axi port=input offset=slave bundle=input_mem
|
||||
#pragma HLS INTERFACE m_axi port=output offset=slave bundle=output_mem
|
||||
|
||||
#pragma HLS INTERFACE s_axilite port=return bundle=params
|
||||
|
||||
int coeff[N] = {13, -2, 9, 11, 26, 18, 95, -43, 6, 74};
|
||||
int shift_reg[N] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
//TODO: insert array partition directive
|
||||
#pragma HLS ARRAY_PARTITION variable=shift_reg dim=0 complete
|
||||
|
||||
loop_1: for (int n = 0; n < SIZE; n++) {
|
||||
//TODO: insert pipeline directive
|
||||
#pragma HLS PIPELINE
|
||||
|
||||
int acc = 0;
|
||||
|
||||
loop_2: for(int j = N-1; j > 0; j--) {
|
||||
//TODO: insert unroll directive
|
||||
#pragma HLS UNROLL
|
||||
shift_reg[j] = shift_reg[j-1];
|
||||
}
|
||||
|
||||
shift_reg[0] = input[n];
|
||||
|
||||
loop_3: for (int j= 0; j< N; j++ ) {
|
||||
//TODO: insert unroll directive
|
||||
#pragma HLS UNROLL
|
||||
acc += shift_reg[j]*coeff[j];
|
||||
}
|
||||
output[n] = acc;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue