From 94946cf75e7ac46a02660a65f81421d4c10e6b8a Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Tue, 5 Oct 2021 00:32:01 +0200 Subject: [PATCH] refactor optimization flags --- examples/alpaka/nbody/CMakeLists.txt | 19 ++++--------------- examples/alpaka/pic/CMakeLists.txt | 13 +++---------- examples/heatequation/CMakeLists.txt | 16 +++------------- examples/nbody/CMakeLists.txt | 19 ++++--------------- examples/nbody_benchmark/CMakeLists.txt | 18 +++--------------- examples/raycast/CMakeLists.txt | 6 ++++++ examples/vectoradd/CMakeLists.txt | 18 ++++-------------- examples/viewcopy/CMakeLists.txt | 16 ++++------------ 8 files changed, 31 insertions(+), 94 deletions(-) diff --git a/examples/alpaka/nbody/CMakeLists.txt b/examples/alpaka/nbody/CMakeLists.txt index 497c0668ec..7cca1c2ed7 100644 --- a/examples/alpaka/nbody/CMakeLists.txt +++ b/examples/alpaka/nbody/CMakeLists.txt @@ -10,19 +10,8 @@ alpaka_add_executable(${PROJECT_NAME} nbody.cpp ../../common/Stopwatch.hpp) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama alpaka::alpaka Vc::Vc) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - #-fno-math-errno # sqrt prevents vectorization otherwise - -march=native - -ffast-math - ) -elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/alpaka/pic/CMakeLists.txt b/examples/alpaka/pic/CMakeLists.txt index db2af81af6..6e6d4f2982 100644 --- a/examples/alpaka/pic/CMakeLists.txt +++ b/examples/alpaka/pic/CMakeLists.txt @@ -12,14 +12,7 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama fmt::fmt alpaka::alpaka OpenMP::OpenMP_CXX) if (MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - ) -elseif() - target_compile_options(${PROJECT_NAME} PRIVATE - #-fno-math-errno # sqrt prevents vectorization otherwise - -march=native - -ffast-math - ) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/heatequation/CMakeLists.txt b/examples/heatequation/CMakeLists.txt index f81ab61455..69c2fd2b6b 100644 --- a/examples/heatequation/CMakeLists.txt +++ b/examples/heatequation/CMakeLists.txt @@ -13,18 +13,8 @@ if (Vc_FOUND) target_link_libraries(${PROJECT_NAME} PRIVATE Vc::Vc) endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - -march=native - -ffast-math - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - ) + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/nbody/CMakeLists.txt b/examples/nbody/CMakeLists.txt index 9798103419..e65e0e3186 100644 --- a/examples/nbody/CMakeLists.txt +++ b/examples/nbody/CMakeLists.txt @@ -15,19 +15,8 @@ if (Vc_FOUND) target_link_libraries(${PROJECT_NAME} PRIVATE Vc::Vc) endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - #-fno-math-errno # sqrt prevents vectorization otherwise - -march=native - -ffast-math - ) -elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/nbody_benchmark/CMakeLists.txt b/examples/nbody_benchmark/CMakeLists.txt index 557e01f0d7..4086a19fd8 100644 --- a/examples/nbody_benchmark/CMakeLists.txt +++ b/examples/nbody_benchmark/CMakeLists.txt @@ -9,20 +9,8 @@ add_executable(${PROJECT_NAME} nbody.cpp) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama fmt::fmt) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - #-fno-math-errno # sqrt prevents vectorization otherwise - -march=native - -ffast-math - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast /bigobj) elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - /bigobj - ) + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/raycast/CMakeLists.txt b/examples/raycast/CMakeLists.txt index 92543a8ca8..317a2fe692 100644 --- a/examples/raycast/CMakeLists.txt +++ b/examples/raycast/CMakeLists.txt @@ -9,3 +9,9 @@ add_executable(${PROJECT_NAME} raycast.cpp) target_include_directories(${PROJECT_NAME} PRIVATE ../../thirdparty/stb/include) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) target_link_libraries(${PROJECT_NAME} PRIVATE tinyobjloader::tinyobjloader llama::llama) + +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) +endif() diff --git a/examples/vectoradd/CMakeLists.txt b/examples/vectoradd/CMakeLists.txt index 30c602de40..0d6f268303 100644 --- a/examples/vectoradd/CMakeLists.txt +++ b/examples/vectoradd/CMakeLists.txt @@ -8,18 +8,8 @@ add_executable(${PROJECT_NAME} vectoradd.cpp ../common/Stopwatch.hpp) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - -march=native - -ffast-math - ) -elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - /fp:fast - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2 /fp:fast) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native -ffast-math) endif() diff --git a/examples/viewcopy/CMakeLists.txt b/examples/viewcopy/CMakeLists.txt index 25cfbc973a..4124a87508 100644 --- a/examples/viewcopy/CMakeLists.txt +++ b/examples/viewcopy/CMakeLists.txt @@ -9,16 +9,8 @@ add_executable(${PROJECT_NAME} viewcopy.cpp ../common/Stopwatch.hpp) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama OpenMP::OpenMP_CXX) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR - CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR - CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR - CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - target_compile_options(${PROJECT_NAME} PRIVATE - -march=native - ) -elseif(MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE - /arch:AVX2 - ) +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /arch:AVX2) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -march=native) endif()