cancel
Showing results for
Show  only  | Search instead for
Did you mean:  1,589 Views
Registered: ‎03-30-2018

## Why 'pow' cannot be synthesized?

Hello,

I tried to synthesize my project in HLS using C++ codes. However, the function of 'pow' cannot be synthesized. I tried to synthesize my algorithm using Vivado HLS 2019.2 version, unfortunately, it still gives me the same error as below: Please, can someone give me any idea how to solve this problem?

1 Solution

Accepted Solutions  Observer
1,247 Views
Registered: ‎10-23-2019

Hello @nurulhuda,

I can't help you with getting pow() to synthesize, I guess you would need to research into the HLS accelerated math library, but I don't know the details. On the other hand, I have had a look at your code, and there is one very simple thing you can certainly do: in all cases were your code uses pow(), the second argument (the exponent) is 2. That means that you are using pow() to square the first argument, and you can do that without calling pow(), just by multiplying the argument by itself, which HLS will undoubtedly be able to synthesize using one to a few DSP48Es (multiplying double-precision floating point values may require more than one DSP48E).

Here is a version of your code modified in the way I am describing, I haven't tested it but it should compile, synthesize, and run correctly:

```//Function to divide
void divideComplex(complex<double> J, complex<double> fft_G1, complex<double> fft_E1, int row)
{
loop7:for (int i = 0; i < row; i++)
{
double a, b;

double re, im, re2, im2, re2im2, inv_re2im2;

re = real(fft_E1[i]);
im = imag(fft_E1[i]);
re2 = re * re;
im2 = im * im;
re2im2 = re2 + im2;
inv_re2im2 = 1.0 / re2im2;

a = (((real(fft_G1[i])) * (real(fft_E1[i]))) + ((imag(fft_G1[i])) * (imag(fft_E1[i])))) * inv_re2im2
b = (((real(fft_E1[i]))*(imag(fft_G1[i]))) - ((real(fft_G1[i]))*(imag(fft_E1[i]))))     * inv_re2im2;

J[i] = complex<double>(a, b);
}
}```

Also notice how I have optimized it in several ways, by calculating repeated values only once, and by doing only one division, since both divisions are by the same denominator, and pre-computing the inverse and multiplying twice is probably going to go faster (but you should always test yourself to verify it, it may be that I am introducing one more delay cycle and that the only savings is in using less area since it's just one division).

Best luck,

-- Jon

8 Replies  Teacher
1,567 Views
Registered: ‎07-09-2009
is this of any help
https://forums.xilinx.com/t5/High-Level-Synthesis-HLS/hls-pow-function/td-p/791341  1,500 Views
Registered: ‎03-30-2018

Dear @drjohnsmith ,

May I know, do you use LINUX?...or is anybody here use LINUX to run Vivado HLS?  Teacher
1,451 Views
Registered: ‎07-09-2009
I don't tend to get involved in HLS ,
but from what I see, the few people that are using HLS are based on Linux,
Its evident from the support answers one sees, that Xilinx are heavily use Linux.  1,339 Views
Registered: ‎03-30-2018

Hello @drjohnsmith

I still could not solve the problem with 'pow'. I have tried to run my synthesize in a different version of Vivado such as Vivado version 2018.3, 2019.1, and 2019.2. Unfortunately, it failed.

Then, I tried to synthesize with Linux, and again it failed. Vivado gave me the same error which mentioned that ' Please, do you have any idea what is wrong with my 'pow' function? How am I going to fix it?

```//Function to divide
void divideComplex(complex<double> J, complex<double> fft_G1, complex<double> fft_E1, int row)
{
loop7:for (int i = 0; i < row; i++)
{
double a, b;

a = (((real(fft_G1[i])) * (real(fft_E1[i]))) + ((imag(fft_G1[i])) * (imag(fft_E1[i])))) / (pow(real(fft_E1[i]), 2) + pow(imag(fft_E1[i]), 2));
b = (((real(fft_E1[i]))*(imag(fft_G1[i]))) - ((real(fft_G1[i]))*(imag(fft_E1[i])))) / (pow(real(fft_E1[i]), 2) + pow(imag(fft_E1[i]), 2));

J[i] = complex<double>(a, b);
}
}```

Thank you.  Observer
1,248 Views
Registered: ‎10-23-2019

Hello @nurulhuda,

I can't help you with getting pow() to synthesize, I guess you would need to research into the HLS accelerated math library, but I don't know the details. On the other hand, I have had a look at your code, and there is one very simple thing you can certainly do: in all cases were your code uses pow(), the second argument (the exponent) is 2. That means that you are using pow() to square the first argument, and you can do that without calling pow(), just by multiplying the argument by itself, which HLS will undoubtedly be able to synthesize using one to a few DSP48Es (multiplying double-precision floating point values may require more than one DSP48E).

Here is a version of your code modified in the way I am describing, I haven't tested it but it should compile, synthesize, and run correctly:

```//Function to divide
void divideComplex(complex<double> J, complex<double> fft_G1, complex<double> fft_E1, int row)
{
loop7:for (int i = 0; i < row; i++)
{
double a, b;

double re, im, re2, im2, re2im2, inv_re2im2;

re = real(fft_E1[i]);
im = imag(fft_E1[i]);
re2 = re * re;
im2 = im * im;
re2im2 = re2 + im2;
inv_re2im2 = 1.0 / re2im2;

a = (((real(fft_G1[i])) * (real(fft_E1[i]))) + ((imag(fft_G1[i])) * (imag(fft_E1[i])))) * inv_re2im2
b = (((real(fft_E1[i]))*(imag(fft_G1[i]))) - ((real(fft_G1[i]))*(imag(fft_E1[i]))))     * inv_re2im2;

J[i] = complex<double>(a, b);
}
}```

Also notice how I have optimized it in several ways, by calculating repeated values only once, and by doing only one division, since both divisions are by the same denominator, and pre-computing the inverse and multiplying twice is probably going to go faster (but you should always test yourself to verify it, it may be that I am introducing one more delay cycle and that the only savings is in using less area since it's just one division).

Best luck,

-- Jon  1,110 Views
Registered: ‎03-30-2018

Dear @jonbho ,

Thank you for your feedback. I will try to synthesize using this code.  1,069 Views
Registered: ‎03-30-2018

Dear @jonbho ,

It works. Thank you.  Observer
1,048 Views
Registered: ‎10-23-2019

@nurulhuda great to hear, thanks for letting me know. Very happy to have helped! :)