Skip to content

Commit

Permalink
resurrect
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Jul 4, 2023
1 parent d87629a commit 0c40844
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ MKL_jll = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[compat]
MKL_jll = "2022.1"
MKL_jll = "2023.1"
julia = "1.8"
Preferences = "1.4"

[extras]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

MKL.jl is a Julia package that allows users to use the Intel MKL library for Julia's underlying BLAS and LAPACK, instead of OpenBLAS, which Julia ships with by default. Julia includes [libblastrampoline](https://github.com/staticfloat/libblastrampoline), which enables picking a BLAS and LAPACK library at runtime. A [JuliaCon 2021 talk](https://www.youtube.com/watch?v=t6hptekOR7s) provides details on this mechanism.

This package requires Julia 1.7+
This package requires Julia 1.7+.

## Usage

If you want to use `MKL.jl` in your project, make sure it is the first package you load before any other package. It is essential that MKL be loaded before other packages so that it can find the Intel OMP library and avoid [issues resulting out of GNU OMP being loaded first](https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/700).
## Installation

## Installation (Julia 1.7 and newer):
To install the package execute

Adding the package will replace the system BLAS and LAPACK with MKL provided ones at runtime. Note that the MKL package has to be loaded in every new Julia process. Upon quitting and restarting, Julia will start with the default OpenBLAS.
```julia
julia> using Pkg; Pkg.add("MKL")
```

## To Check Installation:
## Usage

Loading the package (`using MKL`) will replace the system BLAS and LAPACK with MKL provided ones at runtime. Make sure it is the first package you load before any other package. It is essential that MKL be loaded before other packages so that it can find the Intel OMP library and avoid [issues resulting out of GNU OMP being loaded first](https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/700).

Note that the MKL package has to be loaded in every new Julia process. Upon quitting and restarting, Julia will start with the default OpenBLAS.

## Check

```julia
julia> using LinearAlgebra
Expand All @@ -41,12 +44,10 @@ Note that you can put `using MKL` into your `startup.jl` to make Julia automatic

We use ILP64 by default on 64-bit systems, and LP64 on 32-bit systems.

## Using a preinstalled Intel MKL
## Using a system-provided Intel MKL

If you already have an Intel MKL installation available (as on most HPC clusters), you can use the the environment variable `JULIA_MKL_PATH` or the [preference](https://github.com/JuliaPackaging/Preferences.jl) `mkl_path` to hint MKL.jl to the `libmkl_rt` library. Specifically, the options are:
If you want to use a system-provided Intel MKL installation, you can set the [preference](https://github.com/JuliaPackaging/Preferences.jl) `mkl_path` to hint MKL.jl to the corresponding `libmkl_rt` library. Specifically, the options are:

* `mkl_jll` (default): Download and install MKL via [MKL_jll.jl](https://github.com/JuliaBinaryWrappers/MKL_jll.jl).
* `system`: The package will try to automatically locate the libmkl_rt library (i.e. find it on the linker search path).
* `system`: The package will try to automatically locate the system-provided libmkl_rt library (i.e. find it on the linker search path).
* `path/to/my/libmkl_rt.<EXT>`: Explicit path to the `libmkl_rt.<EXT>` where `<EXT>` is the shared library extension of the system at hand (e.g. `.so`, `.dll`, `.dylib`)

Note that, in contrast to the preference, the environment variable only has an effect when MKL.jl is (re-)precompiled. To force a change of the MKL path after the compilation has happened, use the function `MKL.set_mkl_path`, which takes the options listed above as input. The usecase for the environment variable convenience is for automated installs such as CI systems, where the initial default choice should be set with no human interaction whatsoever.
10 changes: 3 additions & 7 deletions src/MKL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ using Preferences
using Libdl
using LinearAlgebra

# Choose an MKL provider/path; taking an explicit preference as the first choice,
# but if 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`.
# Note: The environment variable is only read at (.ji) compile time and
# not(!) every time before loading the package.
# Choose an MKL path; taking an explicit preference as the first choice,
# but if nothing is set as a preference, fall back to the default choice of `MKL_jll`.
const mkl_path = lowercase(something(
@load_preference("mkl_path", nothing),
get(ENV, "JULIA_MKL_PATH", nothing),
"mkl_jll",
)::String)

Expand All @@ -38,7 +34,7 @@ function set_mkl_path(path)
isfile(path) || error("The provided argument $path doesn't seem to be a valid path to libmkl_rt.")
end
@set_preferences!("mkl_path" => path)
@info("New MKL provider/path set; please restart Julia to see this take effect", path)
@info("New MKL preference set; please restart Julia to see this take effect", path)
end

using LinearAlgebra
Expand Down

0 comments on commit 0c40844

Please sign in to comment.