]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Update internal CUDA setup, remove obsolete code
authorMatthias Maier <tamiko@43-1.org>
Mon, 14 Aug 2017 22:39:26 +0000 (17:39 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 15 Aug 2017 06:28:32 +0000 (01:28 -0500)
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
cmake/macros/macro_deal_ii_add_library.cmake
cmake/macros/macro_deal_ii_add_test.cmake
cmake/macros/macro_deal_ii_insource_setup_target.cmake
cmake/macros/macro_deal_ii_setup_target.cmake
tests/setup_testsubproject.cmake

index 45a02046ca1207a26c67d6c879c18649034bdfe1..07c4c34d27197430a6ae7cc6601dab5693127ca0 100644 (file)
@@ -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
 #
index 3c4962560a72d3adefe59f2f18cd94c0036b34ca..b9b9bee1d0412cd7ad1390802108e75e23ae1b10 100644 (file)
 
 #
 # 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}
-      "$<TARGET_OBJECTS:${_library}_${_build_lowercase}>"
-      )
+    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
+        $<$<COMPILE_LANGUAGE:CXX>:${_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
+          $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler "${_cxx_flags}">
+          $<$<COMPILE_LANGUAGE:CUDA>:${_cuda_flags}>
+          )
+
+        SET_TARGET_PROPERTIES(${_library}_${_build_lowercase} PROPERTIES
+          CUDA_SEPARABLE_COMPILATION TRUE
+          )
+      ENDIF()
+
     ENDIF()
 
+    SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build}
+      "$<TARGET_OBJECTS:${_library}_${_build_lowercase}>"
+      )
   ENDFOREACH()
 
 ENDMACRO()
index 2036b2d9d4cff40377bc73559751c432ab577151..5dbb375df69d85c04993aa6d5f7721627a430843 100644 (file)
@@ -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}
index f8141955a495950c4f139f49428303d632e77bc7..524e5d709b2046cb029ab53a4105a5174e3881b9 100644 (file)
@@ -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
+      $<$<COMPILE_LANGUAGE:CXX>:${_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
+        $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler "${_cxx_flags}">
+        $<$<COMPILE_LANGUAGE:CUDA>:${_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}
index c3e5181762337d1fbd6366baaf2ad0f42485ea93..69900512c64148154ea48587db3135e486021e25 100644 (file)
@@ -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
+      $<$<COMPILE_LANGUAGE:CXX>:${_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
+        $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler "${_cxx_flags}">
+        $<$<COMPILE_LANGUAGE:CUDA>:${_cuda_flags}>
+        )
+
+      SET_TARGET_PROPERTIES(${_target} PROPERTIES
+        CUDA_SEPARABLE_COMPILATION TRUE
+        )
+    ENDIF()
+  ENDIF()
 
   #
   # Set up the link interface:
index e5eea1dac26280bb7919b773e7febc8f86a88706..e368c7297f28a6596aa7dd4f61d0af0c032dd375 100644 (file)
@@ -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.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.