From 5dec403103990f766f458ff79987234e3b945787 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 27 Sep 2016 14:29:30 -0400 Subject: [PATCH] CUDA: Refactor CMakeCUDAInformation to prepare for separable compilation. --- Modules/CMakeCUDAInformation.cmake | 75 ++++++++++++++++++++++++++---- Modules/Compiler/NVIDIA-CUDA.cmake | 5 ++ 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake index 19bce6fb58..202a7a6045 100644 --- a/Modules/CMakeCUDAInformation.cmake +++ b/Modules/CMakeCUDAInformation.cmake @@ -18,6 +18,44 @@ if(CMAKE_CUDA_COMPILER_ID) include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL) endif() + +if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG) + set(CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) +endif() + +if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP) + set(CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP}) +endif() + +if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG) + set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG}) +endif() + +if(NOT DEFINED CMAKE_EXE_EXPORTS_CUDA_FLAG) + set(CMAKE_EXE_EXPORTS_CUDA_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG}) +endif() + +if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_CUDA_FLAG) + set(CMAKE_SHARED_LIBRARY_SONAME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}) +endif() + +if(NOT CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG) + set(CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG}) +endif() + +if(NOT CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG_SEP) + set(CMAKE_EXECUTABLE_RUNTIME_CUDA_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CUDA_FLAG_SEP}) +endif() + +if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CUDA_FLAG) + set(CMAKE_EXECUTABLE_RPATH_LINK_CUDA_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CUDA_FLAG}) +endif() + +if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CUDA_WITH_RUNTIME_PATH) + set(CMAKE_SHARED_LIBRARY_LINK_CUDA_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH}) +endif() + + # for most systems a module is the same as a shared library # so unless the variable CMAKE_MODULE_EXISTS is set just # copy the values from the LIBRARY variables @@ -99,12 +137,27 @@ if(NOT DEFINED CMAKE_CUDA_ARCHIVE_FINISH) set(CMAKE_CUDA_ARCHIVE_FINISH " ") endif() +#Specify how to compile when ptx has been requested +if(NOT CMAKE_CUDA_COMPILE_PTX_COMPILATION) + set(CMAKE_CUDA_COMPILE_PTX_COMPILATION + " ${CMAKE_CUDA_HOST_FLAGS} -x cu -ptx -o ") +endif() -# compile a cu file into an object file -if(NOT CMAKE_CUDA_COMPILE_OBJECT) - set(CMAKE_CUDA_COMPILE_OBJECT +#Specify how to compile when separable compilation has been requested +if(NOT CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION) + set(CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION + " ${CMAKE_CUDA_HOST_FLAGS} -x cu -dc -o ") +endif() + +#Specify how to compile when whole compilation has been requested +if(NOT CMAKE_CUDA_COMPILE_WHOLE_COMPILATION) + set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION " ${CMAKE_CUDA_HOST_FLAGS} -x cu -c -o ") +endif() +if(CMAKE_GENERATOR STREQUAL "Ninja") + set(CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION + " ${CMAKE_CUDA_HOST_FLAGS} -x cu -M -MT -o $DEP_FILE") #The Ninja generator uses the make file dependency files to determine what #files need to be recompiled. Unfortunately, nvcc doesn't support building #a source file and generating the dependencies of said file in a single @@ -112,19 +165,23 @@ if(NOT CMAKE_CUDA_COMPILE_OBJECT) # #The makefile generators uses the custom CMake dependency scanner, and thus #it is exempt from this logic. - if(CMAKE_GENERATOR STREQUAL "Ninja") - list(APPEND CMAKE_CUDA_COMPILE_OBJECT - " ${CMAKE_CUDA_HOST_FLAGS} -x cu -M -MT -o $DEP_FILE") - endif() - + list(APPEND CMAKE_CUDA_COMPILE_PTX_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}") + list(APPEND CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}") + list(APPEND CMAKE_CUDA_COMPILE_WHOLE_COMPILATION "${CMAKE_CUDA_COMPILE_DEPENDENCY_DETECTION}") endif() # compile a cu file into an executable if(NOT CMAKE_CUDA_LINK_EXECUTABLE) set(CMAKE_CUDA_LINK_EXECUTABLE - " -o ${__IMPLICT_LINKS}") + " -o ${__IMPLICT_LINKS}") endif() +#These are used when linking relocatable (dc) cuda code +set(CMAKE_CUDA_DEVICE_LINK_LIBRARY + " ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} -shared -dlink -o ") +set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE + " ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} -shared -dlink -o ") + mark_as_advanced( CMAKE_CUDA_FLAGS diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake index 6b1ac7489f..e3ff5e3ad9 100644 --- a/Modules/Compiler/NVIDIA-CUDA.cmake +++ b/Modules/Compiler/NVIDIA-CUDA.cmake @@ -10,6 +10,11 @@ set(CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS -shared) set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA -isystem=) set(CMAKE_CUDA_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=) +set(CMAKE_CUDA_FLAGS_INIT " ") +set(CMAKE_CUDA_FLAGS_DEBUG_INIT " -g") +set(CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG") +set(CMAKE_CUDA_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") +set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") set(CMAKE_CUDA98_STANDARD_COMPILE_OPTION "") set(CMAKE_CUDA98_EXTENSION_COMPILE_OPTION "")