From 5e930afb0083269909acb9ea885b48a9f08ace9f Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 5 Aug 2025 21:13:56 -0400 Subject: [PATCH] Safety measures around AppleAccelerate ```julia Enzyme Derivative Rules: Error During Test at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:30 Got exception outside of a @test LoadError: could not load library "/System/Library/Frameworks/Accelerate.framework/Accelerate" /System/Library/Frameworks/Accelerate.framework/Accelerate.so: cannot open shared object file: No such file or directory Stacktrace: [1] fix_ptr_lookup(name::String) @ Enzyme.Compiler.JIT ~/.julia/packages/Enzyme/LMVya/src/compiler/orcv2.jl:63 [2] add!(mod::LLVM.Module) @ Enzyme.Compiler.JIT ~/.julia/packages/Enzyme/LMVya/src/compiler/orcv2.jl:251 [3] _link(job::GPUCompiler.CompilerJob{<:Enzyme.Compiler.EnzymeTarget}, mod::LLVM.Module, edges::Vector{Any}, adjoint_name::String, primal_name::Union{Nothing, String}, TapeType::Any, prepost::String) @ Enzyme.Compiler ~/.julia/packages/Enzyme/LMVya/src/compiler.jl:5661 [4] cached_compilation @ ~/.julia/packages/Enzyme/LMVya/src/compiler.jl:5750 ``` Basically, you can't do option dependencies, but BinaryBuilder just simply sends no binary if the platform isn't supported. So LinearSolve.jl always has a dependency on AppleAccelerate, and if the binary exists it defaults to it (since it's pretty much always the fastest on M-series mac) and otherwise it disables it. Enzyme still seems to want to try to call it, so this should fix that. --- src/appleaccelerate.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/appleaccelerate.jl b/src/appleaccelerate.jl index a8772f336..64482ef33 100644 --- a/src/appleaccelerate.jl +++ b/src/appleaccelerate.jl @@ -34,6 +34,8 @@ function aa_getrf!(A::AbstractMatrix{<:ComplexF64}; ipiv = similar(A, Cint, min(size(A, 1), size(A, 2))), info = Ref{Cint}(), check = false) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A) check && chkfinite(A) chkstride1(A) @@ -54,6 +56,8 @@ function aa_getrf!(A::AbstractMatrix{<:ComplexF32}; ipiv = similar(A, Cint, min(size(A, 1), size(A, 2))), info = Ref{Cint}(), check = false) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A) check && chkfinite(A) chkstride1(A) @@ -74,6 +78,8 @@ function aa_getrf!(A::AbstractMatrix{<:Float64}; ipiv = similar(A, Cint, min(size(A, 1), size(A, 2))), info = Ref{Cint}(), check = false) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A) check && chkfinite(A) chkstride1(A) @@ -94,6 +100,8 @@ function aa_getrf!(A::AbstractMatrix{<:Float32}; ipiv = similar(A, Cint, min(size(A, 1), size(A, 2))), info = Ref{Cint}(), check = false) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A) check && chkfinite(A) chkstride1(A) @@ -116,6 +124,8 @@ function aa_getrs!(trans::AbstractChar, ipiv::AbstractVector{Cint}, B::AbstractVecOrMat{<:ComplexF64}; info = Ref{Cint}()) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A, ipiv, B) LinearAlgebra.LAPACK.chktrans(trans) chkstride1(A, B, ipiv) @@ -140,6 +150,8 @@ function aa_getrs!(trans::AbstractChar, ipiv::AbstractVector{Cint}, B::AbstractVecOrMat{<:ComplexF32}; info = Ref{Cint}()) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A, ipiv, B) LinearAlgebra.LAPACK.chktrans(trans) chkstride1(A, B, ipiv) @@ -165,6 +177,8 @@ function aa_getrs!(trans::AbstractChar, ipiv::AbstractVector{Cint}, B::AbstractVecOrMat{<:Float64}; info = Ref{Cint}()) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A, ipiv, B) LinearAlgebra.LAPACK.chktrans(trans) chkstride1(A, B, ipiv) @@ -190,6 +204,8 @@ function aa_getrs!(trans::AbstractChar, ipiv::AbstractVector{Cint}, B::AbstractVecOrMat{<:Float32}; info = Ref{Cint}()) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") require_one_based_indexing(A, ipiv, B) LinearAlgebra.LAPACK.chktrans(trans) chkstride1(A, B, ipiv) @@ -236,6 +252,8 @@ end function SciMLBase.solve!(cache::LinearCache, alg::AppleAccelerateLUFactorization; kwargs...) + __appleaccelerate_isavailable() || + error("Error, AppleAccelerate binary is missing but solve is being called. Report this issue") A = cache.A A = convert(AbstractMatrix, A) if cache.isfresh