mirror of
https://github.com/Steffo99/unimore-hpc-assignments.git
synced 2024-11-21 23:54:25 +00:00
hls vector add co-simulation
This commit is contained in:
parent
b558d22f47
commit
9a9a8ba614
7 changed files with 1085 additions and 56 deletions
|
@ -1,11 +0,0 @@
|
|||
#ifndef VADD_HPP
|
||||
#define VADD_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//#define TEST_DATA_SIZE 4194304 // 2^22
|
||||
#define TEST_DATA_SIZE 12
|
||||
|
||||
void vadd(int *a, int *b, int *c, const int len);
|
||||
|
||||
#endif
|
1024
hls/lab1/exercise_0/ground_truth.txt
Normal file
1024
hls/lab1/exercise_0/ground_truth.txt
Normal file
File diff suppressed because it is too large
Load diff
41
hls/lab1/exercise_0/main_tb.cpp
Normal file
41
hls/lab1/exercise_0/main_tb.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vadd.h"
|
||||
|
||||
int main () {
|
||||
|
||||
int n = max_elem;
|
||||
|
||||
int * a = (int *) malloc(n*sizeof(int));
|
||||
int * b = (int *) malloc(n*sizeof(int));
|
||||
int * c = (int *) malloc(n*sizeof(int));
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = i;
|
||||
b[i] = 2*i;
|
||||
}
|
||||
|
||||
sum (a, b, c, n);
|
||||
|
||||
FILE *fp = fopen("ground_truth.txt", "r");
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
||||
int buff;
|
||||
|
||||
fscanf(fp, "%d", &buff);
|
||||
|
||||
if (buff != c[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
|
||||
return 0;
|
||||
}
|
15
hls/lab1/exercise_0/vadd.cpp
Normal file
15
hls/lab1/exercise_0/vadd.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "vadd.h"
|
||||
|
||||
void sum (int *a, int *b, int *c, int n) {
|
||||
|
||||
#pragma HLS INTERFACE s_axilite port=n bundle=regfile
|
||||
#pragma HLS_INTERFACE s_axilite port=return bundle=regfile
|
||||
#pragma HLS INTERFACE m_axi port=a offset=slave depth=max_elem bundle=a_mem
|
||||
#pragma HLS INTERFACE m_axi port=b offset=slave depth=max_elem bundle=bc_mem
|
||||
#pragma HLS INTERFACE m_axi port=c offset=slave depth=max_elem bundle=bc_mem
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
#pragma HLS LOOP_TRIPCOUNT min=max_elem max=max_elem
|
||||
c[i] = a[i] + b[i];
|
||||
}
|
||||
}
|
5
hls/lab1/exercise_0/vadd.h
Normal file
5
hls/lab1/exercise_0/vadd.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
//const int max_elem = 4194304; // for testing
|
||||
const int max_elem = 1024; // for co-simulation
|
||||
|
||||
|
||||
void sum (int *a, int *b, int *c, int n);
|
|
@ -1,17 +0,0 @@
|
|||
#include "exercise_0.hpp"
|
||||
|
||||
const unsigned int c_dim = TEST_DATA_SIZE;
|
||||
|
||||
void vadd(int *a, int *b, int *c, const int len)
|
||||
{
|
||||
#pragma HLS INTERFACE m_axi port=a offset=slave depth=c_dim bundle=mem
|
||||
#pragma HLS INTERFACE m_axi port=b offset=slave depth=c_dim bundle=mem
|
||||
#pragma HLS INTERFACE m_axi port=c offset=slave depth=c_dim bundle=mem
|
||||
#pragma HLS INTERFACE s_axilite port=len bundle=params
|
||||
#pragma HLS INTERFACE s_axilite port=return bundle=params
|
||||
|
||||
loop: for(int i = 0; i < len; i++) {
|
||||
#pragma HLS LOOP_TRIPCOUNT min=c_dim max=c_dim
|
||||
c[i] = a[i] + b[i];
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "exercise_0.hpp"
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
||||
int * a = (int *)malloc(TEST_DATA_SIZE*sizeof(int));
|
||||
int * b = (int *)malloc(TEST_DATA_SIZE*sizeof(int));
|
||||
int * c = (int *)malloc(TEST_DATA_SIZE*sizeof(int));
|
||||
|
||||
for(int i = 0; i < TEST_DATA_SIZE; i++) {
|
||||
a[i] = i*i;
|
||||
b[i] = i;
|
||||
}
|
||||
|
||||
vadd(a, b, c, TEST_DATA_SIZE);
|
||||
|
||||
for(int i = 0; i < TEST_DATA_SIZE; i++) {
|
||||
printf("%d\n", c[i]);
|
||||
}
|
||||
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue