From 6ebff6ebf8850a9372786bf56af8ee79dca6860d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 11 Sep 2023 15:54:53 -0400 Subject: [PATCH 8/9] VS: Avoid unnecessary CUDA device linking for OBJECT libraries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without `CudaLink` fields, MSBuild tries to perform a device link step for object libraries with CUDA_SEPARABLE_COMPILATION on them even when not needed. This commonly was encountered when generating PTX or OPTIX-IR output. Signed-off-by: Björn Esser --- Source/cmVisualStudio10TargetGenerator.cxx | 5 ++++- Tests/CudaOnly/Fatbin/CMakeLists.txt | 1 + Tests/CudaOnly/OptixIR/CMakeLists.txt | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index b3699ae739..b011615097 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3855,7 +3855,10 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions( Elem& e1, std::string const& configName) { - if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) { + // We need to write link options for OBJECT libraries so that + // we override the default device link behavior ( enabled ) when + // building object libraries with ptx/optix-ir/etc + if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) { return; } diff --git a/Tests/CudaOnly/Fatbin/CMakeLists.txt b/Tests/CudaOnly/Fatbin/CMakeLists.txt index db0dc227e0..99744044c1 100644 --- a/Tests/CudaOnly/Fatbin/CMakeLists.txt +++ b/Tests/CudaOnly/Fatbin/CMakeLists.txt @@ -10,6 +10,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../CUBIN/kernelB.cu ${CMAKE_CURRENT_SOURCE_DIR}/../CUBIN/kernelC.cu) set_property(TARGET CudaFATBIN PROPERTY CUDA_FATBIN_COMPILATION ON) +set_property(TARGET CudaFATBIN PROPERTY CUDA_SEPARABLE_COMPILATION ON) # Will use `cuModuleLoadFatBinary` to load the fatbinaries add_executable(CudaOnlyFatbin main.cu) diff --git a/Tests/CudaOnly/OptixIR/CMakeLists.txt b/Tests/CudaOnly/OptixIR/CMakeLists.txt index afeabdade7..f408d40325 100644 --- a/Tests/CudaOnly/OptixIR/CMakeLists.txt +++ b/Tests/CudaOnly/OptixIR/CMakeLists.txt @@ -13,6 +13,7 @@ if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.7.0") set_property(TARGET CudaOptix PROPERTY CUDA_OPTIX_COMPILATION ON) endif() +set_property(TARGET CudaOptix PROPERTY CUDA_SEPARABLE_COMPILATION ON) set_property(TARGET CudaOptix PROPERTY CUDA_ARCHITECTURES native) add_executable(CudaOnlyOptixIR main.cu) -- 2.41.0