Created
July 14, 2021 16:35
-
-
Save staticfloat/817fd946216a1af37ea4835402bbcbae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MKLPrefsExample | |
using Preferences, Libdl | |
# Choose an MKL provider; taking an explicit preference as the first choice, | |
# but it nothing is set as a preference, fall back to an environment variable, | |
# and if that is not given, fall back to the default choice of `MKL_jll`. | |
const mkl_provider = something( | |
@load_preference("mkl_provider", nothing), | |
get(ENV, "MKL_PROVIDER", nothing), | |
"mkl_jll", | |
)::String | |
if mkl_provider == "mkl_jll" | |
# Only load MKL_jll if we are suppoed to use it as the MKL source | |
import MKL_jll | |
const libmkl_rt = MKL_jll.libmkl_rt | |
elseif mkl_provider == "system" | |
# If we want to use a "system" MKL just use "libmkl_rt" and expect it to | |
# already be loaded, or be on our linker search path. | |
const libmkl_rt = "libmkl_rt" | |
else | |
error("Invalid mkl_provider choice $(mkl_provider)") | |
end | |
function set_mkl_provider(provider) | |
if provider ∉ ("mkl_jll", "system") | |
error("Invalid provider $(provider)") | |
end | |
@set_preferences!("mkl_provider" => provider) | |
@info("New MKL provider set; please restart Julia to see this take effect", provider) | |
end | |
end # module MKLPrefsExample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment