Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions src/matrix_multiply_add.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,45 @@ const StaticVecOrMatLikeForFiveArgMulDest{T} = Union{
α::Number, β::Number) = _mul!(TSize(dest), mul_parent(dest), Size(A), Size(B), A, B,
AlphaBeta(α,β))

@inline function LinearAlgebra.mul!(dest::StaticVecOrMatLike{TDest}, A::StaticVecOrMatLike{TA},
B::StaticVecOrMatLike{TB}) where {TDest,TA,TB}
TMul = promote_op(matprod, TA, TB)
return _mul!(TSize(dest), mul_parent(dest), Size(A), Size(B), A, B, NoMulAdd{TMul, TDest}())
if VERSION < v"1.1"
# See https://github.com/JuliaArrays/StaticArrays.jl/issues/857.
# `StaticVecOrMatLike` is a very large union, and this caused Julia 1.0.x to
# use a large amount of memory when compiling StaticArrays in the presence
# of other packages that also extend `LinearAlgebra.mul!` in a similar
# fashion. As an example, this led to JuMP using more than 4 GB of RAM when
# running `using JuMP`, causing its CI to crash.
#
# Computing the eltypes within the function, rather than specifying them in
# the type arguments greatly improves the issue, with `using JuMP` going
# from:
# julia> @time using JuMP
# [ Info: Precompiling JuMP [4076af6c-e467-56ae-b986-b466b2749572]
# Killed
# to:
# julia> @time using JuMP
# [ Info: Precompiling JuMP [4076af6c-e467-56ae-b986-b466b2749572]
# 97.868305 seconds (12.75 M allocations: 805.413 MiB, 0.30% gc time)
@inline _eltype(::StaticVecOrMatLike{T}) where {T} = T
@inline function LinearAlgebra.mul!(
dest::StaticVecOrMatLike,
A::StaticVecOrMatLike,
B::StaticVecOrMatLike,
)
TDest, TA, TB = _eltype(dest), _eltype(A), _eltype(B)
TMul = promote_op(matprod, TA, TB)
return _mul!(TSize(dest), mul_parent(dest), Size(A), Size(B), A, B, NoMulAdd{TMul, TDest}())
end
else
@inline function LinearAlgebra.mul!(
dest::StaticVecOrMatLike{TDest},
A::StaticVecOrMatLike{TA},
B::StaticVecOrMatLike{TB},
) where {TDest,TA,TB}
TMul = promote_op(matprod, TA, TB)
return _mul!(TSize(dest), mul_parent(dest), Size(A), Size(B), A, B, NoMulAdd{TMul, TDest}())
end
end


"Calculate the product of the dimensions being multiplied. Useful as a heuristic for unrolling."
@inline multiplied_dimension(A::Type{<:StaticVecOrMatLike}, B::Type{<:StaticVecOrMatLike}) =
prod(size(A)) * size(B,2)
Expand Down Expand Up @@ -310,7 +342,7 @@ function uplo_access(sa, asym, k, j, uplo)
elseif uplo == :unit_lower_triangular
if k > j
return :($asym[$(LinearIndices(sa)[k, j])])
elseif k == j
elseif k == j
return :(oneunit($TAsym))
else
return :(zero($TAsym))
Expand Down Expand Up @@ -439,7 +471,7 @@ end
else
ab = [:(a[$i] * transpose(b[$j])) for i = 1:sa[1], j = 1:sb[2]]
end

exprs = _muladd_expr(lhs, ab, _add)

return quote
Expand Down Expand Up @@ -558,7 +590,7 @@ end
@inbounds $(Expr(:block, exprs...))
end
end

return quote
@_inline_meta
α = alpha(_add)
Expand Down