From MKL back to OpenBLAS

After building MKL on Julia.

julia>]add https://github.com/JuliaComputing/MKL.jl

julia>] build MKL

Is there a way to set OpenBLAS back?

1 Like

Probably not the best way but reinstalling Julia works. At least on Mac I can just run the install and replace the current install and REPL history etc will still be left.

At the end that is just what I did. I wanted to know if there was an easy and fast way to switch between both in order to perform some benchmarks.

1 Like

This should work: MKL.jl/install.jl at 61720ba15055424dde7dabfef8e3880eebbd4566 · JuliaLinearAlgebra/MKL.jl · GitHub

2 Likes

It took a few minutes (to be exact since you replied) for the re-build, but I had not expected for it to be faster. Thanks, that’s exactly what I was looking for.

I tried to run the install script in Julia and executed

julia> enable_openblas_startup()
[ Info: Removing code to load MKL in C:\Users\Win10\AppData\Local\Programs\Julia-1.6.3\bin\..\share\julia\base\sysimg.jl
[ Info: getting precompile script from: https://raw.githubusercontent.com/JuliaLang/julia/release-1.6/contrib/generate_precompile.jl
┌ Warning: Base.download is deprecated; use Downloads.download instead
│   caller = get_precompile_statments_file() at switchblas.jl:75
â”” @ Main C:\Users\Win10\source\repos\julia\idioms\test\switchblas.jl:75
ERROR: UndefKeywordError: keyword argument sysimage_path not assigned

Is this borken or am I doing it wrong? Nevermind I’m doing it wrong. Used a newer, unsupported version of the package compiler, it seems.

For Julia 1.7 you don’t have to do anything else than just restarting Julia. We even want to add a way to dynamically switch back to OpenBLAS (or back and forth) at some point. However, no one has implemented that yet despite the fact that it should be fairly simple. See https://github.com/JuliaLinearAlgebra/MKL.jl/issues/90

2 Likes

Just use 1.7 for MKL. It’s just not worth dealing with 1.6 when it comes to this.

5 Likes

The following seems to work, for switching at run-time in Julia 1.7.
No need to restart.

julia> using LinearAlgebra

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
â”” [ILP64] libopenblas64_.so

julia> using MKL

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
â”” [ILP64] libmkl_rt.so

julia> LinearAlgebra.__init__()

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
â”” [ILP64] libopenblas64_.so

julia> MKL.__init__()
4770

julia> BLAS.get_config()
LinearAlgebra.BLAS.LBTConfig
Libraries: 
â”” [ILP64] libmkl_rt.so

Credits to @giordano (though he also warned this might not be proper way to switch).

3 Likes

What is the “correct” way to switch back to OpenBLAS as of Julia 1.10?

1 Like

Start a new Julia session, and don’t using MKL this time.

Starting in Julia 1.7, switching to MKL doesn’t require anything permanent. Just a using MLK (which I have in my startup.jl). So to not use it, don’t using MKL.

3 Likes

Thanks for the quick response! Is there an intended way to switch back from MKL (by using MKL) to OpenBLAS without restarting the Julia session?

julia> using OpenBLAS_jll, LinearAlgebra.BLAS

julia> BLAS.lbt_forward(OpenBLAS_jll.libopenblas_path; clear=true)
4860
5 Likes

Perfect, thanks!

How do you apply the same trick for MKL?
Since after

BLAS.lbt_forward(OpenBLAS_jll.libopenblas_path; clear=true)
using MKL;

Won’t have effect. Is there a way to set MKL as you did with OpenBLAS?

It won’t have any effect because you had already loaded MKL.jl in the same session, and the __init__ function is skipped, so the solution is to look at what the init function (which is almost the entirety of the package) would do:

(which is pretty much what was suggested in From MKL back to OpenBLAS - #9 by e3c6)

1 Like