JuliaMath / IntelVectorMath.jl

Julia bindings for the Intel Vector Math Library
Other
73 stars 18 forks source link

Updated for Julia 1.0, added (limited) auto detection of libraries and avx support #17

Closed Crown421 closed 4 years ago

aminya commented 4 years ago

Is there any update on this, MKL was updated recently https://github.com/JuliaComputing/MKL.jl, but it doesn't use VML functions (like exp, log) by itself.

aminya commented 4 years ago

How can I call the functions? I don't get any speed up. Is the Base API replaced, and so I can call the functions like just normal names (log, exp, etc)?

Crown421 commented 4 years ago

VML extends the base functions to e.g. sin(x::Array{Float64}), as the base functions don't take arrays but instead rely on broadcasting.

julia> using VML
julia> a = rand(10000);
julia>@time  sin.(a);                                                                                                    
 0.159878 seconds (583.25 k allocations: 30.720 MiB, 2.78% gc time)
julia> @time sin(a);                                                                                                      
0.000465 seconds (6 allocations: 781.484 KiB) 

In short, if you call function with an array they go to vml, otherwise they use the base functions.

aminya commented 4 years ago

Oh yes, I was trying the wrong code! I thought it is possible to run something like sin(a) in Julia Base. It would be nice to add this example to the Readme!

mcabbott commented 4 years ago

Great to see progress!

VML extends the base functions to e.g. sin(x::Array{Float64}), as the base functions don't take arrays

I didn't realise it did this, are we sure this the right way to go? Overloading Base functions on Base types. You must write Yeppp.sin and AppleAccelerate.exp etc. Perhaps the 1.0 update is a good moment to do likewise here?

aminya commented 4 years ago

Great to see progress!

VML extends the base functions to e.g. sin(x::Array{Float64}), as the base functions don't take arrays

I didn't realise it did this, are we sure this the right way to go? Overloading Base functions on Base types. You must write Yeppp.sin and AppleAccelerate.exp etc. Perhaps the 1.0 update is a good moment to do likewise here?

I think this is beyond this pull request, and it will just lag using this package. Changing the API requires a completely different work

Crown421 commented 4 years ago

Great to see progress!

VML extends the base functions to e.g. sin(x::Array{Float64}), as the base functions don't take arrays

I didn't realise it did this, are we sure this the right way to go? Overloading Base functions on Base types. You must write Yeppp.sin and AppleAccelerate.exp etc. Perhaps the 1.0 update is a good moment to do likewise here?

It does, when I updated the test suite I ran into some issues verifying that a given call actually belongs to Base or VML, to make sure that I am not comparing a function to itself in terms of accurate output. Ideally I would like the option that using VML extends Base and import VML doesn't, like one would expect, but unfortunately there seem to be some restrictions in the way Julia itself works here. I think that is appropriate for its own issue.

mcabbott commented 4 years ago

I can't seem to make this work, with MKL.jl. On a mac with Julia 1.3rc4 or 1.4, afetr installing MKL.jl, I can add & build VML (Crown421:master), but can't use it. Is this expected to work?

