Intel® oneAPI Math Kernel Library (oneMKL) and pkg-config tool

ID 标签 659677
已更新 1/12/2023
版本 Latest
公共

author-image

作者

The pkg-config tool[1] is a widely used tool that many users apply to their makefiles. Intel® oneAPI Math Kernel Library (oneMKL) provides pkg-config metadata files for this tool starting with the Intel® Math Kernel Library (Intel® MKL) 2018 Update 1 release.

oneMKL 2023.0 adds files for Intel® oneAPI Thread Building Blocks (oneTBB), mkl_rt linking and OpenMP* threaded library for GNU* support.

This table describes the oneMKL pkg-config metadata files provided and the oneMKL configurations that they cover.

Interface:

LP64

ILP64

Threading:

Sequential

OpenMP threaded oneMKL OpenMP threaded library for GNU 

oneTBB

Sequential

OpenMP threaded oneMKL OpenMP threaded library for GNU 

oneTBB

Link type

Static

mkl-static-lp64-seq

mkl-static-lp64-iomp

mkl-static-lp64-gomp

mkl-static-lp64-tbb

mkl-static-ilp64-seq

mkl-static-ilp64-iomp

mkl-static-ilp64-gomp

mkl-static-ilp64-tbb

Dynamic

mkl-dynamic-lp64-seq

mkl-dynamic-lp64-iomp

mkl-dynamic-lp64-gomp

mkl-dynamic-lp64-tbb

mkl-dynamic-ilp64-seq

mkl-dynamic-ilp64-iomp

mkl-dynamic-ilp64-gomp

mkl-dynamic-ilp64-tbb

SDL*

mkl-sdl

*Single Dynamic Library (mkl_rt)

pkg-config is a helper tool that provide the necessary options for compiling and linking an application to a library. For example, if you want to build your source code test.c with oneMKL, you can call the pkg-config tool and provide the name of the oneMKL pkg-config metadata as an input parameter. The full compiling and linking line would be:   e:   

Linux* OS:  icc test.c pkg−config --cflags --libs mkl−dynamic−lp64−iomp
Windows* OS:  for /F "delims=," %i in ('pkg-config --cflags --libs mkl-dynamic-lp64-iomp') do icl test.c %i

For the mkl-dynamic-lp64-iomp, oneMKL configuration (dynamic linking, LP64 interface and OpenMP threaded library with Intel® oneAPI) the pkg-config tool generates the following full executable command line on Linux OS:

icc test.c -I/opt/intel/compilers_and_libraries/linux/mkl/include  -L/opt/intel/compilers_and_libraries/linux/mkl/lib/intel64_lin -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -L/opt/intel/compilers_and_libraries/linux/mkl/../compiler/lib/intel64_lin -liomp5 -lpthread -lm -ldl

To get the compilation line for oneMKL, call pkg-config with the --cflags option:

pkg-config --cflags mkl-dynamic-lp64-iomp

To get the link line for oneMKL, call pkg-config with the --libs option:

pkg-config --libs mkl-dynamic-lp64-iomp

The pkg-config tool helps avoid large hard-coded link lines inside makefiles and makes it easy to change the linking line by using another pkg-config metadata file as an input parameter for the pkg-config tool or by adjusting the metadata file itself.

To adjust compilation and link options in the pkg-config metadata file:

  1. Go to the <onemkl_install_dir>/mkl/bin/pkgconfig directory.
  2. Specify Libs:the link line that is returned by pkg_config --libs. You can get the preferred link line for the oneMKL configuration using the Link Line Advisor for oneMKL or the offline oneMKL link line tool.
  3. Specify Cflags: the compiler options that will be returned by pkg-config --cflags. You can also update it (see the instruction from step 3).

Example of oneMKL pkg-config metadata file mkl-dynamic-lp64-iomp for Linux OS*:

prefix=${pcfiledir}/../..

exec_prefix=${prefix}

libdir=${exec_prefix}/lib/intel64

includedir=${prefix}/include

#info

Name: mkl

Description: Intel(R) oneAPI Math Kernel Library

Version: 2023

URL: https://software.intel.com/en-us/mkl

Requires: openmp >= 2021.0.0

#Link line

Libs: -L${libdir} -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lm -ldl

#Compiler line

Cflags: -I"${includedir}"

To use oneMKL pkg-config metadata files with the pkg-config tool please be sure that you add the full path for the oneMKL pkg-config metadata files to PKG_CONFIG_PATH so that pkg-config can locate them.

Use the oneMKL environment script to set up entire Intel MKL environment.