-
-
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
faster randn with ifelse #9126
faster randn with ifelse #9126
Conversation
branch-free code for the win! |
This is awesome! I have another suggestion - would be great if you can try it out. If we can separate out the else part of |
Cc: @JuliaBackports |
Seems like have the same code on the Edit seems like Viral had the same idea, but I didn't see it before posting |
This change is interesting enough to be a blog post about |
This is the poster child for ifelse because the branch is inherently unpredictable, so you're going to get pipeline stalls 50% of the time – which is awful for performance. |
-1 on backporting this, especially right as we're trying to get a tag out the door. |
This also paves the way for |
I'm also negative on holding back 0.3.3 for this. We should rather do 0.3.4 in two weeks, if we think it is that important.
|
Ok, let's not have this block the 0.3.3 release. Agree this can wait for 0.3.4, or even 0.4. |
I verify the 50% speedup on my mac as well. @alanedelman You might love a 50% performance bump in |
All credits to @ViralBShah (cf. #8941 and #9126). This change probably allows better inlining.
All credits to @ViralBShah (cf. #8941 and #9126). This change probably allows better inlining.
0.3.4-pre is open so we could consider backporting a 0.3-syntax version of this, as long as the same performance comparison applies there. Also a broader issue of the large number of RNG-related changes on 0.4 recently which have been diverging further and further from 0.3. I have no idea which, if any, would be safe/appropriate to backport at this time, and I don't think Ivar or Elliot know either. We should either:
|
Thanks to @rfourquet Backport of #9126 (from 376afcf)
This seemed pretty easy to backport, so I took the chance in 9f76ed3. Unless someone steps up and want to redo some part of the recent work on release-0.4, I think we should leave the APIs as is. |
There are a couple of things. The segfault fixed recently and faster array fill. The refactoring of randn. There were a few other perf improvements too, for random integers and such. But we can't do any of the api changes and the work is all mixed up. So all this has to be pretty much done again on 0.3. |
I could do some backport, but am not sure yet what amount of work this implies and if it's worth it. I have few questions:
I wonder if the simplest wouldn't be to start from master's file and then to disable things to make the API match with that of 0.3. |
|
Perhaps all this suggests that it is best to leave the 0.3 branch as is. |
I wouldn't be against that! |
|
As @ivarne says, I think adding new APIs from 0.4 to 0.3.x minor releases should be considered as a good thing on the contrary, as it allows writing code that works on both versions. That's e.g. how GTK works: the last GTK2 version included almost all APIs of 3.0, except for breaking changes. This makes porting much smoother, and means you also benefit from new stuff in the last release. What's needed is just to note in the documentation when the function was introduced. |
Agreed with @ivarne and @nalimilan, API additions in 0.3.x should not be completely off the table but care needs to be taken, and it should only be done for very good bugfix reasons. The ease-of-porting issue can hopefully be addressed mostly by Compat.jl, but we'll see. For example we did sneak in backporting a Julia implementation of |
I am ok with bugfixes, but wary about introducing new APIs. If I have julia on two computers, one that is on 0.3.1 in a lab, and my laptop, say at 0.3.3, it would not be nice if code written in 0.3.3 did not work on 0.3.1. In many of the new RNG APIs, order of arguments is changed, AbstractRNG is allowed as an argument now in almost all cases, and so on. Performance updates, bugfixes and internal APIs are all ok to update. I am just wary about changing the behaviour of published APIs. @rfourquet The recent segfault that you fixed, does it happen on 0.3 also? Since we did not have the array fill generators in 0.3, it is perhaps safe from the segfault? |
No the segfault was caused exclusively by the transition to fill_array functions, so 0.3 is safe from it (as long as |
I just verified that, and 0.3 is indeed safe. |
Such a small change makes
randn
(all versions) faster by about 40-50 % (or more) on my machine. One week ago, I wanted to ask on the user list what was the point ofifelse
, now I know!