Commit 81e8f627 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Stage topic 'cuda-default-runtime'

Topic-id: 4762
Topic-url: !4762
parents b85ec268 c924ae76
......@@ -135,6 +135,7 @@ If set, the following variables are passed in to the generated
try_compile CMakeLists.txt to initialize compile target properties with
default values:
* :variable:`CMAKE_CUDA_RUNTIME_LIBRARY`
* :variable:`CMAKE_ENABLE_EXPORTS`
* :variable:`CMAKE_LINK_SEARCH_START_STATIC`
* :variable:`CMAKE_LINK_SEARCH_END_STATIC`
......
......@@ -10,8 +10,8 @@ The allowed case insensitive values are:
Contents of ``CUDA_RUNTIME_LIBRARY`` may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
If this property is not set then CMake uses the default value
``Static`` to select the CUDA runtime library.
If that property is not set then CMake uses an appropriate default
value based on the compiler to select the CUDA runtime library.
.. note::
......
CMAKE_CUDA_RUNTIME_LIBRARY
--------------------------
Select the CUDA runtime library for use by compilers targeting the MSVC ABI.
Select the CUDA runtime library for use when compiling and linking CUDA.
This variable is used to initialize the :prop_tgt:`CUDA_RUNTIME_LIBRARY`
property on all targets as they are created.
......@@ -14,7 +14,8 @@ Contents of ``CMAKE_CUDA_RUNTIME_LIBRARY`` may use
If this variable is not set then the :prop_tgt:`CUDA_RUNTIME_LIBRARY` target
property will not be set automatically. If that property is not set then
CMake uses the default value ``Static`` to select the CUDA runtime library.
CMake uses an appropriate default value based on the compiler to select the
CUDA runtime library.
.. note::
......
......@@ -54,6 +54,8 @@ set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "@CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES@")
set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES@")
set(CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
@_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT@
set(CMAKE_LINKER "@CMAKE_LINKER@")
set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_MT "@CMAKE_MT@")
......@@ -67,6 +67,39 @@ else()
set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES}")
endif()
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
# Detect CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT from the compiler by looking at which
# cudart library exists in the implicit link libraries passed to the host linker.
# This is required when a project sets the cuda runtime library as part of the
# initial flags.
list(FIND CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES cudart_static __cuda_rt_loc)
if(NOT __cuda_rt_loc EQUAL -1)
set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
else()
list(FIND CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES cudart __cuda_rt_loc)
if(NOT __cuda_rt_loc EQUAL -1)
set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED")
else()
set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "NONE")
endif()
endif()
unset(__cuda_rt_loc)
set(_SET_CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT
"set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT \"${CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT}\")")
# Remove the CUDA Toolkit include directories from the set of
# implicit system include directories.
# This resolves the issue that NVCC doesn't specify these
# includes as SYSTEM includes when compiling device code, and sometimes
# they contain headers that generate warnings, so let users mark them
# as SYSTEM explicitly
if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)
list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
)
endif()
endif()
# Remove the following libraries from CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES and
# CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES
#
......@@ -83,20 +116,6 @@ else()
list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES cudart cudart_static cudadevrt rt pthread dl)
list(REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES cudart cudart_static cudadevrt rt pthread dl)
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
# Remove the CUDA Toolkit include directories from the set of
# implicit system include directories.
# This resolves the issue that NVCC doesn't specify these
# includes as SYSTEM includes when compiling device code, and sometimes
# they contain headers that generate warnings, so let users mark them
# as SYSTEM explicitly
if(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)
list(REMOVE_ITEM CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
)
endif()
endif()
# Re-configure to save learned information.
configure_file(
${CMAKE_ROOT}/Modules/CMakeCUDACompiler.cmake.in
......
......@@ -59,7 +59,6 @@ set(CMAKE_CUDA_DEVICE_COMPILER_WRAPPER_FLAG_SEP ",")
set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG "-Xlinker=")
set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG_SEP ",")
set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "cudadevrt;cudart_static")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "cudadevrt;cudart")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_NONE "")
......
......@@ -69,7 +69,6 @@ else()
endif()
unset(_cmp0092)
set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "cudadevrt;cudart_static")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "cudadevrt;cudart")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_NONE "")
......
......@@ -44,6 +44,8 @@ static std::string const kCMAKE_CUDA_ARCHITECTURES =
"CMAKE_CUDA_ARCHITECTURES";
static std::string const kCMAKE_CUDA_COMPILER_TARGET =
"CMAKE_CUDA_COMPILER_TARGET";
static std::string const kCMAKE_CUDA_RUNTIME_LIBRARY =
"CMAKE_CUDA_RUNTIME_LIBRARY";
static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
static std::string const kCMAKE_LINK_SEARCH_END_STATIC =
"CMAKE_LINK_SEARCH_END_STATIC";
......@@ -717,6 +719,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
vars.insert(kCMAKE_CXX_COMPILER_TARGET);
vars.insert(kCMAKE_CUDA_ARCHITECTURES);
vars.insert(kCMAKE_CUDA_COMPILER_TARGET);
vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY);
vars.insert(kCMAKE_ENABLE_EXPORTS);
vars.insert(kCMAKE_LINK_SEARCH_END_STATIC);
vars.insert(kCMAKE_LINK_SEARCH_START_STATIC);
......
......@@ -9,6 +9,8 @@ ADD_TEST_MACRO(CudaOnly.Toolkit CudaOnlyToolkit)
ADD_TEST_MACRO(CudaOnly.WithDefs CudaOnlyWithDefs)
if(CMake_TEST_CUDA AND NOT CMake_TEST_CUDA STREQUAL "Clang")
ADD_TEST_MACRO(CudaOnly.SharedRuntimeViaCUDAFlags CudaOnlySharedRuntimeViaCUDAFlags)
# Separable compilation is currently only supported on NVCC. Disable tests
# using it for other compilers.
ADD_TEST_MACRO(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine)
......
cmake_minimum_required(VERSION 3.17)
project(SharedRuntimeViaCUDAFlags NONE)
set(CMAKE_CUDA_FLAGS "")
string(APPEND CMAKE_CUDA_FLAGS "-cudart shared")
enable_language(CUDA)
add_executable(CudaOnlySharedRuntimeViaCUDAFlags main.cu)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment