From a233e4e7d9c157cae0098762d8a7add463fb3492 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Aug 2019 15:04:59 -0400 Subject: [PATCH] CUDA: Compilers can now state they don't require a device linking step --- Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst | 14 +++++++++----- Modules/CMakeCUDAInformation.cmake | 3 ++- Modules/Compiler/NVIDIA-CUDA.cmake | 1 + Source/cmLinkLineDeviceComputer.cxx | 5 +++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst b/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst index ef74ae26f0..dae960fbeb 100644 --- a/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst +++ b/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst @@ -1,12 +1,16 @@ CUDA_RESOLVE_DEVICE_SYMBOLS --------------------------- -CUDA only: Enables device linking for the specific library target +CUDA only: Enables device linking for the specific library target where +required. -If set this will enable device linking on the library target. Normally -device linking is deferred until a shared library or executable is generated, -allowing for multiple static libraries to resolve device symbols at the same -time when they are used by a shared library or executable. +If set, this will tell the required compilers to enable device linking +on the library target. Device linking is an additional link step +required by some CUDA compilers when :prop_tgt:`CUDA_SEPARABLE_COMPILATION` is +enabled. Normally device linking is deferred until a shared library or +executable is generated, allowing for multiple static libraries to resolve +device symbols at the same time when they are used by a shared library or +executable. By default static library targets have this property is disabled, while shared, module, and executable targets have this property enabled. diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 43ae989e08..b0d80d161c 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -171,7 +171,8 @@ if(NOT CMAKE_CUDA_LINK_EXECUTABLE) " -o ${__IMPLICT_LINKS}") endif() -if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0") +if( CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND + CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0") set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "-Wno-deprecated-gpu-targets") else() set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "") diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index c0ccb71474..b59deda172 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -1,3 +1,4 @@ +set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE True) set(CMAKE_CUDA_VERBOSE_FLAG "-v") set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v") diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index 656907aaa1..7cacb24ed3 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -13,6 +13,7 @@ #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" +#include "cmMakefile.h" #include "cmStateDirectory.h" #include "cmStateSnapshot.h" #include "cmStateTypes.h" @@ -156,6 +157,10 @@ bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg, return false; } + if (!lg.GetMakefile()->IsOn("CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE")) { + return false; + } + if (const char* resolveDeviceSymbols = target.GetProperty("CUDA_RESOLVE_DEVICE_SYMBOLS")) { // If CUDA_RESOLVE_DEVICE_SYMBOLS has been explicitly set we need