Skip to content

Commit 8da359d

Browse files
committed
Manage own dependency instead of MKL
1 parent 58e8c11 commit 8da359d

File tree

5 files changed

+68
-47
lines changed

5 files changed

+68
-47
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ uuid = "c8ce9da6-5d36-5c03-b118-5a70151be7bc"
33
version = "0.2.1"
44

55
[deps]
6+
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
67
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
78
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
89
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
910

1011
[compat]
11-
julia = "0.7, 1.0"
1212
CpuId = "0.2"
1313
SpecialFunctions = "0.8, 0.9, 0.10"
14+
julia = "0.7, 1.0"
1415

1516
[extras]
1617
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

deps/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
deps.jl
2-
build.log
2+
build.log
3+
4+
usr/

deps/build.jl

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
1-
1+
using BinaryProvider # requires BinaryProvider 0.3.0 or later
22
using CpuId
3-
using Libdl
4-
5-
## this lets us load CpuId only once
63

74
if cpufeature(:AVX2)
8-
libsuffix = :avx2
5+
avxlib = "avx2"
96
println("AVX2 support detected, vml_avx2 selected")
107
else
11-
libsuffix = :avx
8+
avxlib = "avx"
129
println("AVX2 support missing, vml_avx selected")
1310
end
1411

15-
if Sys.iswindows()
16-
rtlib = :mkl_rt
17-
corelib = :mkl_core
18-
lib = Symbol(:mkl_vml_, libsuffix)
19-
else
20-
rtlib = :libmkl_rt
21-
corelib = :libmkl_core
22-
lib = Symbol(:libmkl_vml_, libsuffix)
23-
end
12+
# Parse some basic command-line arguments
13+
const verbose = "--verbose" in ARGS
14+
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
15+
16+
baseproducts = [("mkl_core", :libmkl_core),
17+
("mkl_rt", :libmkl_rt),
18+
("mkl_vml_" * avxlib, :libmkl_vml_avx)]
19+
# if Sys.iswindows()
20+
# push!(baseproducts, ("mkl_intel_thread", :libmkl_intel_thread))
21+
# end
22+
23+
products = [LibraryProduct(prefix, ["lib"*bp[1], bp[1]], bp[2]) for bp in baseproducts]
2424

25+
# Download binaries from hosted location
26+
bin_prefix = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/MKL-v2019.0.117"
2527

26-
depsjl_path = joinpath(@__DIR__, "deps.jl")
27-
open(depsjl_path, "w") do depsjl_file
28-
println(depsjl_file, strip("""
29-
## This file was autogenerated by build.jl.
30-
## Do not edit.
31-
import Libdl
28+
# Listing of files generated by BinaryBuilder:
29+
download_info = Dict(
30+
Linux(:x86_64) => ("$bin_prefix/MKL.v2019.0.117.x86_64-linux-gnu.tar.gz", "9a496908c05eccdb331218f4cf32229b024790b30bf7bc0ca0f5587e030d34e6"),
31+
Linux(:i686) => ("$bin_prefix/MKL.v2019.0.117.i686-linux-gnu.tar.gz", "ccdce675bf48738f28878bc831231498c7c9560a94f756da8c114f664790ffee"),
32+
MacOS(:x86_64) => ("$bin_prefix/MKL.v2019.0.117.x86_64-apple-darwin14.tar.gz", "605da525b16f61837bc35834f3a6ff90609b1d0a5f1606faa25bf45180ced6e9"),
33+
Windows(:x86_64) => ("$bin_prefix/MKL.v2019.0.117.x86_64-w64-mingw32.tar.gz", "0a9aaac254421fde0f26a95856b595deb8cce85d039050d8167293d049fd716d"),
34+
Windows(:i686) => ("$bin_prefix/MKL.v2019.0.117.i686-w64-mingw32.tar.gz", "53cac3a29bbb2acdc383297c256e3b68b3d4712e1b83417226da4971582e80cd"),
35+
)
3236

33-
const lib = :$lib
34-
const rtlib = :$rtlib
35-
const corelib = :$corelib
36-
"""))
37+
# Install unsatisfied or updated dependencies:
38+
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
39+
dl_info = choose_download(download_info, platform_key_abi())
40+
if dl_info === nothing && unsatisfied
41+
# If we don't have a compatible .tar.gz to download, complain.
42+
# Alternatively, you could attempt to install from a separate provider,
43+
# build from source or something even more ambitious here.
44+
error("Your platform (\"$(Sys.MACHINE)\", parsed as \"$(triplet(platform_key_abi()))\") is not supported by this package!")
3745
end
46+
47+
# If we have a download, and we are unsatisfied (or the version we're
48+
# trying to install is not itself installed) then load it up!
49+
if unsatisfied || !isinstalled(dl_info...; prefix=prefix)
50+
# Download and install binaries
51+
install(dl_info...; prefix=prefix, force=true, verbose=verbose)
52+
end
53+
54+
# Write out a deps.jl file that will contain mappings for our products
55+
write_deps_file(joinpath(@__DIR__, "deps.jl"), products, verbose=verbose)
56+
57+
# cleanup for lean install
58+
libfiles = readdir("usr/lib")
59+
idx = .!mapreduce(p -> occursin.(p[1], libfiles), (x,y) -> x.|y, baseproducts)
60+
rm.("usr/lib/" .* libfiles[idx])
61+
62+
rm("usr/downloads/", recursive = true)

