Skip to content

Commit 8b988a1

Browse files
committed
incorporate comments
1 parent 688b3ac commit 8b988a1

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

src/MKL.jl

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ if lowercase(mkl_path) == "mkl_jll"
1515
# Only load MKL_jll if we are suppoed to use it as the MKL source
1616
# to avoid an unnecessary download of the (lazy) artifact.
1717
import MKL_jll
18-
const libmkl_rt = MKL_jll.libmkl_rt
18+
const mkl_found = MKL_jll.is_available()
19+
const libmkl_rt = mkl_found ? MKL_jll.libmkl_rt : nothing
1920
elseif lowercase(mkl_path) == "system"
2021
# We expect the "system" MKL to already be loaded,
2122
# or be on our linker search path.
2223
libname = string("libmkl_rt", ".", Libdl.dlext)
2324
const libmkl_rt = find_library(libname, [""])
24-
libmkl_rt == "" && error("Couldn't find $libname. Try to specify the path to `libmkl_rt` explicitly.")
25+
const mkl_found = libmkl_rt != ""
26+
mkl_found || @warn("Couldn't find $libname. Try to specify the path to `libmkl_rt` explicitly.")
2527
else
2628
# mkl_path should be a valid path to libmkl_rt.
2729
const libmkl_rt = mkl_path
28-
isfile(libmkl_rt) || error("Couldn't find MKL library at $libmkl_rt.")
30+
const mkl_found = isfile(libmkl_rt)
31+
mkl_found || @warn("Couldn't find MKL library at $libmkl_rt.")
2932
end
3033

3134
# Changing the MKL provider/path preference
3235
function set_mkl_path(path)
33-
if lowercase(path) ("mkl_jll", "system")
34-
isfile(path) || error("The provided argument $path doesn't seem to be a valid path to libmkl_rt.")
36+
if lowercase(path) ("mkl_jll", "system") && !isfile(path)
37+
error("The provided argument $path neither seems to be a valid path to libmkl_rt nor \"mkl_jll\" or \"system\".")
3538
end
3639
@set_preferences!("mkl_path" => path)
3740
@info("New MKL preference set; please restart Julia to see this take effect", path)
@@ -71,23 +74,30 @@ function set_interface_layer(interface::Interface = INTERFACE_LP64)
7174
return nothing
7275
end
7376

77+
function lbt_mkl_forwarding()
78+
if Sys.isapple()
79+
set_threading_layer(THREADING_SEQUENTIAL)
80+
end
81+
# MKL 2022 and onwards have 64_ for ILP64 suffixes. The LP64 interface
82+
# includes LP64 APIs for the non-suffixed symbols and ILP64 API for the
83+
# 64_ suffixed symbols. LBT4 in Julia is necessary for this to work.
84+
set_interface_layer(INTERFACE_LP64)
85+
if Base.USE_BLAS64
86+
# Load ILP64 forwards
87+
BLAS.lbt_forward(libmkl_rt; clear=true, suffix_hint="64")
88+
# Load LP64 forward
89+
BLAS.lbt_forward(libmkl_rt; suffix_hint="")
90+
else
91+
BLAS.lbt_forward(libmkl_rt; clear=true, suffix_hint="")
92+
end
93+
return nothing
94+
end
95+
7496
function __init__()
75-
if !(mkl_path == "mkl_jll" && !MKL_jll.is_available())
76-
if Sys.isapple()
77-
set_threading_layer(THREADING_SEQUENTIAL)
78-
end
79-
# MKL 2022 and onwards have 64_ for ILP64 suffixes. The LP64 interface
80-
# includes LP64 APIs for the non-suffixed symbols and ILP64 API for the
81-
# 64_ suffixed symbols. LBT4 in Julia is necessary for this to work.
82-
set_interface_layer(INTERFACE_LP64)
83-
if Base.USE_BLAS64
84-
# Load ILP64 forwards
85-
BLAS.lbt_forward(libmkl_rt; clear=true, suffix_hint="64")
86-
# Load LP64 forward
87-
BLAS.lbt_forward(libmkl_rt; suffix_hint="")
88-
else
89-
BLAS.lbt_forward(libmkl_rt; clear=true, suffix_hint="")
90-
end
97+
if mkl_found
98+
lbt_mkl_forwarding()
99+
else
100+
@warn("MKL library couldn't be found. Please make sure to set the `mkl_path` preference correctly (e.g. via `MKL.set_mkl_path`).")
91101
end
92102
end
93103

0 commit comments

Comments
 (0)