From c61ada21b83caa1ecb9bf50d199a90fdb16fe701 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Fri, 6 Mar 2020 11:34:01 +0100 Subject: [PATCH 1/2] use_blas64 false to fix mkl.jl interaction numpy problem --- src/install.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/install.jl b/src/install.jl index ea5291a..013963b 100644 --- a/src/install.jl +++ b/src/install.jl @@ -4,11 +4,15 @@ function replace_libblas(base_dir, name) libblas_idx = findfirst(match.(r"const libblas_name", lines) .!= nothing) liblapack_idx = findfirst(match.(r"const liblapack_name", lines) .!= nothing) + useblas64_idx = findfirst(match.(r"USE_BLAS64", lines) .!= nothing) @assert libblas_idx !== nothing && liblapack_idx !== nothing lines[libblas_idx] = "const libblas_name = $(repr(name))" lines[liblapack_idx] = "const liblapack_name = $(repr(name))" + if useblas64_idx != nothing + lines[useblas64_idx] = "const USE_BLAS64 = false" + end write(file, string(join(lines, '\n'), '\n')) end From bfb14b64eb8800de2e3cf00743a6e44187bf9c82 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Sat, 13 Jun 2020 19:41:18 +0200 Subject: [PATCH 2/2] make 32bit MKL optional --- README.md | 7 ++++++- deps/build.jl | 4 ++++ src/install.jl | 24 ++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e35da8a..b922082 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/JuliaComputing/MKL.jl.svg?branch=master)](https://travis-ci.org/JuliaComputing/MKL.jl) [![Build status](https://ci.appveyor.com/api/projects/status/n37h9eagmnx1gly0/branch/master?svg=true)](https://ci.appveyor.com/project/andreasnoack/mkl-jl/branch/master) -*MKL.jl* is a package that makes Julia's linear algebra use Intel MKL BLAS and LAPACK instead of OpenBLAS. The build step of the package will automatically download Intel MKL and rebuild Julia's system image against Intel MKL. +*MKL.jl* is a package that makes Julia's linear algebra use Intel MKL BLAS and LAPACK instead of OpenBLAS. The build step of the package will automatically download Intel MKL and rebuild Julia's system image against Intel MKL. ## To Install: @@ -29,3 +29,8 @@ julia> BLAS.vendor() :mkl ``` and all Julia's dense linear algebra routines ranging from matrix multiply, over solving linear systems of equations, to eigenvalue computations will be computed by Intel MKL. In many cases, this will greatly improve the execution time. + + +## Using the 64-bit vs 32-bit version of MKL + +By default, when building *MKL.jl* the 32-bit version of MKL is installed. This is due to frequently encountered compatibility issues with the MKL version linked to *numpy*, that by default is shipped with the 32-bit version of MKL. To use the 64-bit version of MKL set the environment variable `ENV["USE_BLAS64"] = true` before building *MKL.jl*. diff --git a/deps/build.jl b/deps/build.jl index 1cf17d2..2f99f43 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,5 +1,9 @@ using PackageCompiler using MKL_jll +# if no environment variable ENV["USE_BLAS64"] is set install.jl +# tries to change USE_BLAS64 = false +const USEBLAS64 = parse(Bool,get(ENV, "USE_BLAS64","false")) + include("../src/install.jl") enable_mkl_startup() diff --git a/src/install.jl b/src/install.jl index 013963b..04b2d16 100644 --- a/src/install.jl +++ b/src/install.jl @@ -5,18 +5,35 @@ function replace_libblas(base_dir, name) libblas_idx = findfirst(match.(r"const libblas_name", lines) .!= nothing) liblapack_idx = findfirst(match.(r"const liblapack_name", lines) .!= nothing) useblas64_idx = findfirst(match.(r"USE_BLAS64", lines) .!= nothing) + revertline = lines[useblas64_idx] #save to revert to previously set variable @assert libblas_idx !== nothing && liblapack_idx !== nothing lines[libblas_idx] = "const libblas_name = $(repr(name))" lines[liblapack_idx] = "const liblapack_name = $(repr(name))" if useblas64_idx != nothing - lines[useblas64_idx] = "const USE_BLAS64 = false" + if USEBLAS64 + lines[useblas64_idx] = "const USE_BLAS64 = true" + else + lines[useblas64_idx] = "const USE_BLAS64 = false" + end end write(file, string(join(lines, '\n'), '\n')) + return revertline end +function revert_blas64(base_dir, name,revertline) + file = joinpath(base_dir, "build_h.jl") + lines = readlines(file) + + useblas64_idx = findfirst(match.(r"USE_BLAS64", lines) .!= nothing) + lines[useblas64_idx] = revertline + + write(file, string(join(lines, '\n'), '\n')) +end + + # Used to insert a load of MKL.jl before the stdlibs and run the __init__ explicitly # since these need to have been run when LinearAlgebra loads and determines # what BLAS vendor is used. @@ -100,7 +117,7 @@ function change_blas_library(libblas) end # Replace definitions of `libblas_name`, etc.. to point to MKL or OpenBLAS - replace_libblas(base_dir, libblas) + revertline = replace_libblas(base_dir, libblas) # Next, build a new system image # We don't want to load PackageCompiler in top level scope because @@ -111,4 +128,7 @@ function change_blas_library(libblas) PackageCompiler.create_sysimage(; incremental=false, replace_default=true, script=get_precompile_statments_file()) end + + # revert const USE_BLAS64 to initial state + revert_blas64(base_dir,libblas,revertline) end