Skip to content

Instantly share code, notes, and snippets.

@salehjg
Created December 27, 2019 15:42
Show Gist options
  • Save salehjg/9dbd973d1b7b8ee84dd69640f15732ef to your computer and use it in GitHub Desktop.
Save salehjg/9dbd973d1b7b8ee84dd69640f15732ef to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define DATA_SIZE 17
#define VEC_SIZE 16
struct _float16{
float vec[VEC_SIZE];
};
typedef struct _float16 float16;
extern "C" {
void vadd_pipelined(float16 *c, const float16 *a, const float16 *b, const int len) {
#pragma HLS INTERFACE m_axi port = c offset = slave bundle = gmem1
#pragma HLS INTERFACE m_axi port = a offset = slave bundle = gmem2
#pragma HLS INTERFACE m_axi port = b offset = slave bundle = gmem3
#pragma HLS INTERFACE s_axilite port = c bundle = control
#pragma HLS INTERFACE s_axilite port = a bundle = control
#pragma HLS INTERFACE s_axilite port = b bundle = control
#pragma HLS INTERFACE s_axilite port = len bundle = control
#pragma HLS INTERFACE s_axilite port = return bundle = control
#pragma HLS data_pack variable=a
#pragma HLS data_pack variable=b
#pragma HLS data_pack variable=c
float16 result;
float16 buff;
for(int v=0;v<2;v++){
if((v+1)*VEC_SIZE -1 < len){
buff = a[v];
}else{
int bnd = len - (v)*VEC_SIZE;
for(int j=0;j<bnd;j++){
buff.vec[j] = a[v].vec[j];
}
}
for(int i=0;i<VEC_SIZE;i++){
if(v*VEC_SIZE+i<len){
result.vec[i] = buff.vec[i];
printf("v=%d, i=%d, read value A: %f\n", v, i, buff.vec[i]);
}
else
{
result.vec[i] = 0;
}
}
//----------------------------------------------------------------------
if((v+1)*VEC_SIZE -1 < len){
buff = b[v];
}else{
int bnd = len - (v)*VEC_SIZE;
for(int j=0;j<bnd;j++){
buff.vec[j] = b[v].vec[j];
}
}
for(int i=0;i<VEC_SIZE;i++){
if(v*VEC_SIZE+i<len){
result.vec[i] += buff.vec[i];
printf("v=%d, i=%d, read value B: %f\n", v, i, buff.vec[i]);
}
else
{
result.vec[i] = 0;
}
}
//----------------------------------------------------------------------
if((v+1)*VEC_SIZE -1 < len){
c[v] = result;
}else{
int bnd = len - (v)*VEC_SIZE;
for(int j=0;j<bnd;j++){
c[v].vec[j] = result.vec[j];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment