@@ -15,23 +15,26 @@ if lowercase(mkl_path) == "mkl_jll"
15
15
# Only load MKL_jll if we are suppoed to use it as the MKL source
16
16
# to avoid an unnecessary download of the (lazy) artifact.
17
17
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
19
20
elseif lowercase (mkl_path) == " system"
20
21
# We expect the "system" MKL to already be loaded,
21
22
# or be on our linker search path.
22
23
libname = string (" libmkl_rt" , " ." , Libdl. dlext)
23
24
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." )
25
27
else
26
28
# mkl_path should be a valid path to libmkl_rt.
27
29
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 ." )
29
32
end
30
33
31
34
# Changing the MKL provider/path preference
32
35
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 \" ." )
35
38
end
36
39
@set_preferences! (" mkl_path" => path)
37
40
@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)
71
74
return nothing
72
75
end
73
76
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
+
74
96
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`)." )
91
101
end
92
102
end
93
103
0 commit comments