Problem when loading Intel MKL shared library to use with C written shared library

Roman_Istomin
Wed, 06 Oct 2021 18:30:19 +0000
General Usage

Hi, I have written an optimized C library to do some matrix algebra basically, speeding up some einsum operations.
I can compile and use the library from C and C++, it links to Intel MKL and is able to run normally. This is how I am trying to use if from Julia:

W = 1.0*Vector(1:4)
X = Vector([4:10])*1.0
v = Vector([1:6])
P = Vector([0;0])
XV = Vector(1:4)
using Libdl

Libdl.dlopen("/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_core.so")
Libdl.dlopen("/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_gnu_thread.so")
Libdl.dlopen("/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so")
ccall((:face_split_product_dgemm_batched, "/opt/rh/devtoolset-9/root/usr/lib/libface_splitting_c.so"), Cvoid, (Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Int64, Int64, Int64, Ptr{Float64}, Ptr{Float64}), W, X, v, 2, 2, 3, P, XV)

I know that my written library libface_splitting_c.so links to Intel MKL and its battery of .so files. I am trying to dlopen one of those and this is what I am getting:

julia> Libdl.dlopen("/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so")
ERROR: could not load library "/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so"
/opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so: undefined symbol: mkl_lapack_zhesvxx
Stacktrace:
 [1] dlopen(s::String, flags::UInt32; throw_error::Bool)
   @ Base.Libc.Libdl ./libdl.jl:114
 [2] dlopen (repeats 2 times)
   @ ./libdl.jl:114 [inlined]
 [3] top-level scope
   @ REPL[2]:1

This is how I compile the libraries:

CPP=g++
CC=gcc

MKLROOT = /opt/intel/compilers_and_libraries_2020.4.304/linux/mkl

# include and link directories must have been amended by mklvsrs.sh script from intel mkl

CFLAGS=-c -I. -fopenmp -m64 -Wl,--no-as-needed -O3
LFLAGS=-L. -fopenmp -m64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_core -lmkl_gnu_thread -lpthread -lm -ldl
SHFLAGS= -fpic
DEPS = face_splitting_product.cpp face_splitting_product.hpp face_splitting_product.c face_splitting_product.h

all: face_splitting_product.o face_splitting_product_c.o face_splitting.so face_splitting_c.so

face_splitting_product.o: face_splitting_product.cpp $(DEPS)
	$(CPP) face_splitting_product.cpp -o face_splitting_product.o $(CFLAGS) $(SHFLAGS)

face_splitting_product_c.o: face_splitting_product.c $(DEPS)
	$(CC) face_splitting_product.c -o face_splitting_product_c.o $(CFLAGS) $(SHFLAGS)

face_splitting.so: face_splitting_product.o
	$(CPP) -shared face_splitting_product.o -o libface_splitting.so $(LFLAGS)

face_splitting_c.so: face_splitting_product_c.o
	$(CC) -shared face_splitting_product_c.o -o libface_splitting_c.so $(LFLAGS)

10 posts - 3 participants