-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Future of openlibm in julia #18102
Comments
also just fwiw, the libm on Windows hasn't changed, so it's the one platform where this is still a major improvement over the system version. linking with openlibm helped get some of the blas / lapack testsuite to pass back in the day. |
I would have expected them to have fixed their libm in the last 5 years. Well, so just means that we have to do something - but perhaps it can be sleef rather than openlibm. |
For sake of "Julia is built on julia", it would be nice if On the other hand, that does mean maintaining own libm still. |
There's also musl libc's libm implementation which is largely derived from the same original freebsd sources but with a different set of improvements: http://git.musl-libc.org/cgit/musl/tree/src/math Why isn't this issue in the openlibm repository? |
I guess the point was the future of openlibm in julia - as in might we have something different, more than openlibm itself. |
One advantage of having libm functions coded in Julia (this doesn't have to be a all-or-nothing step) is that code generation choices such as |
There are definite benefits to having this implemented in Julia. The sleef approach is perhaps the one to follow for maximum simd benefits - but the code is not that pretty to look at. I wonder how we might fare. |
With multiple dispatch and multiple return values, Sleef's code size should shrink by one half. Add generic programming, and the code size will reduce further. I have great hopes. |
It does seem to have lots of code to handle different sizes of vector registers. I don't know how our autovectorization will stack - but there is only one way to find out. |
In that spirit, I've created: Once we're happy with it, we can look at merging it into Base. |
sleef doesn't appear to have a license. |
Sleef is in the public domain: "The software is in public domain. You can use the software without any obligation." https://github.com/shibatch/sleef. |
On some looking for more info on SLEEF: If that were done, then I guess we would just use that? Though right now we don't use too many of the existing LLVM math functions, see #12830. edit: Oh I see this was mentioned in the OP. Teach me not for reading closely. |
@ViralBShah: how much effort is maintaining openlibm these days? My impression is that it's not all that much work. What was the motivation for opening this issue? |
openlibm is years out-of-date w.r.t. bugfixes and improvements in the upstream sources: JuliaMath/openlibm#101, JuliaMath/openlibm#118 |
Also upstream and us have diverged a fair bit. While this work is doable, it is tedious and I have tried and given up on two occasions. |
I have ported some functions from musl at (see erf/erc at JuliaMath/Libm.jl#3) and also the pending exp (wip) port. Based on my tests these ports are essentially within testing noise in terms of speed (some cases faster some cases slower) the erf function is just as fast if not faster, while erfc is a little more variable but is usually not slower than 1.5 times the versions in base. My question: is this exercise worth pursuing to its fullest (julia ports of libm math functions), i.e. is there a possibility that these will be used in base in the near future or is this just an academic exercise. Looking at the musl logs, the math functions get bug fixes ever so rarely (maybe once every 6 months). |
My preference is that we should seriously look into porting something like sleef. The approach there should yield code that lends itself to auto-vectorization. I personally would push hard for a pure julia libm, as it will help push the compiler, and also give us code that many can hack on. |
There's the potential in the future to compile a pure Julia libm to .so form that can be called from C and other languages. In that case, Julia could just be considered a very terse code generator. |
Even then, we should make sure we have a mechanism for regularly flagging and incorporating that kind of change, until Stefan's scenario becomes a reality and Julia-defined versions of these become the upstream for other users. |
While we need a better way to sync with whatever upstream we end up using, the bigger issue is lack of sufficient tests for most libm implementations (except perhaps the stuff crlibm built). I really wish we had adequate easily accessible testing for each of these functions and all the corner cases. |
Fortunately, that's significantly easier to build out in Julia than in C – we have access to high precision libraries (BigFloat, DoubleDouble, ArbFloat) and things like ValidatedNumerics. |
Ok, I'll continue to port more function (and I'll try sleef) since it looks like there is agreement that a pure Julia math library is a profitable option forward. Is source to source conversion a viable option in the near future such that what I'm doing now is wasted effort ? Tbh I'm not familiar with how long such an infrastructure would take to build.
|
I think it is non-trivial to get good source-to-source conversion, and the benefits of being Julian will be lost. I think translation + tests + keeping an eye on the upstream is perhaps the right way to go. |
It's worth pointing out that there is a bunch of discussion at Libm.jl: https://github.com/JuliaMath/Libm.jl/issues Best to leave this issue open, only to close it at the right time when we have a real replacement. In the meanwhile, let's redirect discussion to Libm.jl. Otherwise, we are repeating the same things in both places. |
So I bound SLEEF to Happy to take issues and PRs over there. |
It seems like we've decided to go ahead with the Julia libm project. Should we close this now? |
Now that #20427 is merged, which (almost?) removes openspecfun.so. I've partially lost track of where things are at.
My rough understanding was that work started with https://github.com/JuliaMath/Libm.jl/ then @musm basically solo'd a complete rewrite of Sleef in pure julia. @musm was unhappy with the accuracy of SLEEF, So now it should be roughly possible to swap-out openlibm.so for musm/sleef.jl, Have I got that right @musm , @simonbyrne ? |
I would also be interested in a summary of what's going on with various libm-like efforts. |
Brief conclusions: Then I started working on Amal, I spent a ton of time trying to develop better functions (not gonna mention how, but the process is very tedious in general). While it's possible to develop fast function it's really hard to develop fast and accurate functions (< 1 ulp). My conclusion is that the Amal algorithms should be inspired by the msum versions.
I can submit a PR for an updated exp10 function (I think it's something like 100 times faster) if people want, it blows the water out of the current function version, which just calls the |
A pure Julia exp10 sounds like a good start (since at the moment we just call |
+1 to getting a faster and slightly less accurate exp10. |
cross-ref: #21445 ("Add pure julia exp10 function"). |
The solution to this is the pure Julia libm which is mostly done, and the work is now being tracked in #26434. |
Back when we started the julia project, there were enough libm libraries in the wild that did strange things and having our own openlibm made sense. It was a fork from freebsd's msun, which has been patched heavily and works well for us now. The downside is that there are years of accumulated patches in the original msun that we are missing, and it is not straightforward to port them.
There is the larger issue of whether we should continue to have openlibm, since most libms have greatly improved on that front, and issues that we discover can be fixed by having julia versions now.
@tkelman also pointed me to sleef that may allow for better vectorization and may potentially become part of llvm, which may be a good direction for us to go in. That whole thread is worth reading.
Would love to hear thoughts from others on what to do with openlibm maintenance going forward:
Edit: Updated the options above to reflect the discussion. (VBS)
The text was updated successfully, but these errors were encountered: