Reputation: 115
I am working with larger size matrix in Vivado HLS. As normal "int", its occupies lot of memory space and slow down the hardware speed.
So, for better optimization and performance, arbitrary precision (or bit-accurate) integer data types best. I have gone through the VIVADO User guide, i am not clear. But, I don`t know how to initialize “ap_int.h” or “ap_cin.h” for two-dimensional array. Can anyone clear me how to apply “ap_int.h” or “ap_cin.h” for below source code.
#define ROWS 102 //k
#define COLS 204
void GeneratorM(int msg[ROWS], int dout[COLS])
{
#pragma HLS INTERFACE s_axilite port=msg bundle=a
#pragma HLS INTERFACE s_axilite port=dout bundle=a
#pragma HLS INTERFACE s_axilite port=return bundle=a
int Generator[ROWS][COLS]= {0};
int G[ROWS][COLS] = {0};
int i,j,k,r,c,n;
k = ROWS;
r = ROWS;
c = COLS;
n = COLS;
static int H[ROWS][COLS];
int Codeword[COLS]= {0};
int s = 0;
for (i=0;i<k;i++)
for(j=0;j<k;j++)
if(i == j)
G[i][j] = 1;
for(i=0;i<r;i++)
for(j=0;j<k;j++)
G[j][k+i] = H[i][j];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
Generator[i][j]=G[i][j];
}
for(j=0;j<n;j++)
{
for(i=0;i<k;i++)
{
s = s + msg[i]*Generator[i][j];
}
Codeword[j] = s % 2;
s = 0;
}
for(i=0;i<n;i++)
{
dout[i]=Codeword[i];
}
}
Upvotes: 1
Views: 3113
Reputation: 201
C Based example of 10 bit int:
#include <ap_cint.h>
int10 foo;
C++ Based example of 10 bit int:
#include <ap_int.h>
ap_int<10> foo;
Rewriting your example to use an Arbitrary Precision Integer data type of size 10 bits in C looks like this and it complies nicely in HLS :)
#include <ap_cint.h>
#define ROWS 102 //k
#define COLS 204
typedef int10 arbitraryInt;
void GeneratorM(int msg[ROWS], int dout[COLS])
{
#pragma HLS INTERFACE s_axilite port=msg bundle=a
#pragma HLS INTERFACE s_axilite port=dout bundle=a
#pragma HLS INTERFACE s_axilite port=return bundle=a
arbitraryInt Generator[ROWS][COLS]= {0};
arbitraryInt G[ROWS][COLS] = {0};
arbitraryInt i,j,k,r,c,n;
k = ROWS;
r = ROWS;
c = COLS;
n = COLS;
static arbitraryInt H[ROWS][COLS];
arbitraryInt Codeword[COLS]= {0};
arbitraryInt s = 0;
for (i=0;i<k;i++)
for(j=0;j<k;j++)
if(i == j)
G[i][j] = 1;
for(i=0;i<r;i++)
for(j=0;j<k;j++)
G[j][k+i] = H[i][j];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
Generator[i][j]=G[i][j];
}
for(j=0;j<n;j++)
{
for(i=0;i<k;i++)
{
s = s + msg[i]*Generator[i][j];
}
Codeword[j] = s % 2;
s = 0;
}
for(i=0;i<n;i++)
{
dout[i]=Codeword[i];
}
}
Upvotes: 1