-
Notifications
You must be signed in to change notification settings - Fork 52
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
Memory allocations of 5-argumets mul!
when involving struct
#566
Comments
The memory allocation does not scale with the size of the matrix/vector, and given that it depends on the scalar factors Without inlining (current): julia> @code_typed mul!(y, A, x, α, β)
CodeInfo(
1 ─ %1 = Base.eq_float(alpha, 1.0)::Bool
└── goto #5 if not %1
2 ─ %3 = Base.eq_float(beta, 0.0)::Bool
└── goto #4 if not %3
3 ─ %5 = %new(LinearAlgebra.MulAddMul{true, true, Float64, Float64}, alpha, beta)::LinearAlgebra.MulAddMul{true, true, Float64, Float64}
└── goto #8
4 ─ %7 = %new(LinearAlgebra.MulAddMul{true, false, Float64, Float64}, alpha, beta)::LinearAlgebra.MulAddMul{true, false, Float64, Float64}
└── goto #8
5 ─ %9 = Base.eq_float(beta, 0.0)::Bool
└── goto #7 if not %9
6 ─ %11 = %new(LinearAlgebra.MulAddMul{false, true, Float64, Float64}, alpha, beta)::LinearAlgebra.MulAddMul{false, true, Float64, Float64}
└── goto #8
7 ─ %13 = %new(LinearAlgebra.MulAddMul{false, false, Float64, Float64}, alpha, beta)::LinearAlgebra.MulAddMul{false, false, Float64, Float64}
└── goto #8
8 ┄ %15 = φ (#3 => %5, #4 => %7, #6 => %11, #7 => %13)::LinearAlgebra.MulAddMul{ais1, bis0, Float64, Float64} where {ais1, bis0}
│ %16 = LinearAlgebra.generic_matvecmul!(y, 'N', A, x, %15)::Vector{Float64}
└── goto #9
9 ─ return %16
) => Vector{Float64} With inlining: julia> @code_typed mul!(y, A, x, α, β)
CodeInfo(
1 ─ %1 = Base.eq_float(alpha, 1.0)::Bool
└── goto #5 if not %1
2 ─ %3 = Base.eq_float(beta, 0.0)::Bool
└── goto #4 if not %3
3 ─ goto #8
4 ─ goto #8
5 ─ %7 = Base.eq_float(beta, 0.0)::Bool
└── goto #7 if not %7
6 ─ goto #8
7 ─ goto #8
8 ┄ invoke SparseArrays._spmatmul!(y::Vector{Float64}, A::SparseMatrixCSC{Float64, Int64}, x::Vector{Float64}, alpha::Float64, beta::Float64)::Any
└── goto #9
9 ─ return y
) => Vector{Float64} You see, it doesn't even mess with the So, if you have a minute, please submit a PR. |
So, which functions should I inline? All up to |
For what I posted, the |
Hello,
I show a simple example where I find some memory allocations when performing the 5-arguments
mul!
. In some cases only when the Sparse matrixA
is inside astruct
, in other cases also withoutstruct
.Involving a simple constructor
Possible partial fix
I've noticed that, by defining the functions above with the
@inline
orBase.@constprop :aggressive
macros, themul!($y, $A_op_my, $x, $α, false)
case is fixed, but it is still a mystery to me.The text was updated successfully, but these errors were encountered: