Skip to content

Adding MKL_jll artifact #39

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

Merged
merged 10 commits into from
Mar 7, 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
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: julia 1.0/1.3
name: julia 1.3
on:
push:
branches:
Expand All @@ -13,7 +13,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.3'
os:
- ubuntu-latest
Expand Down
11 changes: 4 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name = "IntelVectorMath"
uuid = "c8ce9da6-5d36-5c03-b118-5a70151be7bc"
version = "0.3.1"
version = "0.4.0"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MKL_jll = "856f044c-d86e-5d09-b602-aeab76dc8ba7"

[compat]
BinaryProvider = "0.5.8"
CpuId = "0.2"
julia = "0.7, 1.0"
julia = "1.3"
MKL_jll = "2020"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[pkgeval-url]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html

[![PkgEval][pkgeval-img]][pkgeval-url]
![](https://github.com/JuliaMath/VML.jl/workflows/julia%201.0/1.3/badge.svg)
![](https://github.com/JuliaMath/VML.jl/workflows/julia%201.3/badge.svg)
![](https://github.com/JuliaMath/VML.jl/workflows/julia%20nightly/badge.svg)

This package provides bindings to the Intel MKL [Vector Mathematics Functions](https://software.intel.com/en-us/node/521751).
Expand All @@ -13,14 +13,18 @@ Until Julia 0.6 the package was registered as `VML.jl`.

Similar packages are [Yeppp.jl](https://github.com/JuliaMath/Yeppp.jl), which wraps the open source Yeppp library, and [AppleAccelerate.jl](https://github.com/JuliaMath/AppleAccelerate.jl), which provides access to macOS's Accelerate framework.

### Warning for macOS
There is currently [the following](https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/700) issue between the `CompilerSupportLibraries_jll` artifact, which is used for example by `SpecialFunctions.jl`, and `MKL_jll`. Unless `MKL_jll` is loaded first, there might be wrong results coming from a small number of function for particular input array lengths. If you are unsure which, if any, your used packages might load this artifact, loading `IntelVectorMath` as the very first package should be fine.

## Basic install

To install IntelVectorMath.jl run
```julia
julia> ] add IntelVectorMath
```
Since version 0.3 IntelVectorMath downloads its own version of MKL and keeps only the required files in its own directory. As such installing MKL.jl or MKL via intel are no longer required, and may mean some duplicate files if they are present. However, this package will adopt the new artifact system in the next minor version update and fix this issue.
Since version 0.4 `IntelVectorMath` uses the `MKL_jll` artifact, which is shared with other packages uses MKL, removing several other dependencies. This has the side effect that from version 0.4 onwards this package requires at least Julia 1.3.

For older versions of Julia `IntelVectorMath v0.3` downloads its own version of MKL and keeps only the required files in its own directory. As such installing MKL.jl or MKL via intel are no longer required, and may mean some duplicate files if they are present. However, this package will adopt the new artifact system in the next minor version update and fix this issue.
In the event that MKL was not installed properly you will get an error when first `using` it. Please try running
```julia
julia> ] build IntelVectorMath
Expand Down
4 changes: 0 additions & 4 deletions deps/.gitignore

This file was deleted.

62 changes: 0 additions & 62 deletions deps/build.jl

This file was deleted.

10 changes: 7 additions & 3 deletions src/IntelVectorMath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ export IVM
const IVM = IntelVectorMath

# import Base: .^, ./
# using Libdl
include("../deps/deps.jl")

include("setup.jl")

function __init__()
compilersupportlibaries_jll_uuid = Base.UUID("e66e0078-7015-5450-92f7-15fbd957f2ae")
if Sys.isapple() && haskey(Base.loaded_modules, Base.PkgId(compilersupportlibaries_jll_uuid, "CompilerSupportLibraries_jll"))
@warn "It appears CompilerSupportLibraries_jll was loaded prior to this package, which currently on mac may lead to wrong results in some cases. For further details see github.com/JuliaMath/IntelVectorMath.jl"
end
end

for t in (Float32, Float64, ComplexF32, ComplexF64)
# Unary, real or complex
def_unary_op(t, t, :acos, :acos!, :Acos)
Expand Down
48 changes: 19 additions & 29 deletions src/setup.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@

function __init__()
check_deps()

Libdl.dlopen(libmkl_core, Libdl.RTLD_GLOBAL)
Libdl.dlopen(libmkl_rt, Libdl.RTLD_GLOBAL) # maybe only needed on mac
Libdl.dlopen(libmkl_vml_avx, Libdl.RTLD_GLOBAL)

end

__init__()
import MKL_jll

struct VMLAccuracy
mode::UInt
Expand All @@ -20,15 +10,15 @@ const VML_EP = VMLAccuracy(0x00000003)

Base.show(io::IO, m::VMLAccuracy) = print(io, m == VML_LA ? "VML_LA" :
m == VML_HA ? "VML_HA" : "VML_EP")
vml_get_mode() = ccall((:_vmlGetMode, libmkl_vml_avx), Cuint, ())
vml_set_mode(mode::Integer) = (ccall((:_vmlSetMode, libmkl_vml_avx), Cuint, (UInt,), mode); nothing)

vml_get_mode() = ccall((:vmlGetMode, MKL_jll.libmkl_rt), Cuint, ())
vml_set_mode(mode::Integer) = (ccall((:vmlSetMode, MKL_jll.libmkl_rt), Cuint, (UInt,), mode); nothing)

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

vml_set_mode((vml_get_mode() & ~0x0000FF00))
function vml_check_error()
vml_error = ccall((:_vmlClearErrStatus, libmkl_vml_avx), Cint, ())
vml_error = ccall((:vmlClearErrStatus, MKL_jll.libmkl_rt), Cint, ())
if vml_error != 0
if vml_error == 1
throw(DomainError(-1, "This function does not support arguments outside its domain"))
Expand All @@ -45,13 +35,13 @@ end

function vml_prefix(t::DataType)
if t == Float32
return "_vmls"
return "vs"
elseif t == Float64
return "_vmld"
return "vd"
elseif t == Complex{Float32}
return "_vmlc"
return "vc"
elseif t == Complex{Float64}
return "_vmlz"
return "vz"
end
error("unknown type $t")
end
Expand All @@ -63,24 +53,24 @@ function def_unary_op(tin, tout, jlname, jlname!, mklname;
(@isdefined jlname) || push!(exports, jlname)
(@isdefined jlname!) || push!(exports, jlname!)
@eval begin
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}) where {N}
function ($jlname!)(out::Array{$tout}, A::Array{$tin})
size(out) == size(A) || throw(DimensionMismatch())
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
ccall(($mklfn, MKL_jll.libmkl_rt), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
vml_check_error()
return out
end
$(if tin == tout
quote
function $(jlname!)(A::Array{$tin})
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, A)
ccall(($mklfn, MKL_jll.libmkl_rt), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, A)
vml_check_error()
return A
end
end
end)
function ($jlname)(A::Array{$tin})
out = similar(A, $tout)
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
ccall(($mklfn, MKL_jll.libmkl_rt), Nothing, (Int, Ptr{$tin}, Ptr{$tout}), length(A), A, out)
vml_check_error()
return out
end
Expand All @@ -95,16 +85,16 @@ function def_binary_op(tin, tout, jlname, jlname!, mklname, broadcast)
(@isdefined jlname!) || push!(exports, jlname!)
@eval begin
$(isempty(exports) ? nothing : Expr(:export, exports...))
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}, B::Array{$tin,N}) where {N}
size(out) == size(A) == size(B) || $(broadcast ? :(return broadcast!($jlname, out, A, B)) : :(throw(DimensionMismatch())))
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
function ($jlname!)(out::Array{$tout}, A::Array{$tin}, B::Array{$tin})
size(out) == size(A) == size(B) || throw(DimensionMismatch("Input arrays and output array need to have the same size"))
ccall(($mklfn, MKL_jll.libmkl_rt), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
vml_check_error()
return out
end
function ($jlname)(A::Array{$tout,N}, B::Array{$tin,N}) where {N}
size(A) == size(B) || $(broadcast ? :(return broadcast($jlname, A, B)) : :(throw(DimensionMismatch())))
function ($jlname)(A::Array{$tout}, B::Array{$tin})
size(A) == size(B) || throw(DimensionMismatch("Input arrays need to have the same size"))
out = similar(A)
ccall(($mklfn, libmkl_vml_avx), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
ccall(($mklfn, MKL_jll.libmkl_rt), Nothing, (Int, Ptr{$tin}, Ptr{$tin}, Ptr{$tout}), length(A), A, B, out)
vml_check_error()
return out
end
Expand Down
24 changes: 21 additions & 3 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[CompilerSupportLibraries_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "b57c5d019367c90f234a7bc7e24ff0a84971da5d"
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.2.0+1"

[[CpuId]]
deps = ["Markdown", "Test"]
git-tree-sha1 = "f0464e499ab9973b43c20f8216d088b61fda80c6"
Expand All @@ -17,6 +23,12 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[IntelOpenMP_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "fb8e1c7a5594ba56f9011310790e03b5384998d6"
uuid = "1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0"
version = "2018.0.3+0"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand All @@ -30,15 +42,21 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[MKL_jll]]
deps = ["IntelOpenMP_jll", "Libdl", "Pkg"]
git-tree-sha1 = "7f7034f27491a8bb955a9e4097e4fb5c2167bda5"
uuid = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
version = "2020.0.166+0"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[OpenSpecFun_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "65f672edebf3f4e613ddf37db9dcbd7a407e5e90"
deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"]
git-tree-sha1 = "d110040968b9afe95c6bd9c6233570b0fe8abd22"
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.3+1"
version = "0.5.3+2"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Test", "UUIDs"]
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[deps]
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MKL_jll = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MKL_jll
using Test
using IntelVectorMath

Expand Down