cancel
Showing results for
Did you mean:
Highlighted
811 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
469 Views
Registered: ‎10-23-2019

## Re: Why 'pow' cannot be synthesized?

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[8], complex<double> fft_G1[8], complex<double> fft_E1[8], 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
Highlighted
Teacher
789 Views
Registered: ‎07-09-2009

## Re: Why 'pow' cannot be synthesized?

is this of any help
https://forums.xilinx.com/t5/High-Level-Synthesis-HLS/hls-pow-function/td-p/791341
<== If this was helpful, please feel free to give Kudos, and close if it answers your question ==>
Highlighted
722 Views
Registered: ‎03-30-2018

## Re: Why 'pow' cannot be synthesized?

Dear @drjohnsmith ,

May I know, do you use LINUX?...or is anybody here use LINUX to run Vivado HLS?

Highlighted
Teacher
673 Views
Registered: ‎07-09-2009

## Re: Why 'pow' cannot be synthesized?

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.
<== If this was helpful, please feel free to give Kudos, and close if it answers your question ==>
Highlighted
561 Views
Registered: ‎03-30-2018

## Re: Why 'pow' cannot be synthesized?

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[8], complex<double> fft_G1[8], complex<double> fft_E1[8], 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
470 Views
Registered: ‎10-23-2019

## Re: Why 'pow' cannot be synthesized?

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[8], complex<double> fft_G1[8], complex<double> fft_E1[8], 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

Highlighted
332 Views
Registered: ‎03-30-2018

## Re: Why 'pow' cannot be synthesized?

Dear @jonbho ,

Thank you for your feedback. I will try to synthesize using this code.

Highlighted
291 Views
Registered: ‎03-30-2018

## Re: Why 'pow' cannot be synthesized?

Dear @jonbho ,

It works. Thank you.

Highlighted
Observer
270 Views
Registered: ‎10-23-2019