From 46688dbcbe68e728410018087715003b5c5cf172 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Mon, 14 Aug 2017 17:39:26 -0500 Subject: [PATCH] CMake: Update internal CUDA setup, remove obsolete code Update internal CUDA setup to use native language features. If the current CMake version is too old, fall back to the old behavior. Further, remove obsolete CUDA configuration from tests. --- cmake/config/Config.cmake.in | 17 ++++ cmake/macros/macro_deal_ii_add_library.cmake | 87 +++++++++---------- cmake/macros/macro_deal_ii_add_test.cmake | 7 +- .../macro_deal_ii_insource_setup_target.cmake | 51 ++++++++++- cmake/macros/macro_deal_ii_setup_target.cmake | 54 ++++++++++-- tests/setup_testsubproject.cmake | 7 ++ 6 files changed, 163 insertions(+), 60 deletions(-) diff --git a/cmake/config/Config.cmake.in b/cmake/config/Config.cmake.in index 45a02046ca..07c4c34d27 100644 --- a/cmake/config/Config.cmake.in +++ b/cmake/config/Config.cmake.in @@ -173,6 +173,23 @@ SET(DEAL_II_LIBRARIES_RELEASE "@CONFIG_LIBRARIES_RELEASE@") SET(DEAL_II_LIBRARIES "@CONFIG_LIBRARIES@") +# +# Information about CUDA configuration +# + +SET(DEAL_II_CUDA_TOOLKIT_ROOT_DIR "@CUDA_TOOLKIT_ROOT_DIR@") +SET(DEAL_II_CUDA_COMPILER "@CMAKE_CUDA_COMPILER@") + +# used for all cuda targets: +SET(DEAL_II_CUDA_FLAGS "@DEAL_II_CUDA_FLAGS@") + +# _additionally_ used for debug targets: +SET(DEAL_II_CUDA_FLAGS_DEBUG "@DEAL_II_CUDA_FLAGS_DEBUG@") + +# _additionally_ used for release targets: +SET(DEAL_II_CUDA_FLAGS_RELEASE "@DEAL_II_CUDA_FLAGS_RELEASE@") + + # # Information about library targets and feature configuration # diff --git a/cmake/macros/macro_deal_ii_add_library.cmake b/cmake/macros/macro_deal_ii_add_library.cmake index 3c4962560a..b9b9bee1d0 100644 --- a/cmake/macros/macro_deal_ii_add_library.cmake +++ b/cmake/macros/macro_deal_ii_add_library.cmake @@ -15,15 +15,14 @@ # # A small wrapper around ADD_LIBRARY that will define a target for each -# build type specified in DEAL_II_BUILD_TYPES +# build type specified in DEAL_II_BUILD_TYPES. Only compatible with object +# targets (as used in the build system). # # It is assumed that the desired compilation configuration is set via -# DEAL_II_LINKER_FLAGS_${build} # DEAL_II_CXX_FLAGS_${build} # DEAL_II_DEFINITIONS_${build} # # as well as the global (for all build types) -# DEAL_II_LINKER_FLAGS # DEAL_II_CXX_FLAGS # DEAL_II_DEFINITIONS # @@ -37,60 +36,60 @@ MACRO(DEAL_II_ADD_LIBRARY _library) ${ARGN} ) - - # - # Work around a problem in CUDA_WARP_SRCS that doesn't take empty list - # elements lightly... - # - SET(_definitions - ${DEAL_II_DEFINITIONS} - ${DEAL_II_DEFINITIONS_${_build}} - ) - SET_TARGET_PROPERTIES(${_library}_${_build_lowercase} PROPERTIES - LINK_FLAGS "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" - COMPILE_DEFINITIONS "${_definitions}" - COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" LINKER_LANGUAGE "CXX" ) - SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build} - "$" - ) + IF(CMAKE_VERSION VERSION_LESS 3.9) - # - # Cuda specific target setup: - # - IF(DEAL_II_WITH_CUDA) - - # - # CUDA_WRAP_SRCS does not automatically pick up host compiler flags - # from the target, so we have to feed relevant flags ourselves - # - # Furthermore, C++14 is not yet supported, so filter the flag: - # - STRING(REPLACE "-std=c++14" "-std=c++11" CMAKE_CXX_FLAGS - "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + SET_TARGET_PROPERTIES(${_library}_${_build_lowercase} PROPERTIES + COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + COMPILE_DEFINITIONS "${DEAL_II_DEFINITIONS};${DEAL_II_DEFINITIONS_${_build}}" ) - CUDA_WRAP_SRCS(${_library}_${_build_lowercase} - OBJ _generated_cuda_files ${ARGN} SHARED - ) - SET(CMAKE_CXX_FLAGS "") + ELSE() - ADD_CUSTOM_TARGET(${_library}_${_build_lowercase}_cuda - DEPENDS - ${_generated_cuda_files} - ) - ADD_DEPENDENCIES(${_library}_${_build_lowercase} - ${_library}_${_build_lowercase}_cuda + SET(_flags "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_flags) + TARGET_COMPILE_OPTIONS(${_library}_${_build_lowercase} PUBLIC + $<$:${_flags}> ) - SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build} - "${_generated_cuda_files}" + TARGET_COMPILE_DEFINITIONS(${_library}_${_build_lowercase} + PUBLIC ${DEAL_II_DEFINITIONS} ${DEAL_II_DEFINITIONS_${_build}} ) + + IF(DEAL_II_WITH_CUDA) + # + # Add cxx compiler and cuda compilation flags to cuda source files: + # + + SET(_cuda_flags "${DEAL_II_CUDA_FLAGS} ${DEAL_II_CUDA_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_cuda_flags) + + # + # Workaround: cuda will split every compiler option with a comma + # (','), so remove all compiler flags that contain a comma: + # + STRING(REGEX REPLACE "[^ ]*,[^ ]*" "" _cxx_flags + "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + ) + + TARGET_COMPILE_OPTIONS(${_library}_${_build_lowercase} PUBLIC + $<$:-Xcompiler "${_cxx_flags}"> + $<$:${_cuda_flags}> + ) + + SET_TARGET_PROPERTIES(${_library}_${_build_lowercase} PROPERTIES + CUDA_SEPARABLE_COMPILATION TRUE + ) + ENDIF() + ENDIF() + SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build} + "$" + ) ENDFOREACH() ENDMACRO() diff --git a/cmake/macros/macro_deal_ii_add_test.cmake b/cmake/macros/macro_deal_ii_add_test.cmake index 2036b2d9d4..5dbb375df6 100644 --- a/cmake/macros/macro_deal_ii_add_test.cmake +++ b/cmake/macros/macro_deal_ii_add_test.cmake @@ -249,12 +249,7 @@ MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file) OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${_target}/interrupt_guard.cc ) - - IF(DEAL_II_WITH_CUDA) - FIND_PACKAGE(CUDA) - CUDA_INCLUDE_DIRECTORIES("${DEAL_II_INCLUDE_DIRS}") - CUDA_WRAP_SRCS( ${_target} OBJ _generated_files ${_source_file} ) - ENDIF() + ADD_EXECUTABLE(${_target} EXCLUDE_FROM_ALL ${_generated_files} diff --git a/cmake/macros/macro_deal_ii_insource_setup_target.cmake b/cmake/macros/macro_deal_ii_insource_setup_target.cmake index f8141955a4..524e5d709b 100644 --- a/cmake/macros/macro_deal_ii_insource_setup_target.cmake +++ b/cmake/macros/macro_deal_ii_insource_setup_target.cmake @@ -28,10 +28,8 @@ MACRO(DEAL_II_INSOURCE_SETUP_TARGET _target _build) SET_TARGET_PROPERTIES(${_target} PROPERTIES LINK_FLAGS "${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" - COMPILE_DEFINITIONS "${DEAL_II_DEFINITIONS};${DEAL_II_DEFINITIONS_${_build}}" - COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" LINKER_LANGUAGE "CXX" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_test_short}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) SET_PROPERTY(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES @@ -41,6 +39,53 @@ MACRO(DEAL_II_INSOURCE_SETUP_TARGET _target _build) ${DEAL_II_INCLUDE_DIRS} ) + IF(CMAKE_VERSION VERSION_LESS 3.9) + SET_PROPERTY(TARGET ${_target} APPEND_STRING PROPERTY + COMPILE_FLAGS " ${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS};${DEAL_II_USER_DEFINITIONS_${_build}}" + ) + + ELSE() + + SET(_flags "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_flags) + TARGET_COMPILE_OPTIONS(${_target} PUBLIC + $<$:${_flags}> + ) + + TARGET_COMPILE_DEFINITIONS(${_target} + PUBLIC ${DEAL_II_DEFINITIONS} ${DEAL_II_DEFINITIONS_${_build}} + ) + + IF(DEAL_II_WITH_CUDA) + # + # Add cxx compiler and cuda compilation flags to cuda source files: + # + + SET(_cuda_flags "${DEAL_II_CUDA_FLAGS} ${DEAL_II_CUDA_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_cuda_flags) + + # + # Workaround: cuda will split every compiler option with a comma + # (','), so remove all compiler flags that contain a comma: + # + STRING(REGEX REPLACE "[^ ]*,[^ ]*" "" _cxx_flags + "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + ) + + TARGET_COMPILE_OPTIONS(${_target} PUBLIC + $<$:-Xcompiler "${_cxx_flags}"> + $<$:${_cuda_flags}> + ) + + SET_TARGET_PROPERTIES(${_target} PROPERTIES + CUDA_SEPARABLE_COMPILATION TRUE + ) + ENDIF() + ENDIF() + GET_PROPERTY(_type TARGET ${_target} PROPERTY TYPE) IF(NOT "${_type}" STREQUAL "OBJECT_LIBRARY") TARGET_LINK_LIBRARIES(${_target} diff --git a/cmake/macros/macro_deal_ii_setup_target.cmake b/cmake/macros/macro_deal_ii_setup_target.cmake index c3e5181762..69900512c6 100644 --- a/cmake/macros/macro_deal_ii_setup_target.cmake +++ b/cmake/macros/macro_deal_ii_setup_target.cmake @@ -95,7 +95,6 @@ MACRO(DEAL_II_SETUP_TARGET _target) ) ENDIF() - # # We can only append DEBUG link flags and compile definitions if deal.II # was built with the Debug or DebugRelease build type. So test for this: @@ -107,15 +106,56 @@ MACRO(DEAL_II_SETUP_TARGET _target) SET_PROPERTY(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES "${DEAL_II_INCLUDE_DIRS}" ) - SET_PROPERTY(TARGET ${_target} APPEND_STRING PROPERTY - COMPILE_FLAGS " ${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" - ) SET_PROPERTY(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS " ${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}}" ) - SET_PROPERTY(TARGET ${_target} APPEND PROPERTY - COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS};${DEAL_II_USER_DEFINITIONS_${_build}}" - ) + + IF(CMAKE_VERSION VERSION_LESS 3.9) + SET_PROPERTY(TARGET ${_target} APPEND_STRING PROPERTY + COMPILE_FLAGS " ${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + ) + SET_PROPERTY(TARGET ${_target} APPEND PROPERTY + COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS};${DEAL_II_USER_DEFINITIONS_${_build}}" + ) + + ELSE() + + SET(_flags "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_flags) + TARGET_COMPILE_OPTIONS(${_target} PUBLIC + $<$:${_flags}> + ) + + TARGET_COMPILE_DEFINITIONS(${_target} + PUBLIC ${DEAL_II_DEFINITIONS} ${DEAL_II_DEFINITIONS_${_build}} + ) + + IF(DEAL_II_WITH_CUDA) + # + # Add cxx compiler and cuda compilation flags to cuda source files: + # + + SET(_cuda_flags "${DEAL_II_CUDA_FLAGS} ${DEAL_II_CUDA_FLAGS_${_build}}") + SEPARATE_ARGUMENTS(_cuda_flags) + + # + # Workaround: cuda will split every compiler option with a comma + # (','), so remove all compiler flags that contain a comma: + # + STRING(REGEX REPLACE "[^ ]*,[^ ]*" "" _cxx_flags + "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}" + ) + + TARGET_COMPILE_OPTIONS(${_target} PUBLIC + $<$:-Xcompiler "${_cxx_flags}"> + $<$:${_cuda_flags}> + ) + + SET_TARGET_PROPERTIES(${_target} PROPERTIES + CUDA_SEPARABLE_COMPILATION TRUE + ) + ENDIF() + ENDIF() # # Set up the link interface: diff --git a/tests/setup_testsubproject.cmake b/tests/setup_testsubproject.cmake index e5eea1dac2..e368c7297f 100644 --- a/tests/setup_testsubproject.cmake +++ b/tests/setup_testsubproject.cmake @@ -8,6 +8,13 @@ FOREACH(_var DIFF_DIR NUMDIFF_DIR TEST_PICKUP_REGEX TEST_TIME_LIMIT) SET(${_var} "${${_var}}" CACHE STRING "" FORCE) ENDFOREACH() +IF(DEAL_II_WITH_CUDA) + PROJECT(blubb) + SET(CUDA_TOOLKIT_ROOT_DIR "${DEAL_II_CUDA_TOOLKIT_ROOT_DIR}") + FIND_PACKAGE(CUDA REQUIRED) + ENABLE_LANGUAGE(CUDA) +ENDIF() + # # A custom target that does absolutely nothing. It is used in the main # project to trigger a "make rebuild_cache" if necessary. -- 2.39.5