]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add support for compiling CUDA code 2586/head
authorKarl Ljungkvist <k.ljungkvist@gmail.com>
Mon, 9 May 2016 17:37:14 +0000 (12:37 -0500)
committerKarl Ljungkvist <k.ljungkvist@gmail.com>
Tue, 10 May 2016 14:12:05 +0000 (09:12 -0500)
This adds support to the internal build system for CUDA code in .cu
files inside the library.

cmake/configure/configure_1_cuda.cmake [new file with mode: 0644]
cmake/macros/macro_deal_ii_add_library.cmake
include/deal.II/base/config.h.in
source/CMakeLists.txt

diff --git a/cmake/configure/configure_1_cuda.cmake b/cmake/configure/configure_1_cuda.cmake
new file mode 100644 (file)
index 0000000..b55c047
--- /dev/null
@@ -0,0 +1,40 @@
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2016 by the deal.II authors
+##
+## This file is part of the deal.II library.
+##
+## The deal.II library is free software; you can use it, redistribute
+## it, and/or modify it under the terms of the GNU Lesser General
+## Public License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+## The full text of the license can be found in the file LICENSE at
+## the top level of the deal.II distribution.
+##
+## ---------------------------------------------------------------------
+
+#
+# Configuration for cuda support:
+#
+
+MACRO(FEATURE_CUDA_FIND_EXTERNAL var)
+  FIND_PACKAGE(CUDA)
+
+  IF(CUDA_FOUND)
+    SET(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE FALSE)
+
+    SET(${var} TRUE)
+  ENDIF()
+
+ENDMACRO()
+
+MACRO(FEATURE_CUDA_ERROR_MESSAGE)
+  MESSAGE(FATAL_ERROR "\n"
+    "Could not find any suitable cuda library!\n"
+    ${CUDA_ADDITIONAL_ERROR_STRING}
+    "\nPlease ensure that a cuda library is installed on your computer\n"
+    )
+ENDMACRO()
+
+
+CONFIGURE_FEATURE(CUDA)
index 02f4ed9818463ae8b9eb6c17ddef48ee846ad96d..fb384c5366d1f840ddc697156e99d0cda48b543b 100644 (file)
@@ -1,6 +1,6 @@
 ## ---------------------------------------------------------------------
 ##
-## Copyright (C) 2012 - 2015 by the deal.II authors
+## Copyright (C) 2012 - 2016 by the deal.II authors
 ##
 ## This file is part of the deal.II library.
 ##
@@ -47,6 +47,28 @@ MACRO(DEAL_II_ADD_LIBRARY _library)
     SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build}
       "$<TARGET_OBJECTS:${_library}.${_build_lowercase}>"
       )
+
+    #
+    # Cuda specific target setup:
+    #
+    IF(DEAL_II_WITH_CUDA)
+      CUDA_WRAP_SRCS(${_library}.${_build_lowercase}
+        OBJ _generated_cuda_files ${ARGN} SHARED
+        )
+
+      ADD_CUSTOM_TARGET(${_library}.${_build_lowercase}_cuda
+        DEPENDS
+        ${_generated_cuda_files}
+        )
+      ADD_DEPENDENCIES(${_library}.${_build_lowercase}
+        ${_library}.${_build_lowercase}_cuda
+        )
+
+      SET_PROPERTY(GLOBAL APPEND PROPERTY DEAL_II_OBJECTS_${_build}
+        "${_generated_cuda_files}"
+        )
+    ENDIF()
+
   ENDFOREACH()
 
 ENDMACRO()
index 1f8cb03e52b5ccb17e685f76ccc6a3f47f5f326b..64405266f8a856d3a5131db64cfe1cb1560ec52b 100644 (file)
@@ -37,6 +37,7 @@
 #cmakedefine DEAL_II_WITH_64BIT_INDICES
 #cmakedefine DEAL_II_WITH_ARPACK
 #cmakedefine DEAL_II_WITH_BZIP2
+#cmakedefine DEAL_II_WITH_CUDA
 #cmakedefine DEAL_II_WITH_CXX11
 #cmakedefine DEAL_II_WITH_CXX14
 #cmakedefine DEAL_II_WITH_GSL
index b7bb5014b0757f5efc88bf0a5ca917317e046d59..ef531932b579a822f6dd4fa469245b925438bc73 100644 (file)
@@ -57,6 +57,21 @@ FOREACH(build ${DEAL_II_BUILD_TYPES})
   #
 
   GET_PROPERTY(_objects GLOBAL PROPERTY DEAL_II_OBJECTS_${build})
+
+  #
+  # FIXME: Somehow the cuda object files lose the "generated" property.
+  # This is an ugly hack
+  #
+  FOREACH(_object ${_objects})
+    IF("${_object}" MATCHES "cu.o$")
+      SET_SOURCE_FILES_PROPERTIES("${_object}"
+        PROPERTIES
+        EXTERNAL_OBJECT TRUE
+        GENERATED TRUE
+        )
+    ENDIF()
+  ENDFOREACH()
+
   ADD_LIBRARY(${DEAL_II_BASE_NAME}${DEAL_II_${build}_SUFFIX}
     dummy.cc # Workaround for a bug in the Xcode generator
     ${_objects}

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.