-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed point std_exp
#404
Fixed point std_exp
#404
Conversation
Wow; awesome work digging into the right way to do this!!! Crazy that the fractional part needs a polynomial approximation. One other random idea occurs to me: depending on the width, it could be efficient approximate the fractional part with a lookup table. Basically, the unit could hard-code a mapping from Anyway, not sure if that's a good idea—just a thought. |
I like this idea because it means I can do most of the calculations in regular floating point, and then only need to convert to fixed point with the final compute. I'll try this, and see if I run into any potential issues. An obvious constraint I foresee is table size, since a 2^16 table is less than ideal, but I imagine we can get away with fewer entries somehow if this is necessary. |
Awesome! Yeah, after a certain point, a lookup table becomes unwieldy. But perhaps just using a lower precision (i.e., dropping the fractional bits beyond a given fixed maximum) wouldn't be too bad! 😇 |
Ok I've written up a component for The Results: Using larger exponents leads to larger errors, as expected. |
Incredibly cool. That seems like a not-bad approximation, all things considered, and it's awesome that this is a reasonably low-complexity way to get the result in hardware. Of course, aside from this specific advancement, I can't help but think about other implications:
|
@cgyurgyik are you waiting on a PR/review for this? |
I wasn't. I got sidetracked with looking at fixed point libraries. Perhaps we could continue with this until we find something better? I imagine the one unnatural dependency here is the requirement that we use |
Yeah, that sounds good to me! In an idealized future, we'd want to generate tables for arbitrary precisions, but I think sticking to just this one for now is a good step. 👍 |
In that case, merge it when ready! (Unless you're waiting on #292) |
Sounds good. I'm currently messing around to see how easily we can actually drop this into another calyx component. |
Currently just getting zeroes back, presumably because its using the integer-based |
Remind me—is this blocked on the new data format stuff? If so, can you mark it with the "blocked" label? |
Not blocked. Going to close with the #463.
I'm closing this for now. I'll come back to it at a later point, but I think finding or implementing a real SV |
From initial research, it seems that a common way to implement
pow
approximations is to first implemente^x
, and use its properties to implement otherpow
s.I am breaking the exponent
x
into its integer value and its fractional value,For the integer value, we can simply multiply
e
n times, where n is the integer value. For the fractional value, I am using Chebyshev polynomials to approximatee^x
bounded by [0, 1].Currently, I'm just converting the decimal value of the number to floating point. Instead, all the math should also be done in fixed point. This might get tricky, given things such as overflow.
Addresses #299.