Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7222 Discussions

BLAS-like extensions cause segmentation fault for me (regular BLAS routines work)

NatSpring
Beginner
427 Views

I have written many Julia wrapper-functions that call routines from various parts of Intel oneAPI without issue, such as BLAS routines, LAPACK routines and vector mathematical functions using ccall.

However, when I try to do the same thing with functions that are from the "BLAS-like Extensions" category of Intel oneAPI I get segmentation faults. I have tried two routines that are BLAS-like extensions: mkl_dimatcopy and mkl_domatadd, both crash in the same way.

Here is a minimal example showing how I call the mkl_dimatcopy routine from the MKL library file libmkl_rt.so using Julia:

# Path to MKL library file.
const libmklSo = "/opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so"
@assert(isfile(libmklSo))

# Random 10 x 10 matrix to transpose.
AB = rand(10, 10)

# Verify that AB is 64-byte aligned which is a requirement of mkl_dimatcopy. 
@assert((UInt(pointer(AB)) % 64) == 0)

# Call the mkl_dimatcopy routine.
ccall((:mkl_dimatcopy, libmklSo), Cvoid,
    (
        Cchar,        # ordering ('C')
        Cchar,        # trans ('T')
        Csize_t,      # rows (10)
        Csize_t,      # cols (10)
        Cdouble,      # alpha (1.0)
        Ptr{Cdouble}, # AB
        Csize_t,      # lda (10)
        Csize_t,      # ldb (10)
    ),
    'C', 'T', 10, 10, 1.0, AB, 10, 10)

Running this code causes a segfault for me.

I have also tried to verify that the mkl_dimatcopy symbol is in the libmkl_rt.so file I am using, and it seems to be:

$ nm -D /opt/intel/oneapi/mkl/latest/lib/libmkl_rt.so | grep mkl_dimatcopy
00000000005ff510 T mkl_dimatcopy
00000000005ff510 T mkl_dimatcopy_
00000000005ff640 T mkl_dimatcopy_batch
00000000005ff640 T mkl_dimatcopy_batch_
00000000005ff770 T mkl_dimatcopy_batch_strided
00000000005ff770 T mkl_dimatcopy_batch_strided_

Does anyone understand why this is happening and how I can fix the issue? 

0 Kudos
1 Reply
Andrew_Barker
Employee
287 Views

This is similar to a previous issue.

Briefly, the symbol for the C interface is MKL_Dimatcopy while the symbol for the fortran interface is mkl_dimatcopy, they differ in whether certain parameters are passed by value or as pointers. Users who include C header files do not see this distinction but calling directly via the Julia ccall interface reveals it.

The simplest way to resolve your issue would be to replace line 12 in your code with

ccall((:MKL_Dimatcopy, libmklSo), Cvoid,
0 Kudos
Reply