cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dsula
Adventurer
Adventurer
2,961 Views
Registered: ‎01-14-2008

fixed point sin and cos

Jump to solution

Hi,

 

According to the HLS user guide UG902 (v2017.4) February 2, 2018, page 238

it should be possible to synthesize the code below.

 

 

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

void gen(ap_fixed<8,4> x, ap_fixed<8,2> *s)
{
   *s = sin(x);
}

 

 

 

This code is in fact synthesizable, however I suspect it's actually implementing a double precision sin calculation instead of a simplified fixed point cordic or LUT or whatever solution. I base this on a few observations made during synthesis:

 

1. many messages related to double or float like this one:

WARNING: [HLS 200-40] Directive 'RESOURCE' for core 'ROM_1P_LUTRAM' cannot be applied: Variable 'second_order_float::sin_cos_K2' can not be recognized(UNKNOWN VARIABLE) in 'sin_or_cos_approximation'.

I have no idea what this warning means, as I did not specify an "RESOURCE" directive.

 

2. a ridiculously large design of 70x DSP48 and more than 2000x FF.

 

So here are the questions:

1. how can I get the fixed point sin instead of the (presumably) floating point version?

2. Is it possible to specify the design target to be the smallest possible design? Consider the code below:

 

void gen(int a, int b, int c, int d, int e, int f, int *z)
{
   *z = a+b+c+d+e+f;
}

In case I do not care about latency or interval, how can I get HLS to only implement one adder instead of 5? (and use a loop with muxes).

 

Or asked differently, with a specified latency (#pragma LATENCY) and interval (#pragma PIPELINE II) does HLS always generate the smallest possible design?

 

Thank you for any insight.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
jprice
Scholar
Scholar
3,249 Views
Registered: ‎01-28-2014

1. You have to use to use the hls namespace. This was my very first mistake in HLS :). Off the top of my head try hls::sin/hls::cos

 

2. There is an allocation directive for limiting the # of a particular resource within a function. I don't think HLS tries to produce the smallest design possible, but it tends to not be overkill for a given set of requirements. Except sometimes it bugs out so you have to watch it.  There is also project settings for trying to reuse resources, something related to binding, but I've found that it's fairly buggy in the past (Haven't tried in any 2017 versions). 

View solution in original post

3 Replies
jprice
Scholar
Scholar
3,250 Views
Registered: ‎01-28-2014

1. You have to use to use the hls namespace. This was my very first mistake in HLS :). Off the top of my head try hls::sin/hls::cos

 

2. There is an allocation directive for limiting the # of a particular resource within a function. I don't think HLS tries to produce the smallest design possible, but it tends to not be overkill for a given set of requirements. Except sometimes it bugs out so you have to watch it.  There is also project settings for trying to reuse resources, something related to binding, but I've found that it's fairly buggy in the past (Haven't tried in any 2017 versions). 

View solution in original post

dsula
Adventurer
Adventurer
2,945 Views
Registered: ‎01-14-2008

@jprice wrote:

1. You have to use to use the hls namespace. This was my very first mistake in HLS :). Off the top of my head try hls::sin/hls::cos


Nice one. That did the trick. Thank you.

0 Kudos
hamidnaghi1
Newbie
Newbie
1,219 Views
Registered: ‎05-08-2019

Hi,

 

I could use the #include "hls_math.h"  and then I used the following:

(ap_fixed<32,16>)DataTmp=  (ap_fixed<16,0>)(hls::sin(InX)) * (ap_fixed<16,16>)10000;

But once I changed the 10000 to a variable like Factor then the result(DataTmp) would be zero! Anyone could help me to find out why it would be zero?

ap_fixed<16,16> Factor=10000;
(ap_fixed<32,16>)DataTmp=  (ap_fixed<16,0>)(hls::sin(InX)) * (ap_fixed<16,16>)Factor;

 

Kind regards

Hamid

0 Kudos