Combine nvcc with icx

Hello , I am currently trying to combine MKL , cuBLAS and cuSPARSE libraries and compile a single executable. The majority of the code is CUDA and I need to invoke only one MKL function. So I am guessing that I need to create an object file containing this function (csrilu02) and then link it with the other files.

I create the object file using:

icx -c test test.c -L/home/stavros/intel/oneapi/mkl/2022.1.0/lib/intel64 -liomp5 -lpthread -lm -ldl -DMKL_ILP64 -qmkl=parallel

and when I try to link it using nvcc by:

nvcc -o gpu_sparse gpu_sparse.cu cudaUtilities.cu utilities.c mmio.c read.c -lcublas -lcusolver -lcusparse -g -G test.o

I get this error message : undefined reference to `MKL_malloc’

I cannot understand what goes wrong and I am quite inexperienced in compilers and linkers. You can access the project’s source files here. Thank you in advance.

Hi stavrenas,

The error is because you’re missing the MKL libraries on the link line hence the symbol can’t be found. The question is how best to fix this.

Now, this forum is for questions on the NV HPC SDK compilers (i…e nvc, nvfortran, and nvc++), so we’ll try our best to answer, but we may need to redirect you to another forum for help.

I think the easiest solution would be to have nvcc use icx as the host compiler (by default it uses g++) and then add the same flags you have on the compilation. Something like:

nvcc -o gpu_sparse gpu_sparse.cu cudaUtilities.cu utilities.c mmio.c read.c -lcublas -lcusolver -lcusparse -g -G test.o -ccbin=icx -Xcompiler "-L/home/stavros/intel/oneapi/mkl/2022.1.0/lib/intel64 -liomp5 -lpthread -lm -ldl -DMKL_ILP64 -qmkl=parallel"

However, I believe nvcc only supports up to Intel 20.x compilers so you may also need to add “-allow-unsupported-compiler”.

If this still doesn’t work, then you can try adding the MKL libraries and most likely the Intel compiler runtime libraries to your link command. Exactly which libraries need to added, I don’t know.

-Mat

1 Like

Thank you for your reply.
I am sorry for posting on the wrong forum. As a workaround, I found out here that I can include test.c as a dependency and add these flags to nvcc:
-L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl

I will also try out your solution.