cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor
9,730 Views
Registered: ‎12-04-2014

What fixed and float arithmetic function can be synthesis in vivado hls?

Hi, 

   Can fixed point / floating point function such as cos , acos , sqrt be synthesis in vivado hls ?

   where can I get such information ?

 

0 Kudos
5 Replies
Highlighted
Explorer
Explorer
9,717 Views
Registered: ‎09-02-2013

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

#include "hls_math.h"

This should give you access to such synthesizable functions.

0 Kudos
Highlighted
Moderator
Moderator
9,699 Views
Registered: ‎04-17-2011

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

For details refer page 286 onward of the document: http://www.xilinx.com/support/documentation/sw_manuals/xilinx2015_1/ug902-vivado-high-level-synthesis.pdf
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
Contributor
Contributor
9,688 Views
Registered: ‎12-04-2014

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

It listed only floating point function , no fixed point function.

for resource consideration, I'd like to use fixed point functions.

The document says fixed point function also supported by a complex way as follows :

 

• Review Table 2-5 to determine if a fixed-point implementation is supported.
• Update the math functions to use ap_fixed types.
• Perform C simulation to validate the design still operates with the required precision.
The C simulation is performed using the same bit-accurate types as the RTL
implementation.
• Synthesize the design.

 

The first step, Table 2-5 list only floating point function , no fixed point function.

The second step. Does it mean that I should copy the source code of floating point functions and rewrite it in fixed point ?

 

here is my source code converting rgb to hsi, fixed point min/max/sqrt/acos/atan are not reported as error.

 

#include "hls_math.h"
#include "ap_fixed.h"

void rgb2hsi( ap_uint<8> r, ap_uint<8> g, ap_uint<8> b, ap_uint<8> *h, ap_uint<8> *s, ap_uint<8> *i)

{
    ap_ufixed<16,8> rr,gg,bb;
    ap_ufixed<16,8> min_val, max_val ;
    ap_fixed<16,8> ss, hh, ii ;
    ap_fixed<32,16> t1,t2,t3 ;
    ap_ufixed<32,16> theta ;

    rr = r ; gg = g ; bb = b ;
    rr = rr>>8 ; gg = gg>>8 ; bb = bb>>8 ;
    ii = (rr+gg+bb)*(ap_ufixed<16,0>)0.333333;

    min_val = fmin( rr , gg ) ;
    min_val = fmin( bb , min_val ) ;
    max_val = fmax( rr , gg ) ;
    max_val = fmax( bb , min_val ) ;

    if(max_val == min_val)
    {
         ss = 0;
        hh = -1.0;
    }
    else
    {
        // c
        ss = 1 - 3 * min_val / ( rr + gg + bb ) ;

        // h
        t1 = (rr - gg + rr - bb )/2 ;
        t2 = (rr-gg)*(rr-gg)+(rr-bb)*(gg-bb) ;
        t3 = t1 / t2 ;
        theta = atanf(t3) ;    // acos not supported, use atanf instead

        if (b > g)
        {
            hh = 2 - theta;
        }
        else
        {
            hh = theta;
        }
    }
    *h = hh ;
    *s = ss ;
    *i = ii ;
}

 

0 Kudos
Highlighted
2,820 Views
Registered: ‎06-13-2017

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

I have the same problem. I have a code using abs and pow using exp and log functions in hls_math library. I wanted to optimize it by doing a fixed point but it seems hls_math has no support of the ap_fixed<> type. any suggestions?

0 Kudos
Highlighted
Visitor
Visitor
2,808 Views
Registered: ‎05-10-2017

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

Hello,

 

For cos, you should be able to use the DDS ip for a fixed point implementation. Or write your own look-up table implementation.

 

I don't think there is built-in fixed point IP for the other functions you mentioned, however, there is some examples of CORDIC based square root and atan here that may help:

https://github.com/Xilinx/HLx_Examples/tree/master/Math.

 

You can also use Newton's method to implement these, but I don't know of a ready to go example anywhere. The issue is that for something like atan or sqrt, when you get close to the boundaries, fixed point solutions have a lot of error, or require a lot of iterations in order to get an accurate result. So if you need a lot of accuracy close to the boundaries it may not be much more efficient to use fixed instead of floating point. Of course it depends a lot on what your system requirements are, but this is something to consider.

 

Hope this helps,

eschei 

 

 

0 Kudos