JuliaMath/IntelVectorMath.jl

Extending VML to MKL

Closed this issue · 1 comments

Hello,

I've been working on a wrapper of Intel MKL, as far as :

  • it's still difficult to build Julia with MKL
  • MKL offers functionalities OpenBLAS don't provide (such as VML)

I've been doing fine with VML and BLAS1 (inspired by VML.jl and Base.BLAS) but I'm struggling a little bit with BLAS2. Here's my example :

Libdl.dlopen(:libmkl_rt) # necessary to preload - don't know why
const libmkl   = :libmkl_rt
const libvml   = :libmkl_vml_avx

## ?gemv
function mkl_gemv!( layout::Cint, trans::Char,
                    m::Integer, n::Integer,
                    alpha::Float64, A::Union{Ptr{Float64},DenseArray{Float64}}, lda::Integer, X::Union{Ptr{Float64},DenseArray{Float64}}, incx::Integer,
                    beta::(Float64), Y::Union{Ptr{Float64},DenseArray{Float64}}, incy::Integer)

    ccall((:dgemv, libmkl), Void,
            (Ptr{Cint}, Ptr{Int},
            Ptr{Int}, Ptr{Int},
            Ptr{Float64}, Ptr{Float64}, Ptr{Int}, Ptr{Float64}, Ptr{Int},
            Ptr{Float64}, Ptr{Float64}, Ptr{Int}),
            &layout, &trans,
            &m, &n,
            &alpha, A, &lda, X, incx,
            &beta, Y, &incy)
    Y
end


A = [1.0 2.0 3.0 ; 3.0 4.0 5.0]
m,n = size(A,1),size(A,2)
X = [1.0,2.0,3.0]
Y = [1.0,1.0]

# Native Julia
2*A*X+Y

# MKL
mkl_gemv!(  convert(Cint,102), 'N',
            2, 3,
            2.0, A, 3, X, 1,
            1.0, Y, 1)

It's not working. It seems the layout param(which is a C ENUM) is rejected and I do not no what to do with it.

WARNING: convert(::Type{Ptr}, ::Int64) methods should be converted to be methods of unsafe_convert
 in depwarn at deprecated.jl:73
 [inlined code] from deprecated.jl:418
 in unsafe_convert at no file:417
 in mkl_gemv! at /Users/Lionel/.julia/v0.4/MKL/src/test_blas_level_2.jl:11
 in include at /Applications/Julia-0.4.0.app/Contents/Resources/julia/lib/julia/sys.dylib
 in include_from_node1 at /Applications/Julia-0.4.0.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/Lionel/.julia/v0.4/MKL/src/test_blas_level_2.jl, in expression starting on line 36
** On entry to DGEMV , parameter number  1 had an illegal value
2-element Array{Float64,1}:
 29.0
 53.0

Do you have any suggestion ?
I'm planning to release something when I'm good with BLAS2.

Thanks,
Lionel