MACRO(FEATURE_CUDA_FIND_EXTERNAL var)
- #
- # FIXME Restructure this call into a ./modules/FindCUDA.cmake file and
- # use DEAL_II_PACKAGE_HANDLE
- #
FIND_PACKAGE(CUDA)
- MARK_AS_ADVANCED(
- CUDA_HOST_COMPILER
- CUDA_SDK_ROOT_DIR
- CUDA_TOOLKIT_ROOT_DIR
- CUDA_USE_STATIC_CUDA_RUNTIME
- )
IF(CUDA_FOUND)
-
+ #
+ # CUDA was found, check whether we can actually use it:
+ #
SET(${var} TRUE)
- IF(DEFINED CUDA_DIR)
- SET(CUDA_TOOLKIT_ROOT_DIR "${CUDA_DIR}")
+ #
+ # CUDA support requires CMake version 3.9 or newer
+ #
+ IF(CMAKE_VERSION VERSION_LESS 3.9)
+ SET(${var} FALSE)
+ MESSAGE(STATUS "deal.II requires CMake version 3.9, or newer for CUDA support")
+ SET(CUDA_ADDITIONAL_ERROR_STRING
+ ${CUDA_ADDITIONAL_ERROR_STRING}
+ "deal.II requires CMake version 3.9, or newer for CUDA support.\n"
+ "Reconfigure with a sufficient cmake version."
+ )
ENDIF()
- MESSAGE(STATUS "Configured to use CUDA installation at ${CUDA_TOOLKIT_ROOT_DIR}")
-
- IF("${CUDA_NVCC_FLAGS}" MATCHES "-arch")
-
- # Compute Capability specified explicitly.
- # Now parse:
-
- IF("${CUDA_NVCC_FLAGS}" MATCHES "-arch[ ]*sm_([0-9]*)")
- SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}")
- ELSEIF("${CUDA_NVCC_FLAGS}" MATCHES "-arch=sm_([0-9]*)")
- SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}")
- ELSE()
- STRING(REGEX MATCH "(-arch[ ]*[^ ]*)" match "${CUDA_NVCC_FLAGS}")
- MESSAGE(STATUS "Ill-formed Compute Capability specified.")
- SET(CUDA_ADDITIONAL_ERROR_STRING
- ${CUDA_ADDITIONAL_ERROR_STRING}
- "An ill-formed Compute Capability was passed in CUDA_NVCC_FLAGS: ${match}\n"
- "deal.II requires at least Compute Capability 3.5\n"
- "which is used as default is nothing is specified."
- )
- SET(${var} FALSE)
- ENDIF()
-
-
- IF("${CUDA_COMPUTE_CAPABILITY}" LESS "35")
- MESSAGE(STATUS "Too low CUDA Compute Capability specified -- deal.II requires at least 3.5 ")
- SET(CUDA_ADDITIONAL_ERROR_STRING
- ${CUDA_ADDITIONAL_ERROR_STRING}
- "Too low CUDA Compute Capability specified: ${CUDA_COMPUTE_CAPABILITY}\n"
- "deal.II requires at least Compute Capability 3.5\n"
- "which is used as default is nothing is specified."
- )
- SET(${var} FALSE)
- ENDIF()
+
+ IF("${DEAL_II_CUDA_FLAGS}" MATCHES "-arch[ ]*sm_([0-9]*)")
+ SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}")
+ ELSEIF("${DEAL_II_CUDA_FLAGS}" MATCHES "-arch=sm_([0-9]*)")
+ SET(CUDA_COMPUTE_CAPABILITY "${CMAKE_MATCH_1}")
+ ELSE()
+ #
+ # Assume a cuda compute capability of 35
+ #
+ SET(CUDA_COMPUTE_CAPABILITY "35")
+ ADD_FLAGS(DEAL_II_CUDA_FLAGS "-arch=sm_35")
+ ENDIF()
+
+ IF("${CUDA_COMPUTE_CAPABILITY}" LESS "35")
+ MESSAGE(STATUS "Too low CUDA Compute Capability specified -- deal.II requires at least 3.5 ")
+ SET(CUDA_ADDITIONAL_ERROR_STRING
+ ${CUDA_ADDITIONAL_ERROR_STRING}
+ "Too low CUDA Compute Capability specified: ${CUDA_COMPUTE_CAPABILITY}\n"
+ "deal.II requires at least Compute Capability 3.5\n"
+ "which is used as default if nothing is specified."
+ )
+ SET(${var} FALSE)
ENDIF()
+ ENDIF()
+ENDMACRO()
- # Configuration was successful
- IF(${var})
- IF( NOT DEFINED CUDA_COMPUTE_CAPABILITY)
- # Set to use compute capability 3.5 by default
- SET(CUDA_COMPUTE_CAPABILITY "35")
- SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=sm_35)
- ENDIF()
+MACRO(FEATURE_CUDA_CONFIGURE_EXTERNAL)
- # Export further definitions
- STRING(SUBSTRING "${CUDA_COMPUTE_CAPABILITY}" 0 1 CUDA_COMPUTE_CAPABILITY_MAJOR)
- STRING(SUBSTRING "${CUDA_COMPUTE_CAPABILITY}" 1 1 CUDA_COMPUTE_CAPABILITY_MINOR)
- SET(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE FALSE)
+ ENABLE_LANGUAGE(CUDA)
- ENDIF()
- ENDIF()
+ #
+ # Set up cuda flags:
+ #
+ ADD_FLAGS(DEAL_II_CUDA_FLAGS "${DEAL_II_CXX_VERSION_FLAG}")
+ #
+ # Export definitions:
+ #
+ STRING(SUBSTRING "${CUDA_COMPUTE_CAPABILITY}" 0 1 CUDA_COMPUTE_CAPABILITY_MAJOR)
+ STRING(SUBSTRING "${CUDA_COMPUTE_CAPABILITY}" 1 1 CUDA_COMPUTE_CAPABILITY_MINOR)
ENDMACRO()
+
MACRO(FEATURE_CUDA_ERROR_MESSAGE)
MESSAGE(FATAL_ERROR "\n"
"Could not find any suitable cuda library!\n"
--- /dev/null
+## ---------------------------------------------------------------------
+##
+## Copyright (C) 2014 - 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.
+##
+## ---------------------------------------------------------------------
+
+#
+# Try to find cuda
+#
+# This module exports:
+#
+# CUDA_FOUND
+# CUDA_LIBRARIES
+# CUDA_INCLUDE_DIRS
+# CUDA_VERSION
+# CUDA_VERSION_MAJOR
+# CUDA_VERSION_MINOR
+#
+
+SET(CUDA_DIR "" CACHE PATH "An optional hint to a CUDA installation")
+SET_IF_EMPTY(CUDA_DIR "$ENV{CUDA_DIR}")
+
+IF(NOT "${CUDA_DIR}" STREQUAL "")
+ SET(CUDA_TOOLKIT_ROOT_DIR "${CUDA_DIR}")
+ENDIF()
+
+# temporarily disable ${CMAKE_SOURCE_DIR}/cmake/modules for module lookup
+LIST(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/)
+FIND_PACKAGE(CUDA)
+LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/)
+
+IF(CUDA_FOUND)
+ MESSAGE(STATUS "Configured to use CUDA installation at ${CUDA_TOOLKIT_ROOT_DIR}")
+ENDIF()
+
+SET(_cuda_libraries ${CUDA_LIBRARIES})
+SET(_cuda_include_dirs ${CUDA_INCLUDE_DIRS})
+DEAL_II_PACKAGE_HANDLE(CUDA
+ LIBRARIES REQUIRED _cuda_libraries
+ INCLUDE_DIRS REQUIRED _cuda_include_dirs
+ USER_INCLUDE_DIRS REQUIRED _cuda_include_dirs
+ CLEAR
+ CUDA_cublas_device_LIBRARY
+ CUDA_cublas_LIBRARY
+ CUDA_cudadevrt_LIBRARY
+ CUDA_cudart_static_LIBRARY
+ CUDA_cufft_LIBRARY
+ CUDA_cupti_LIBRARY
+ CUDA_curand_LIBRARY
+ CUDA_cusolver_LIBRARY
+ CUDA_cusparse_LIBRARY
+ CUDA_HOST_COMPILER
+ CUDA_nppc_LIBRARY
+ CUDA_nppi_LIBRARY
+ CUDA_npps_LIBRARY
+ CUDA_rt_LIBRARY
+ CUDA_SDK_ROOT_DIR
+ CUDA_TOOLKIT_ROOT_DIR
+ CUDA_USE_STATIC_CUDA_RUNTIME
+ )
CMAKE_Fortran_FLAGS_DEBUG
CMAKE_Fortran_FLAGS_MINSIZEREL
CMAKE_Fortran_FLAGS_RELWITHDEBINFO
+ CMAKE_CUDA_FLAGS
+ CMAKE_CUDA_FLAGS_RELEASE
+ CMAKE_CUDA_FLAGS_DEBUG
+ CMAKE_CUDA_FLAGS_MINSIZEREL
+ CMAKE_CUDA_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
#
SET(DEAL_II_USED_FLAGS
+ DEAL_II_CUDA_FLAGS
+ DEAL_II_CUDA_FLAGS_DEBUG
+ DEAL_II_CUDA_FLAGS_RELEASE
DEAL_II_CXX_FLAGS
DEAL_II_CXX_FLAGS_DEBUG
DEAL_II_CXX_FLAGS_RELEASE
# Translate CMake specific variables to deal.II naming:
#
-FOREACH(_flag CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG)
+FOREACH(_flag
+ CUDA_FLAGS CUDA_FLAGS_RELEASE CUDA_FLAGS_DEBUG
+ CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG
+ )
IF(NOT "${CMAKE_${_flag}}" STREQUAL "")
MESSAGE(STATUS
"Prepending \${CMAKE_${_flag}} to \${DEAL_II_${_flag}}"