-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow architecture-specific optimizations to be skipped
march=native builds optimized but non-portable binaries. When building binaries for distribution or sharing between machines, a more careful approach to platform optimization must be taken. A better approach might be to provide optimization profiles that target broadly available instruction extensions, e.g., AVX2. But there seems to be a number of tuning parameters (e.g., cache sizes) and compiler-specific flags involved, so I am deferring this for now. Along the way, refactor find_packages(ArchFlags) to include(CheckArchFlags) since determining compiler flags does not have much similarity to finding packages. find_package_handle_standard_args in FindArchFlags.cmake also was raising warnings due its non-standard form: The package name passed to `find_package_handle_standard_args` (ARCH_FLAGS) does not match the name of the calling package (ArchFlags). This can lead to problems in calling code that expects `find_package` result variables (e.g., `_FOUND`) to follow a certain pattern.
- Loading branch information
Showing
3 changed files
with
45 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Find architecture-specific flags | ||
# | ||
# Once done this will define | ||
# ARCH_FLAGS_FOUND | ||
# ARCH_CXX_FLAGS - Compiler flags to enable architecture-specific optimizations | ||
# ARCH_C_FLAGS - Compiler flags to enable architecture-specific optimizations | ||
# ARCH_LINK_FLAGS - Compiler flags to enable architecture-specific optimizations | ||
include(CheckCXXCompilerFlag) | ||
|
||
if(NOT USE_ARCH OR USE_ARCH STREQUAL "none" OR ARCH_FLAGS_FOUND) | ||
set(ARCH_CXX_FLAGS_CANDIDATES) | ||
else() | ||
set(ARCH_CXX_FLAGS_CANDIDATES "-march=${USE_ARCH}") | ||
endif() | ||
|
||
if(USE_ARCH STREQUAL "mic") | ||
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel") | ||
list(APPEND ARCH_CXX_FLAGS_CANDIDATES -mmic) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCC) | ||
list(APPEND ARCH_CXX_FLAGS_CANDIDATES -march=knc) | ||
endif() | ||
endif() | ||
|
||
foreach(FLAG ${ARCH_CXX_FLAGS_CANDIDATES}) | ||
message(STATUS "Try architecture flag = [${FLAG}]") | ||
unset(ARCH_CXX_FLAGS_DETECTED) | ||
check_cxx_compiler_flag("${FLAG}" ARCH_CXX_FLAGS_DETECTED) | ||
if(ARCH_CXX_FLAGS_DETECTED) | ||
set(ARCH_FLAGS_FOUND "YES") | ||
set(ARCH_CXX_FLAGS "${FLAG}") | ||
set(ARCH_C_FLAGS "${FLAG}") | ||
set(ARCH_LINK_FLAGS "${FLAG}") | ||
endif() | ||
endforeach() |
This file was deleted.
Oops, something went wrong.