Prevent Cmake error for CUDA with incompatible c++.

At least on Debian 10 the standard c++ compiler is g++-8,
but CUDA only supports g++-7 and our test for CUDA in cmake
did send an error in that case/combination which is quite
annoying.

The reason was that check_language(CUDA) did not honor
the CMAKE_CUDA_FLAGS variable and always used the default g++7,
but enable_language(CUDA) did honor it. As we do set the underlying
host compiler the fromer reported that CUDA is available while the
latter marked the CUDA compiler as broken.

With this commit we work around this by setting the environment
variable ENV{CUDAHOSTCXX} which nvcc will use. Hence now we only try
to enable CUDA if it is compatible with the C++ compiler
This commit is contained in:
Markus Blatt 2020-04-27 14:54:08 +02:00
parent a7a3aec72d
commit ddb0940336

View File

@ -95,7 +95,15 @@ if(NOT CMAKE_DISABLE_FIND_PACKAGE_CUDA AND
CMAKE_VERSION VERSION_GREATER 3.7.9)
if(NOT DEFINED ENV{CUDAHOSTCXX} AND
(NOT CMAKE_CUDA_FLAGS OR NOT CMAKE_CUDA_FLAGS MATCHES ".*-ccbin .*"))
message(STATUS "Setting CUDA host compiler to ${CMAKE_CXX_COMPILER} to "
"prevent incompatibilities. Note that this might report that there "
"is not CUDA compiler if your system's CUDA compiler does not support "
"${CMAKE_CXX_COMPILER}.")
set(CMAKE_CUDA_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} ${CMAKE_CUDA_FLAGS}")
# check_language does not seem to care about ${CMAKE_CUDA_FLAGS}, we
# need to set the environment variable CUDAHOSTCXX such that cuda
# picks up the correct compiler.
set(ENV{CUDAHOSTCXX} ${CMAKE_CXX_COMPILER})
endif()
include(CheckLanguage)
# Unfortunately check_language(CUDA) will only check whether there is
@ -105,12 +113,12 @@ if(NOT CMAKE_DISABLE_FIND_PACKAGE_CUDA AND
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA OPTIONAL)
# While the documentation says that it is deprecated, FindCUDA seems the
# only easy way to determine the cublas and cusparse libraries.
# Hence we call it unconditionally
# The WellContributions kernel uses __shfl_down_sync, which was introduced in CUDA 9.0
find_package(CUDA)
endif()
# While the documentation says that it is deprecated, FindCUDA seems the
# only easy way to determine the cublas and cusparse libraries.
# Hence we call it unconditionally
# The WellContributions kernel uses __shfl_down_sync, which was introduced in CUDA 9.0
find_package(CUDA)
if(CUDA_FOUND AND CUDA_VERSION VERSION_LESS "9.0")
set(CUDA_FOUND OFF)
message(WARNING "Deactivating CUDA as we require version 9.0 or newer."