Skip to content

Commit 94be106

Browse files
committed
Use LP64 BLAS and LAPACK from Accelerate
These should always be available everywhere.
1 parent 9ef7134 commit 94be106

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
1212
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1313
KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
1414
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
15+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1516
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1617
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1718
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

src/appleaccelerate.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using LinearAlgebra
2+
using Libdl
3+
14
# For now, only use BLAS from Accelerate (that is to say, vecLib)
25
global const libacc = "/System/Library/Frameworks/Accelerate.framework/Accelerate"
36

@@ -12,33 +15,33 @@ to avoid allocations and does not require libblastrampoline.
1215
struct AppleAccelerateLUFactorization <: AbstractFactorization end
1316

1417
function appleaccelerate_isavailable()
15-
libacc_hdl = dlopen_e(libacc)
18+
libacc_hdl = Libdl.dlopen_e(libacc)
1619
if libacc_hdl == C_NULL
1720
return false
1821
end
1922

20-
if dlsym_e(libacc_hdl, "dgemm\$NEWLAPACK\$ILP64") == C_NULL
23+
if dlsym_e(libacc_hdl, "dgetrf_") == C_NULL
2124
return false
2225
end
2326
return true
2427
end
2528

26-
function aa_getrf!(A::AbstractMatrix{<:Float64}; ipiv = similar(A, BlasInt, min(size(A,1),size(A,2))), info = Ref{BlasInt}(), check = false)
29+
function aa_getrf!(A::AbstractMatrix{<:Float64}; ipiv = similar(A, Cint, min(size(A,1),size(A,2))), info = Ref{Cint}(), check = false)
2730
require_one_based_indexing(A)
2831
check && chkfinite(A)
2932
chkstride1(A)
3033
m, n = size(A)
3134
lda = max(1,stride(A, 2))
3235
if isempty(ipiv)
33-
ipiv = similar(A, BlasInt, min(size(A,1),size(A,2)))
36+
ipiv = similar(A, Cint, min(size(A,1),size(A,2)))
3437
end
3538

36-
ccall(("dgetrf\$NEWLAPACK\$ILP64", libacc), Cvoid,
37-
(Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64},
38-
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
39+
ccall(("dgetrf_", libacc), Cvoid,
40+
(Ref{Cint}, Ref{Cint}, Ptr{Float64},
41+
Ref{Cint}, Ptr{Cint}, Ptr{Cint}),
3942
m, n, A, lda, ipiv, info)
40-
chkargsok(info[])
41-
A, ipiv, info[] #Error code is stored in LU factorization type
43+
info[] < 0 && throw(ArgumentError("Invalid arguments sent to LAPACK dgetrf_"))
44+
A, Vector{BlasInt}(ipiv), BlasInt(info[]) #Error code is stored in LU factorization type
4245
end
4346

4447
default_alias_A(::AppleAccelerateLUFactorization, ::Any, ::Any) = false
@@ -62,4 +65,4 @@ function SciMLBase.solve!(cache::LinearCache, alg::AppleAccelerateLUFactorizatio
6265
end
6366
y = ldiv!(cache.u, @get_cacheval(cache, :AppleAccelerateLUFactorization), cache.b)
6467
SciMLBase.build_linear_solution(alg, y, nothing, cache)
65-
end
68+
end

0 commit comments

Comments
 (0)