From ef7ff0adebcbaa1f7098b686c4256cf97d77a696 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 13 Feb 2020 19:57:17 +0100 Subject: [PATCH] Add options for AVX, AVX2, AVX512 compilation options Compile fix for scene.cpp --- CMakeLists.txt | 26 ++++++++++++++++++- ext/ghoul | 2 +- src/scene/scene.cpp | 1 + .../set_openspace_compile_settings.cmake | 23 ++++++++++++++-- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 215dfa5b16..33aed7363d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,30 @@ endif() option(OPENSPACE_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) +if (MSVC) + option(OPENSPACE_OPTIMIZATION_ENABLE_AVX "Enable AVX instruction set for compilation" OFF) + option(OPENSPACE_OPTIMIZATION_ENABLE_AVX2 "Enable AVX2 instruction set for compilation" OFF) + option(OPENSPACE_OPTIMIZATION_ENABLE_AVX512 "Enable AVX2 instruction set for compilation" OFF) + option(OPENSPACE_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS "Enable other optimizations, like LTCG, intrinsics, etc") + + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX AND OPENSPACE_OPTIMIZATION_ENABLE_AVX2) + message(FATAL_ERROR "Cannot enable AVX and AVX2 instructions simultaneously") + endif () + + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX AND OPENSPACE_OPTIMIZATION_ENABLE_AVX512) + message(FATAL_ERROR "Cannot enable AVX and AVX512 instructions simultaneously") + endif() + + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX2 AND OPENSPACE_OPTIMIZATION_ENABLE_AVX512) + message(FATAL_ERROR "Cannot enable AVX2 and AVX512 instructions simultaneously") + endif() + + set(GHOUL_OPTIMIZATION_ENABLE_AVX ${OPENSPACE_OPTIMIZATION_ENABLE_AVX} CACHE BOOL "" FORCE) + set(GHOUL_OPTIMIZATION_ENABLE_AVX2 ${OPENSPACE_OPTIMIZATION_ENABLE_AVX2} CACHE BOOL "" FORCE) + set(GHOUL_OPTIMIZATION_ENABLE_AVX512 ${OPENSPACE_OPTIMIZATION_ENABLE_AVX512} CACHE BOOL "" FORCE) + set(GHOUL_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS ${OPENSPACE_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS} CACHE BOOL "" FORCE) +endif () + include(src/CMakeLists.txt) ########################################################################################## @@ -132,6 +156,7 @@ endif() # Ghoul add_subdirectory(${OPENSPACE_EXT_DIR}/ghoul) target_link_libraries(openspace-core Ghoul) +set_openspace_compile_settings(Ghoul) set_folder_location(Lua "External") set_folder_location(lz4 "External") set_folder_location(GhoulTest "Unit Tests") @@ -204,7 +229,6 @@ if (MSVC) target_include_directories(openspace-core PUBLIC "${OPENSPACE_NVTOOLS_PATH}/include") end_dependency() endif () - endif () begin_header("Configuring Modules") diff --git a/ext/ghoul b/ext/ghoul index ab9b4d1763..dae112a3a0 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit ab9b4d1763b472f59be7592856c756bfcbd2d0ee +Subproject commit dae112a3a05eebe880db3b39456bc8c4542c8261 diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index f8c9ef6e8a..459bc352a1 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/support/cmake/set_openspace_compile_settings.cmake b/support/cmake/set_openspace_compile_settings.cmake index 70abc0f055..61efb29938 100644 --- a/support/cmake/set_openspace_compile_settings.cmake +++ b/support/cmake/set_openspace_compile_settings.cmake @@ -30,7 +30,6 @@ function (set_openspace_compile_settings project) target_compile_options( ${project} PRIVATE - "/ZI" # Edit and continue support "/MP" # Multi-threading support "/W4" # Highest warning level "/w44062" # enumerator 'identifier' in a switch of enum 'enumeration' is not handled @@ -81,8 +80,28 @@ function (set_openspace_compile_settings project) # Boost as of 1.64 still uses unary_function unless we define this target_compile_definitions(${project} PRIVATE "_HAS_AUTO_PTR_ETC") - target_compile_definitions(${project} PRIVATE "NOMINMAX") + + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX) + target_compile_options(${project} PRIVATE "/arch:AVX") + endif () + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX2) + target_compile_options(${project} PRIVATE "/arch:AVX2") + endif () + if (OPENSPACE_OPTIMIZATION_ENABLE_AVX512) + target_compile_options(${project} PRIVATE "/arch:AVX512") + endif () + + if (OPENSPACE_OPTIMIZATION_ENABLE_OTHER_OPTIMIZATIONS) + target_compile_options(${project} PRIVATE + "/Oi" # usage of intrinsic functions + "/GL" # Whole program optimization + ) + else () + target_compile_options(${project} PRIVATE + "/ZI" # Edit and continue support + ) + endif () elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (OPENSPACE_WARNINGS_AS_ERRORS) target_compile_options(${project} PRIVATE "-Werror")