- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following program:
#include <float.h>
#include <iostream>
int main(){
std::cout << FLT_RADIX << std::endl;
};
compiles and run fine with
$ c++ -o main main.cpp && ./main
2
but it does not compile anymore with
$ c++ -o main main.cpp -I/opt/intel/oneapi/compiler/latest/linux/compiler/include
main.cpp: In function ‘int main()’:
main.cpp:5:16: error: ‘FLT_RADIX’ was not declared in this scope
5 | std::cout << FLT_RADIX << std::endl;
Is that an expected behaviour of `intel-mkl` ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your reply.
>> I still haven't been able to make it compile while keeping the original `pkg_search_module` line.
You can use both the PkgConfig and the MKL Config but we need to specify the exact MKLROOT environment.
Could you please try adding the below lines of code and let us know if you are still facing any issues?
cmake_minimum_required(VERSION 3.20..3.22)
project(MklTest LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(main main.cpp)
#-------------------------------------------------------------------------------
find_package(PkgConfig REQUIRED)
pkg_search_module(MKL mkl-dynamic-lp64-iomp PATHS $ENV{MKLROOT})
target_include_directories(main PRIVATE PATHS $ENV{MKLROOT})
#-------------------------------------------------------------------------------
#target_link_libraries(main PRIVATE toml++)
Please refer to the below link for more details on pkg-config:
>>The reason is that it expects `MKL_ROOT` to be defined but the environment only defines `MKLROOT`.
No, it is not a bug and by default, MKLROOT was defined by the setvars.sh environment. MKL_ROOT may be required for non-standard install locations. Could you please refer to the CMakeLists for more details:
Thanks and Regards,
Varsha
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for posting in Intel Communities.
When we tried the sample reproducer code provided by you with the Intel C++(ICPX) compiler, we were able to get the expected results without any errors. Please find the below screenshot and the command to run the code:
Compiling: icpx code.cpp -qmkl
Running: ./a.out
>>Is that an expected behaviour of `intel-mkl` ?
Could you please let us know what kind of errors you are facing with Intel MKL?
Could you please try and let us know if you are still facing any issues?
Thanks & Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello and thank you for support. The error disappears indeed with `icpx` compiler. Does it mean that MKL headers are not compatible with `gcc` or `clang`?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
>>Does it mean that MKL headers are not compatible with `gcc` or `clang`?
From the sample reproducer code, we could not see any MKL headers or code to include Intel MKL.
But, Intel oneMKL is compatible with gcc and clang compilers.
For proper compiling and linking of your code with several compilers and third-party libraries, and provides different interfaces to the functionality with Intel MKL, please refer to the Intel Link Line Advisor
Thanks & Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, indeed, the MKL header does not actually appear in my example. I have boiled it down from the following situation, where adding MKL to my CMake project made compilaition fail:
main.cpp
#include <float.h>
#include <iostream>
int main() { std::cout << FLT_RADIX << std::endl; };
CMakeLists.txt
cmake_minimum_required(VERSION 3.20..3.22)
project(MklTest LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(main main.cpp)
#-------------------------------------------------------------------------------
# Works if I remove this snippet.
find_package(PkgConfig REQUIRED)
pkg_search_module(MKL mkl-dynamic-lp64-iomp)
target_include_directories(main PRIVATE ${MKL_INCLUDE_DIRS})
#-------------------------------------------------------------------------------
target_link_libraries(main PRIVATE toml++)
FWIU, the the generated variable MKL_INCLUDE_DIRS expands to several paths, including the actual MKL headers and the `compiler/include` header that makes compilation fails with the "undeclared FLT_RADIX" error if the `CCX` environment variable is set to either a GCC or a CLANG compiler, but not if set to ICPX.
Considering that you do expect MKL to be compatible with other compilers and libraries.. then maybe the problem actually lies within the CMake heuristic supposed to find MKL modules?
At this point, maybe I should provide more information about my system and a step by step procedure to help you reproduce. Sorry for not having done this earlier:
$ neofetch
-` iago-lito@copak
.o+` ---------------
`ooo/ OS: Arch Linux x86_64
`+oooo: Host: Precision 3460
`+oooooo: Kernel: 6.5.2-arch1-1
-+oooooo+: Uptime: 1 day, 15 hours, 38 mins
`/:-:++oooo+: Packages: 1339 (pacman)
`/++++/+++++++: Shell: zsh 5.9
`/++++++++++++++: Resolution: 2560x1440
`/+++ooooooooooooo/` DE: GNOME 44.4
./ooosssso++osssssso+` WM: Mutter
.oossssso-````/ossssss+` WM Theme: Adwaita
-osssssso. :ssssssso. Theme: Adwaita [GTK2/3]
:osssssss/ osssso+++. Icons: Adwaita [GTK2/3]
/ossssssss/ +ssssooo/- Terminal: alacritty
`/ossssso+/:- -:/+osssso+- CPU: 12th Gen Intel i7-12700 (20) @ 4.800GHz
`+sso+:-` `.-/+oso: GPU: NVIDIA T400 4GB
`++:. `-/+/ GPU: Intel AlderLake-S GT1
.` `/ Memory: 9816MiB / 31787MiB
$ pacman -Qi intel-oneapi-mkl
Name : intel-oneapi-mkl
Version : 2023.2.0_49495-2
Description : Intel oneAPI Math Kernel Library
Architecture : x86_64
URL : https://software.intel.com/content/www/us/en/develop/tools/oneapi.html
Licenses : custom
Groups : None
Provides : intel-mkl intel-mkl-static
Depends On : intel-oneapi-compiler-dpcpp-cpp-runtime intel-oneapi-tbb intel-oneapi-common
Optional Deps : None
Required By : python-pytorch-cuda
Optional For : None
Conflicts With : intel-mkl intel-mkl-static intel-oneapi-basekit
Replaces : intel-mkl intel-mkl-static
Installed Size : 3.16 GiB
Packager : Torsten Keßler <tpkessler@archlinux.org>
Build Date : Sat 02 Sep 2023 04:22:23 PM CEST
Install Date : Mon 04 Sep 2023 05:44:01 PM CEST
Install Reason : Installed as a dependency for another package
Install Script : No
Validated By : Signature
Prepare folder with the two files above:
.
├── CMakeLists.txt
└── main.cpp
Fail build with:
$ cmake .
-- The CXX compiler identification is GNU 13.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1")
-- Checking for one of the modules 'mkl-dynamic-lp64-iomp'
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: .
$ make
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
./tp/main.cpp: In function ‘int main()’:
./tp/main.cpp:4:27: error: ‘FLT_RADIX’ was not declared in this scope
4 | int main() { std::cout << FLT_RADIX << std::endl; };
| ^~~~~~~~~
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Here is a docker recipe to (hopefully) reproduce on another distro/OS:
Dockerfile
# syntax=docker/dockerfile:1.3-labs
FROM archlinux
RUN <<EOF
pacman -Syu --noconfirm
pacman -Sy --noconfirm base-devel cmake intel-oneapi-mkl
mkdir /test
EOF
WORKDIR /test
COPY ./main.cpp .
COPY ./CMakeLists.txt .
RUN cmake .
ENTRYPOINT ["make"]
Build image with:
$ docker buildx build -t mkltest .
Run and fail compilation with:
$ docker run --rm -it mkltest
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/test/main.cpp: In function ‘int main()’:
/test/main.cpp:4:27: error: ‘FLT_RADIX’ was not declared in this scope
4 | int main() { std::cout << FLT_RADIX << std::endl; };
| ^~~~~~~~~
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Can you reproduce?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for providing all the details and reply.
When we tried to run the CMakeLists provided by you, we were able to get errors but we have included the MKL directories properly. Could you please try the below-attached CMakeLists.txt using the sample reproducer code provided by you with GCC compiler as well as Intel LLVM compiler?
Please find the below screenshots for more details:
Using GNU Compiler
Using Intel LLVM Compiler
Could you please try and let us know if you are still facing any issues?
Thanks & Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for support again. The CMakeLists.txt you provide does fix the build process. From what I understand, the problem stemed from `find_package(MKL CONFIG REQUIRED)` and `pkg_search_module(MKL mkl-dynamic-lp64-iomp)` not properly loaded from environment variable `MKLROOT` because they actually expect `MKL_ROOT` to be defined instead, is that correct?
I would rather expect `find_package(MLK CONFIG REQUIRED)` to work out of the box. Maybe this should be considered a bug in `FindMKL.cmake`? Or a failure of the pacman package intel-oneapi-mkl to meet the environment expected by `cmake` and `MKL` to work together?
Also, I am confused because the project I'm working on does not use
find_package(MKL CONFIG REQUIRED)
as you suggest in your `CMakeLists.txt`, but
find_package(PkgConfig REQUIRED)
pkg_search_module(MKL mkl-dynamic-lp64-iomp)
instead, which still leads to the the same failure. What difference does it make?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your reply.
>>The CMakeLists.txt you provide does fix the build process.
Glad to know that you are able to run and build it without any issues.
When we do initialize the Intel MKL environment it will set the MKLROOT path.
echo $MKLROOT
/opt/intel/oneapi/mkl/2023.2.0
We have changed the CMakeLists file and it is working as expected. Please find the attached file for details and screenshot:
Also, could you please find the below link for more details and usage of CMake:
Thanks & Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We have not heard back from you. Could you please let us know if you need any other details?
Thanks & Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, well, although the example toy project does compile with the CMakeLists.txt files that you suggest, a few questions remain unanswered:
1) The project I have been given uses
find_package(PkgConfig REQUIRED)
pkg_search_module(MKL mkl-dynamic-lp64-iomp)
instead of
find_package(MKL CONFIG REQUIRED)
Why ? What difference does it make? I still haven't been able to make it compile while keeping the original `pkg_search_module` line.
2) The line
find_package(MKL CONFIG REQUIRED)
does not even work out-of-the box, and we need to tweak it into
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
to make it work. The reason is that it expects `MKL_ROOT` to be defined but the environment only defines `MKLROOT`. Is this expected behaviour? Or is this a bug in `FindMKL.cmake` ? Or is this a bug in my distribution / environment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your reply.
>> I still haven't been able to make it compile while keeping the original `pkg_search_module` line.
You can use both the PkgConfig and the MKL Config but we need to specify the exact MKLROOT environment.
Could you please try adding the below lines of code and let us know if you are still facing any issues?
cmake_minimum_required(VERSION 3.20..3.22)
project(MklTest LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(main main.cpp)
#-------------------------------------------------------------------------------
find_package(PkgConfig REQUIRED)
pkg_search_module(MKL mkl-dynamic-lp64-iomp PATHS $ENV{MKLROOT})
target_include_directories(main PRIVATE PATHS $ENV{MKLROOT})
#-------------------------------------------------------------------------------
#target_link_libraries(main PRIVATE toml++)
Please refer to the below link for more details on pkg-config:
>>The reason is that it expects `MKL_ROOT` to be defined but the environment only defines `MKLROOT`.
No, it is not a bug and by default, MKLROOT was defined by the setvars.sh environment. MKL_ROOT may be required for non-standard install locations. Could you please refer to the CMakeLists for more details:
Thanks and Regards,
Varsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, and thank you for the explanations and the docs. I'll look into the non-standard installations to track the reason for the mismatched varname, but I guess this gets out of scope for this forum then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Sure, Thanks for accepting our solution. It’s great to know that the issue has been resolved, in case you run into any other issues please feel free to create a new thread.
Have a Good Day!
Thanks & Regards,
Varsha
![](/skins/images/D2683F18326913BBA0436CB7114DD569/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page