julia> using VML
[ Info: Precompiling VML [c8ce9da6-5d36-5c03-b118-5a70151be7bc]
ERROR: LoadError: LoadError: could not load library "libmkl_rt"
dlopen(libmkl_rt.dylib, 9): image not found
Stacktrace:
 [1] #dlopen#3(::Bool, ::typeof(Libdl.dlopen), ::String, ::UInt32) at /Applications/Julia-1.3.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 [2] #dlopen#2 at /Applications/Julia-1.3.app/Contents/Resources/julia/share/julia/stdlib/v1.3/Libdl/src/Libdl.jl:109 [inlined]
 [3] dlopen at /Applications/Julia-1.3.app/Contents/Resources/julia/share/julia/stdlib/v1.3/Libdl/src/Libdl.jl:105 [inlined]
 [4] __init__() at /Users/me/.julia/dev/VML/src/setup.jl:3

julia> using Libdl

julia> dlopen(:libmkl_rt; throw_error=false) !== nothing
false
Crown421 commented 4 years ago

You are right, I only tested the standalone on Mac, not with MKL.jl. I get the same error on julia 1.1. I might have an idea about the problem, but it is likely something MKL.

Crown421 commented 4 years ago

So, I am not sure how to fix this better (yet), but for now

export DYLD_FALLBACK_LIBRARY_PATH=<path to MKL folder>/deps/usr/lib

will fix the issue.

mcabbott commented 4 years ago

Great, thank you. With that I can load VML, and have updated my tests in #19 .

julia> Base.pathof(MKL) # since I always forget
export DYLD_FALLBACK_LIBRARY_PATH=/Users/me/.julia/packages/MKL/goLVK/deps/usr/lib
aminya commented 4 years ago

I hope this is not abandoned again.

Crown421 commented 4 years ago

Added an ok fix to add the path of the shared libraries from MKL.jl to the search path. @mcabbott Do you want to add your changes to my repository, so that there is at least one usable/ complete repo?

aminya commented 4 years ago

@mcabbott Do you want to add your changes to my repository so that there is at least one usable/ complete repo?

I agree. Now that this may take a little more time to get merged, it is reasonable to merge that one too.

mcabbott commented 4 years ago

Sure, see if I did that right!

BTW the with the latest commit here I still seem to need to provide the path by hand. Error when trying without that, on Julia 1.2 with MKL.jl:

julia> using VML
[ Info: Precompiling VML [c8ce9da6-5d36-5c03-b118-5a70151be7bc]
ERROR: LoadError: LoadError: could not load library "libmkl_rt"
dlopen(libmkl_rt.dylib, 9): image not found
Stacktrace:
 [1] #dlopen#3(::Bool, ::typeof(Libdl.dlopen), ::String, ::UInt32) at /Applications/Julia-1.2.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 [2] #dlopen#2 at /Applications/Julia-1.2.app/Contents/Resources/julia/share/julia/stdlib/v1.2/Libdl/src/Libdl.jl:109 [inlined]
 [3] dlopen at /Applications/Julia-1.2.app/Contents/Resources/julia/share/julia/stdlib/v1.2/Libdl/src/Libdl.jl:105 [inlined]
 [4] __init__() at /Users/me/.julia/dev/VML/src/setup.jl:3
Crown421 commented 4 years ago

Yes, I am working on that. After working once it now doesn't work anymore. I think I came up with a better solution, assuming I can get it to work.

Crown421 commented 4 years ago

@mcabbott Try using it now, I think I made it work now reasonably well. Readme comes next.

aminya commented 4 years ago

Thank you guys for the work.

I will test the functionality.

Crown421 commented 4 years ago

@KristofferC Would it be possible to merge this PR now? While still not perfect, I think this package is now ready for use.

aminya commented 4 years ago

I am going to create a PR to this branch and update the benchmarks code. https://github.com/aminya/VML.jl/tree/workingJulia1

aminya commented 4 years ago

The pull request is ready for merging! https://github.com/Crown421/VML.jl/pull/2

aminya commented 4 years ago

@Crown421 I am working on making AcuteBenchmark by using the approach we took for benchmarking the functions that get arrays. I will add some features such as trying different sizes, etc. So, for now, don't spend time on changing things in the benchmark code. Once that package is finished we can do a more extensive benchmark for VML.

Crown421 commented 4 years ago

I am not entirely sure what you mean with "approach for benchmarking the arrays" ?

aminya commented 4 years ago

That package is going to generate random arrays (as inputs) and benchmark the functions based on that. Similar to what we did in this package, but written in a general and reusable manner and with more features. I will post the source code once it is finished.

Crown421 commented 4 years ago

Feel free to check out the benchmarks branch on my repo, which contains my first attempt at a rewrite (bm.jl and bm_functions.jl) from last week. It also has some stuff for a more thorough job (bm_extended.jl) from Sunday, which includes testing whether the speed-up is statistically significant, but currently suffers from unexplained high RAM usage.

aminya commented 4 years ago

Thank you. That is useful. I also have some code from Julia-Matlab-Benchmark, which overall will make a useful package (AcuteBenchmark).

aminya commented 4 years ago

@simonster @andreasnoack @ViralBShah Could you merge this PR?

ViralBShah commented 4 years ago

@Crown421 @aminya I have invited you to have write access to the repo. Hope that helps with the management of this repo and keeping it updated. Thank you for the contributions!

aminya commented 4 years ago

Thank you! You're welcome.