Skip to content

Commit 4b03b91

Browse files
authored
prepare to properly suppory lazy libraries (#789)
The is_available checks should be runtime checks, which will be possible to handle fully properly once MKL_jll and OpenBLAS_jll are upgraded to support that. For now, just convert the variables here so that they aren't trying to do a runtime lookup of a module that was not imported.
1 parent 900e512 commit 4b03b91

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/LinearSolve.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,24 @@ const CRC = ChainRulesCore
5252
# MKL_jll < 2022.2 doesn't support the mixed LP64 and ILP64 interfaces that we make use of in LinearSolve
5353
# In particular, the `_64` APIs do not exist
5454
# https://www.intel.com/content/www/us/en/developer/articles/release-notes/onemkl-release-notes-2022.html
55-
using MKL_jll
55+
using MKL_jll: MKL_jll, libmkl_rt
5656
const usemkl = MKL_jll.is_available() && pkgversion(MKL_jll) >= v"2022.2"
5757
else
58+
global libmkl_rt
5859
const usemkl = false
5960
end
6061
else
62+
global libmkl_rt
6163
const usemkl = false
6264
end
6365

6466
# OpenBLAS_jll is a standard library, but allow users to disable it via preferences
6567
if Preferences.@load_preference("LoadOpenBLAS_JLL", true)
66-
using OpenBLAS_jll: OpenBLAS_jll
68+
using OpenBLAS_jll: OpenBLAS_jll, libopenblas
6769
const useopenblas = OpenBLAS_jll.is_available()
6870
else
6971
const useopenblas = false
72+
global libopenblas
7073
end
7174

7275
@reexport using SciMLBase

src/mkl.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function getrf!(A::AbstractMatrix{<:ComplexF64};
3232
if isempty(ipiv)
3333
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
3434
end
35-
ccall((@blasfunc(zgetrf_), MKL_jll.libmkl_rt), Cvoid,
35+
ccall((@blasfunc(zgetrf_), libmkl_rt), Cvoid,
3636
(Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF64},
3737
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
3838
m, n, A, lda, ipiv, info)
@@ -54,7 +54,7 @@ function getrf!(A::AbstractMatrix{<:ComplexF32};
5454
if isempty(ipiv)
5555
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
5656
end
57-
ccall((@blasfunc(cgetrf_), MKL_jll.libmkl_rt), Cvoid,
57+
ccall((@blasfunc(cgetrf_), libmkl_rt), Cvoid,
5858
(Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF32},
5959
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
6060
m, n, A, lda, ipiv, info)
@@ -76,7 +76,7 @@ function getrf!(A::AbstractMatrix{<:Float64};
7676
if isempty(ipiv)
7777
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
7878
end
79-
ccall((@blasfunc(dgetrf_), MKL_jll.libmkl_rt), Cvoid,
79+
ccall((@blasfunc(dgetrf_), libmkl_rt), Cvoid,
8080
(Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64},
8181
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
8282
m, n, A, lda, ipiv, info)
@@ -98,7 +98,7 @@ function getrf!(A::AbstractMatrix{<:Float32};
9898
if isempty(ipiv)
9999
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
100100
end
101-
ccall((@blasfunc(sgetrf_), MKL_jll.libmkl_rt), Cvoid,
101+
ccall((@blasfunc(sgetrf_), libmkl_rt), Cvoid,
102102
(Ref{BlasInt}, Ref{BlasInt}, Ptr{Float32},
103103
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
104104
m, n, A, lda, ipiv, info)
@@ -124,7 +124,7 @@ function getrs!(trans::AbstractChar,
124124
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
125125
end
126126
nrhs = size(B, 2)
127-
ccall((@blasfunc(zgetrs_), MKL_jll.libmkl_rt), Cvoid,
127+
ccall((@blasfunc(zgetrs_), libmkl_rt), Cvoid,
128128
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF64}, Ref{BlasInt},
129129
Ptr{BlasInt}, Ptr{ComplexF64}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
130130
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -151,7 +151,7 @@ function getrs!(trans::AbstractChar,
151151
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
152152
end
153153
nrhs = size(B, 2)
154-
ccall((@blasfunc(cgetrs_), MKL_jll.libmkl_rt), Cvoid,
154+
ccall((@blasfunc(cgetrs_), libmkl_rt), Cvoid,
155155
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF32}, Ref{BlasInt},
156156
Ptr{BlasInt}, Ptr{ComplexF32}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
157157
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -178,7 +178,7 @@ function getrs!(trans::AbstractChar,
178178
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
179179
end
180180
nrhs = size(B, 2)
181-
ccall((@blasfunc(dgetrs_), MKL_jll.libmkl_rt), Cvoid,
181+
ccall((@blasfunc(dgetrs_), libmkl_rt), Cvoid,
182182
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt},
183183
Ptr{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
184184
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -205,7 +205,7 @@ function getrs!(trans::AbstractChar,
205205
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
206206
end
207207
nrhs = size(B, 2)
208-
ccall((@blasfunc(sgetrs_), MKL_jll.libmkl_rt), Cvoid,
208+
ccall((@blasfunc(sgetrs_), libmkl_rt), Cvoid,
209209
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float32}, Ref{BlasInt},
210210
Ptr{BlasInt}, Ptr{Float32}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
211211
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,

src/openblas.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function openblas_getrf!(A::AbstractMatrix{<:ComplexF64};
5454
if isempty(ipiv)
5555
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
5656
end
57-
ccall((@blasfunc(zgetrf_), OpenBLAS_jll.libopenblas), Cvoid,
57+
ccall((@blasfunc(zgetrf_), libopenblas), Cvoid,
5858
(Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF64},
5959
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
6060
m, n, A, lda, ipiv, info)
@@ -76,7 +76,7 @@ function openblas_getrf!(A::AbstractMatrix{<:ComplexF32};
7676
if isempty(ipiv)
7777
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
7878
end
79-
ccall((@blasfunc(cgetrf_), OpenBLAS_jll.libopenblas), Cvoid,
79+
ccall((@blasfunc(cgetrf_), libopenblas), Cvoid,
8080
(Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF32},
8181
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
8282
m, n, A, lda, ipiv, info)
@@ -98,7 +98,7 @@ function openblas_getrf!(A::AbstractMatrix{<:Float64};
9898
if isempty(ipiv)
9999
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
100100
end
101-
ccall((@blasfunc(dgetrf_), OpenBLAS_jll.libopenblas), Cvoid,
101+
ccall((@blasfunc(dgetrf_), libopenblas), Cvoid,
102102
(Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64},
103103
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
104104
m, n, A, lda, ipiv, info)
@@ -120,7 +120,7 @@ function openblas_getrf!(A::AbstractMatrix{<:Float32};
120120
if isempty(ipiv)
121121
ipiv = similar(A, BlasInt, min(size(A, 1), size(A, 2)))
122122
end
123-
ccall((@blasfunc(sgetrf_), OpenBLAS_jll.libopenblas), Cvoid,
123+
ccall((@blasfunc(sgetrf_), libopenblas), Cvoid,
124124
(Ref{BlasInt}, Ref{BlasInt}, Ptr{Float32},
125125
Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
126126
m, n, A, lda, ipiv, info)
@@ -146,7 +146,7 @@ function openblas_getrs!(trans::AbstractChar,
146146
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
147147
end
148148
nrhs = size(B, 2)
149-
ccall((@blasfunc(zgetrs_), OpenBLAS_jll.libopenblas), Cvoid,
149+
ccall((@blasfunc(zgetrs_), libopenblas), Cvoid,
150150
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF64}, Ref{BlasInt},
151151
Ptr{BlasInt}, Ptr{ComplexF64}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
152152
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -173,7 +173,7 @@ function openblas_getrs!(trans::AbstractChar,
173173
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
174174
end
175175
nrhs = size(B, 2)
176-
ccall((@blasfunc(cgetrs_), OpenBLAS_jll.libopenblas), Cvoid,
176+
ccall((@blasfunc(cgetrs_), libopenblas), Cvoid,
177177
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{ComplexF32}, Ref{BlasInt},
178178
Ptr{BlasInt}, Ptr{ComplexF32}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
179179
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -200,7 +200,7 @@ function openblas_getrs!(trans::AbstractChar,
200200
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
201201
end
202202
nrhs = size(B, 2)
203-
ccall((@blasfunc(dgetrs_), OpenBLAS_jll.libopenblas), Cvoid,
203+
ccall((@blasfunc(dgetrs_), libopenblas), Cvoid,
204204
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt},
205205
Ptr{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
206206
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,
@@ -227,7 +227,7 @@ function openblas_getrs!(trans::AbstractChar,
227227
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
228228
end
229229
nrhs = size(B, 2)
230-
ccall((@blasfunc(sgetrs_), OpenBLAS_jll.libopenblas), Cvoid,
230+
ccall((@blasfunc(sgetrs_), libopenblas), Cvoid,
231231
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float32}, Ref{BlasInt},
232232
Ptr{BlasInt}, Ptr{Float32}, Ref{BlasInt}, Ptr{BlasInt}, Clong),
233233
trans, n, size(B, 2), A, max(1, stride(A, 2)), ipiv, B, max(1, stride(B, 2)), info,

0 commit comments

Comments
 (0)