Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
/ cmake-cpu-detect Public archive

CMake detect CPU arch / model, useful for -mtune= on Intel oneAPI

License

Notifications You must be signed in to change notification settings

scivision/cmake-cpu-detect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CMake CPU detect

ci

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

Result variables

  • 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

Usage

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

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.

About

CMake detect CPU arch / model, useful for -mtune= on Intel oneAPI

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published