src/IntelVectorMath.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const IVM = IntelVectorMath
77

88
# import Base: .^, ./
99
using SpecialFunctions
10-
using Libdl
11-
include(joinpath(dirname(@__DIR__), "deps/deps.jl"))
10+
# using Libdl
11+
include("../deps/deps.jl")
1212

1313
include("setup.jl")
1414

src/setup.jl

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11

22
function __init__()
3-
MKLpkgid = Base.PkgId(Base.UUID("33e6dc65-8f57-5167-99aa-e5a354878fb2"), "MKL")
4-
mklpath = Base.locate_package(MKLpkgid)
5-
if mklpath != nothing
6-
libpath = normpath(joinpath(dirname(mklpath), "../deps/usr/lib"))
7-
push!(Libdl.DL_LOAD_PATH, libpath)
8-
elseif isempty(Libdl.find_library(rtlib))
9-
error("Could not find MKL shared libraries. Please add MKL.jl or install MKL via the intel website. See the github repository for more details.)")
10-
end
3+
check_deps()
114

12-
Libdl.dlopen(rtlib, RTLD_GLOBAL)
13-
Libdl.dlopen(corelib, RTLD_GLOBAL) # maybe only needed on mac
14-
Libdl.dlopen(lib, RTLD_GLOBAL)
5+
Libdl.dlopen(libmkl_core, Libdl.RTLD_GLOBAL)
6+
Libdl.dlopen(libmkl_rt, Libdl.RTLD_GLOBAL) # maybe only needed on mac
7+
Libdl.dlopen(libmkl_vml_avx, Libdl.RTLD_GLOBAL)
158

169
end
1710

@@ -30,15 +23,15 @@ const _BINARY = []
3023

3124
Base.show(io::IO, m::VMLAccuracy) = print(io, m == VML_LA ? "VML_LA" :
3225
m == VML_HA ? "VML_HA" : "VML_EP")
33-
vml_get_mode() = ccall((:_vmlGetMode, lib), Cuint, ())
34-
vml_set_mode(mode::Integer) = (ccall((:_vmlSetMode, lib), Cuint, (UInt,), mode); nothing)
26+
vml_get_mode() = ccall((:_vmlGetMode, libmkl_vml_avx), Cuint, ())
27+
vml_set_mode(mode::Integer) = (ccall((:_vmlSetMode, libmkl_vml_avx), Cuint, (UInt,), mode); nothing)
3528

3629
vml_set_accuracy(m::VMLAccuracy) = vml_set_mode((vml_get_mode() & ~0x03) | m.mode)
3730
vml_get_accuracy() = VMLAccuracy(vml_get_mode() & 0x3)
3831

3932
vml_set_mode((vml_get_mode() & ~0x0000FF00))
4033
function vml_check_error()
41-
vml_error = ccall((:_vmlClearErrStatus, lib), Cint, ())
34+
vml_error = ccall((:_vmlClearErrStatus, libmkl_vml_avx), Cint, ())
4235
if vml_error != 0
4336
if vml_error == 1
4437
throw(DomainError(-1, "This function does not support arguments outside its domain"))
@@ -76,7 +69,7 @@ function def_unary_op(tin, tout, jlname, jlname!, mklname;
7669
@eval begin
7770
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}) where {N}
7871
size(out) == size(A) || throw(DimensionMismatch())
79-
ccall(($mklfn, lib), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
72+
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
8073
vml_check_error()
8174
return out
8275
end
@@ -91,7 +84,7 @@ function def_unary_op(tin, tout, jlname, jlname!, mklname;
9184
end)
9285
function ($jlname)(A::Array{$tin})
9386
out = similar(A, $tout)
94-
ccall(($mklfn, lib), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
87+
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
9588
vml_check_error()
9689
return out
9790
end
@@ -109,14 +102,14 @@ function def_binary_op(tin, tout, jlname, jlname!, mklname, broadcast)
109102
$(isempty(exports) ? nothing : Expr(:export, exports...))
110103
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}, B::Array{$tin,N}) where {N}
111104
size(out) == size(A) == size(B) || $(broadcast ? :(return broadcast!($jlname, out, A, B)) : :(throw(DimensionMismatch())))
112-
ccall(($mklfn, lib), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
105+
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
113106
vml_check_error()
114107
return out
115108
end
116109
function ($jlname)(A::Array{$tout,N}, B::Array{$tin,N}) where {N}
117110
size(A) == size(B) || $(broadcast ? :(return broadcast($jlname, A, B)) : :(throw(DimensionMismatch())))
118111
out = similar(A)
119-
ccall(($mklfn, lib), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
112+
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
120113
vml_check_error()
121114
return out
122115
end

0 commit comments

Comments
 (0)