-
-
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
Aggressive constprop in matvecmul and matmatmul #51961
Conversation
Indeed, it was. Is there any indication that this helps with compilation times or something? |
The impact seems fairly minimal in the simple tests that I've carried out, although this might make JET happier. |
Unfortunately, this seems to not help elimination of branches. At least for me, this makes things as in #51812 (comment) worse regarding compile time. If anything, then I would have hoped for a decrease in compile time and elimination of branches, since the runtime of the character checks is negligible. |
Perhaps we may apply it selectively, as it seems to improve type inference in certain cases (e.g. complex-real matvecmul)? |
This is unrelated to constant propagation. I'm no longer sure we need these annotations, actually. It seems to suffice to inline some intermediate functions. For instance julia> using LinearAlgebra
julia> A = zeros(10, 10);
julia> @code_typed mul!(copy(A), A', A)
CodeInfo(
1 ─ %1 = Base.getfield(A, :parent)::Matrix{Float64}
│ %2 = (%1 === B)::Bool
└── goto JuliaLang/julia#3 if not %2
2 ─ %4 = invoke LinearAlgebra.syrk_wrapper!(C::Matrix{Float64}, 'T'::Char, %1::Matrix{Float64}, $(QuoteNode(LinearAlgebra.MulAddMul{true, true, Bool, Bool}(true, false)))::LinearAlgebra.MulAddMul{true, true, Bool, Bool})::Matrix{Float64}
└── goto JuliaLang/julia#4
3 ─ %6 = invoke LinearAlgebra.gemm_wrapper!(C::Matrix{Float64}, 'T'::Char, 'N'::Char, %1::Matrix{Float64}, B::Matrix{Float64}, $(QuoteNode(LinearAlgebra.MulAddMul{true, true, Bool, Bool}(true, false)))::LinearAlgebra.MulAddMul{true, true, Bool, Bool})::Matrix{Float64}
└── goto JuliaLang/julia#4
4 ┄ %8 = φ (#2 => %4, JuliaLang/julia#3 => %6)::Matrix{Float64}
└── goto JuliaLang/julia#5
5 ─ return %8
) => Matrix{Float64} That means, the compiler understands that only two branches might be used, but e.g. |
The regression is JuliaLang/LinearAlgebra.jl#1037. There may be cases where we need to rewrap an unwrapped matrix which unfortunately allocates. But for these cases aggressive constant propagation doesn't seem to help. |
2837b33
to
1e29d09
Compare
1e29d09
to
d7a0503
Compare
…Lang/julia into jishnub/constpropmatmatmul
Sorry, I clicked the wrong button in my VSCode instance. |
This usually eliminates branches, with occasional improvement in type-stability. I've replaced
@inline
by aggressive constprop ingeneric_matmatmul
, as I felt that this was the objective.