You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using MKL vectorized functions for things like tanh, exp, log, ... #415
What's the Rust crate that provides bindings to this, and as a first step, what is the general level interface or functionality in ndarray that is needed to implement this? Access to ndarray data that can be used for this, but is still independent of for example the MKL.
And then instead of code mentioned above, one has to do:
unsafe {
let ptr = vector.as_mut_ptr();
vsTanh(vector_len, ptr, ptr);
}
What I was thinking about was to add .exp(), .log(), .tanh(), ... methods for ndarrays, which depending whether we have MKL feature would have faster implementation.
But, if you say, that this is very low priority enhacement and not worth the effort, I would understand.
It sounds good.
I think it is good idea to define tanh and other basic math functions to allow vectorize.
pubtraitVectorizedMath{fntanh(self) -> Self;// or vtanh?fnexp(self) -> Self;
...
}implVectorizedMathforArrayBase<S,D>{/* like @usamec done */}
It is basically independent from MKL. We will be able to implement them using SIMD extensions e.g. vsinf in accelerate (macOS). But this must be depends on the platform where the application works, and we must switch its backend, e.g. intel-mkl-src for Intel CPU and accelerate-src for macOS, and so on.
One way to implement it is a feature flag "intel-mkl-vectorized" to ndarray crate, which enables VectorizedMath trait. We can separate this part as "ndarray-vectorized" sub-crate like ndarray-rand.
Another way is to create a binding of MKL "mkl-sys", which includes functions not included in blas-sys, lapack-sys, and fftw-sys. It should be argued on https://github.com/termoshtt/rust-intel-mkl
Activity
bluss commentedon Feb 6, 2018
What's the Rust crate that provides bindings to this, and as a first step, what is the general level interface or functionality in ndarray that is needed to implement this? Access to ndarray data that can be used for this, but is still independent of for example the MKL.
usamec commentedon Feb 6, 2018
The situation around this is little bit messy.
There is https://crates.io/crates/intel-mkl-src crate, but no direct bindings for MKL.
Right now, go get working solution one has to reexport MKL functions:
And then instead of code mentioned above, one has to do:
What I was thinking about was to add .exp(), .log(), .tanh(), ... methods for ndarrays, which depending whether we have MKL feature would have faster implementation.
But, if you say, that this is very low priority enhacement and not worth the effort, I would understand.
termoshtt commentedon Feb 7, 2018
It sounds good.
I think it is good idea to define
tanhand other basic math functions to allow vectorize.It is basically independent from MKL. We will be able to implement them using SIMD extensions e.g. vsinf in accelerate (macOS). But this must be depends on the platform where the application works, and we must switch its backend, e.g. intel-mkl-src for Intel CPU and accelerate-src for macOS, and so on.
One way to implement it is a feature flag "intel-mkl-vectorized" to ndarray crate, which enables
VectorizedMathtrait. We can separate this part as "ndarray-vectorized" sub-crate like ndarray-rand.Another way is to create a binding of MKL "mkl-sys", which includes functions not included in blas-sys, lapack-sys, and fftw-sys. It should be argued on https://github.com/termoshtt/rust-intel-mkl
burrbull commentedon Mar 15, 2018
Tested:
Works fine.