Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Community Forums
- :
- Forums
- :
- Software Development and Acceleration
- :
- HLS
- :
- Re: Is implementation of lgamma() and tgamma() in ...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

nittax

Contributor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-25-2019 08:29 AM

1,092 Views

Registered:
11-10-2017

From this post. (https://forums.xilinx.com/t5/Vitis-SDAccel-and-SDSoC/SW-Emulation-Error-using-hls-math-function-in-C-Kernel-on/m-p/1036029)

In my development on SDAccel, I thought hls::lgamma() and hls::tgamma() does not calculate correct value.

In HLS use guide (UG902 v2019.1) , the limitation for input argument is as follows.

Fixed-Point Math Functions Fixed-point implementations are also provided for the following math functions. All fixed-point math functions support ap_[u]fixed and ap_[u]int data types with following bitwidth specification, 1. ap_fixed<W,I> where I<=33 and W-I<=32 2. ap_ufixed<W,I> where I<=32 and W-I<=32 3. ap_int<I> where I<=33 4. ap_uint<I> where I<=32

I have tested these functions on Vivado HLS 2019.1.

Case1 and Case 3 is incorrect. only case2 is correct.

Although both ap_fixed<32,10> and ap_fixed<10.5> satisfies the input argument limitation, I can't obtain correct result..

Any ideas? Thanks in advance.

0
Kudos

Reply

1 Solution

Accepted Solutions

nittax

Contributor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2019 06:51 PM

945 Views

Registered:
11-10-2017

I realized that the implementation of "hls_lgamma_apfixed.h" is ported from original lgamma() compatible for IEE754.

The original source code is here.

https://github.com/JuliaMath/openlibm/blob/master/src/e_lgamma_r.c

And In this implementation, when x < 8.0, y is fractional part of x.

In HLS library code, i is the integer part of x, so y is the value obtained by subtracting i from x. I don't know why, but **this code is commented out by default.(L264-266)**.

I could not understand what is doing in L255-262.** I commented out this part, and uncomment L264-266.** This works fine. I made my *own my_lgamma()* function because original source code is read-only.

0
Kudos

Reply

2 Replies

nittax

Contributor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2019 05:40 PM

957 Views

Registered:
11-10-2017

I am continuing to investigate this problem.

When to run *lgamma(2.2), *internal function *lgamma_generic()* is executed.

The implementation is in */tools/Xilinx/Vivado/2019.1/include/hls_lgamma_apfixed.h.*

The source code of lgamma approximation is a little complicated, but I found the code block to be executed.

Here is the source code.

I still don't understand this algorighm, but I found suspicious code.

In Line 258, *pos-51 *is always negative value.

But the type of ys.exp is ap_uint<11>. Assigning negative value to ys.exp means assign INF or NaN to ys. By this code, the warning *"assign NaN to fixed point value"* is showed in the console, and the result is wrong.

The declaration of fp_struct is as the following.

Is this a bug? or Is my understanding wrong?

0
Kudos

Reply

nittax

Contributor

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2019 06:51 PM

946 Views

Registered:
11-10-2017

I realized that the implementation of "hls_lgamma_apfixed.h" is ported from original lgamma() compatible for IEE754.

The original source code is here.

https://github.com/JuliaMath/openlibm/blob/master/src/e_lgamma_r.c

And In this implementation, when x < 8.0, y is fractional part of x.

In HLS library code, i is the integer part of x, so y is the value obtained by subtracting i from x. I don't know why, but **this code is commented out by default.(L264-266)**.

I could not understand what is doing in L255-262.** I commented out this part, and uncomment L264-266.** This works fine. I made my *own my_lgamma()* function because original source code is read-only.

0
Kudos

Reply