-
-
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
Avoid type instability when constructing MulAddMul #47088
Conversation
I personally perfer #47026 if |
@N5N3 to clarify, are you concerned that, for non-const alpha and beta, the binary size of a function that inlines I guess this isn't true in comparison with master, since the previous code did runtime dispatch in this case! - now we are merely branching. I think it should be a strict improvement over master. Unlike #47026, it also improves the non-BLAS paths in case alpha and beta are genuinely not constant by eliminating the possibility of It's true that #47026 avoids, in the non-const BLAS case, unnecessarily branching on the values of alpha and beta in Julia, but I suppose The other issue is that the #47026 approach does not improve the non-BLAS cases over master and actually likely makes them worse in the const case by making const-prop less likely to succeed. Do you see a way to improve this using the |
@Jutho Interested if you have any opinions on this :) |
So, I think this (construct As such, perhaps this PR is the one to prioritize. @N5N3 Should I go ahead and add the macro to the remaining |
@amilsted I tried this solution locally. At present this would increase about a = randn(ComplexF32, 60, 60); b = randn(ComplexF32, 60, 60); c = randn(ComplexF32, 60, 60);
@time mul!(a,b,c,true,false)
@time mul!(a,b,c,1,1)
@time mul!(a,b,c,1.,1.) I can't say the increased compiler time is negligible, but maybe most work load don't call |
@N5N3 Hmm, interesting. I suppose it makes sense that compilation takes longer in the non-const case, as now the compiler can in principle see into the |
Adding In fact, |
Let me see if I understand the issue. In master, runtime dispatch occurs when we call Since we can't tell at compile time whether we will need If we want to restrict runtime dispatch to |
There's no need to pull The combination of this PR with #47026 might be a good idea. @dkarrasch do you think it's OK to make |
@N5N3 Thanks for the explanation. I guess if we push Perhaps if we call |
@N5N3 I just added an inferencebarrier to the Your suggestion is probably better, at least if const-prop continues to work. |
Superseded by #52439. |
Use a macro to move the branching from the
MulAddMul(alpha, beta)
constructor, where it causes type instability (unless one has constant alpha and beta and gets lucky with constant propagation), to the calling function, where it does not cause type instability.This should eliminate runtime dispatch in e.g.
mul!(C, A, B, alpha, beta)
calls wherealpha
andbeta
are not constant (see #46865).This is an (I think nicer) alternative to #47026.
PS: Go easy on me, this is my first macro.