Skip to content

Fix default adjoint for AppleAccelerate and MKL #603

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

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ specific structure distinct from ``A`` then passing in a `linsolve` will be more
linsolve::L = missing
end

function CRC.rrule(T::typeof(SciMLBase.solve), prob::LinearProblem, alg::Nothing, args...; kwargs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function CRC.rrule(T::typeof(SciMLBase.solve), prob::LinearProblem, alg::Nothing, args...; kwargs...)
function CRC.rrule(
T::typeof(SciMLBase.solve), prob::LinearProblem, alg::Nothing, args...; kwargs...)

@show "here?"
assump = OperatorAssumptions(issquare(prob.A))
alg = defaultalg(prob.A, prob.b, assump)
@show alg
CRC.rrule(T, prob, alg, args...; kwargs...)
end

function CRC.rrule(::typeof(SciMLBase.solve), prob::LinearProblem,
alg::SciMLLinearSolveAlgorithm, args...; alias_A = default_alias_A(
alg, prob.A, prob.b), kwargs...)
Expand Down
14 changes: 11 additions & 3 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,20 @@ end
@generated function defaultalg_adjoint_eval(cache::LinearCache, dy)
ex = :()
for alg in first.(EnumX.symbol_map(DefaultAlgorithmChoice.T))
newex = if alg in Symbol.((DefaultAlgorithmChoice.MKLLUFactorization,
DefaultAlgorithmChoice.AppleAccelerateLUFactorization,
DefaultAlgorithmChoice.RFLUFactorization))
newex = if alg == Symbol(DefaultAlgorithmChoice.RFLUFactorization)
quote
getproperty(cache.cacheval, $(Meta.quot(alg)))[1]' \ dy
end
elseif alg == Symbol(DefaultAlgorithmChoice.MKLLUFactorization)
quote
A = getproperty(cache.cacheval, $(Meta.quot(alg)))[1]
getrs!('T', A.factors, A.ipiv, dy)
end
elseif alg == Symbol(DefaultAlgorithmChoice.AppleAccelerateLUFactorization)
quote
A = getproperty(cache.cacheval, $(Meta.quot(alg)))[1]
aa_getrs!('T', A.factors, A.ipiv, dy)
end
elseif alg in Symbol.((DefaultAlgorithmChoice.LUFactorization,
DefaultAlgorithmChoice.QRFactorization,
DefaultAlgorithmChoice.KLUFactorization,
Expand Down
Loading