These CMake functions detect the CPU arch for Intel CPUs on Linux, MacOS and Windows.
These can be useful for setting -mtune
flag for Intel oneAPI.
GCC can simply use -mtune=native
instead.
Related: CMake project that reveals numerous flags for fine-grained CPU capabilities
HOST_ARCH
for Intel CPUs, the generation name e.g. kabylake suitable for-mtune=
HOST_FLAGS
more optimal tuning flags for host system. Sacrifices portability for performance.HAS_AVX
HAS_AVX2
HAS_NEON
cmake -B build
cmake --build build
If AVX2 is available, the example can be checked:
cd build
ctest
To use in an actual project, copy DetectHostArch.cmake to your project directory.
Then do like the part in if(BUILD_TESTING)
in this project's CMakeLists.txt.
Intel oneAPI
-xHost
or /QxHost
is like -march=native -mtune=native
on GCC or Clang.
Better runtime performance can come from enabling the features of the host CPU.
If you choose to not use -xHost
or /QxHost
then the
mtune
option can be used.
There is currently no -mtune=native
for oneAPI, so this CMake CPU arch detection can help.