Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set use_blas64 to false to fix MKL.jl interaction numpy problem #35

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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*.
4 changes: 4 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 25 additions & 1 deletion src/install.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,36 @@ 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
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.
Expand Down Expand Up @@ -96,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
Expand All @@ -107,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