Skip to content

Commit

Permalink
Merge pull request #35 from fgerick/master
Browse files Browse the repository at this point in the history
Set use_blas64 to false to fix MKL.jl interaction numpy problem
  • Loading branch information
andreasnoack committed Oct 13, 2020
2 parents 73c7d24 + bfb14b6 commit 84ae4d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Build Status](https://travis-ci.org/JuliaComputing/MKL.jl.svg?branch=master)](https://travis-ci.org/JuliaComputing/MKL.jl)

*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 @@ -28,3 +28,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

0 comments on commit 84ae4d4

Please sign in to comment.