MAlek2
New Contributor
6 years agoDivision in HLS doesn't work
I'm trying to write a simple matrix inversion program and the generate an HDL code from it.
I'm working with fixed point math. Here is a part of my code:
typedef ac_fixed<40, 20, true> fixed_40_20_t;
hls_register fixed_40_20_t matrix_A_src[8][16];
hls_register fixed_40_20_t matrix_A_temp_mult[16];
hls_register ac_fixed<60, 20, true> div_res;
hls_register fixed_40_20_t numerator;
hls_register fixed_40_20_t denominator;
for (int i = 0; i < 8; ++i)
{
#pragma unroll
for (int p = 0; p < 16; ++p)
{
denomerator = matrix_A_src[i][i];
if(i == p)
matrix_A_src[i][p] = 1;
else
{
numerator = matrix_A_src[i][p];
div_res =numerator / denominator;
matrix_A_src[i][p] = div_res;
}
}
for (int k = 0; k < 8; ++k)
{
if(k != i)
{
for (int j = 0; j < 16; ++j)
{
matrix_A_temp_mult[j] = matrix_A_src[k][j] * matrix_A_src[i][j];
}
#pragma unroll
for (int j = 0; j < 16; ++j)
{
matrix_A_src[k][j] = matrix_A_src[k][j] - matrix_A_temp_mult[j];
}
}
}
}The problem is in division operator. It does not divide at all and after two cycles of division the program gives an exception and crushes. But if i change division to another operator, like multiply, all program works good.
In examples i could't find any example of fixed point division.
Also a simple code like this:
typedef ac_fixed<40, 20, true> fixed_40_20_t;
hls_register ac_fixed<60, 20, true> c;
hls_register fixed_40_20_t a,b;
a = 123.456;
b = 34.56;
c = a / b;
printf(" %f \n", c.to_double());gives the answer
c = 3.572222 which is right