CUDA: MSVC will now state files are cuda files when needed

The MSVC CUDA build customizations before CUDA 9 would not explicitly
add the -x cu option when building. This caused .cpp and .c files
invoked with CudaCompile to be compiled as host code and not
cuda. Now when we detect CUDA < 9 we will explicitly add this
option to correct this bug.
This commit is contained in:
Robert Maynard
2018-01-11 17:15:31 -05:00
parent 46ad721597
commit 46abfedb83
3 changed files with 13 additions and 9 deletions

View File

@@ -2646,6 +2646,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
cudaOptions.AddFlag("GPUDebugInfo", "false");
}
bool notPtx = true;
if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
} else if (this->GeneratorTarget->GetPropertyAsBool(
@@ -2654,6 +2655,16 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
// We drop the %(Extension) component as CMake expects all PTX files
// to not have the source file extension at all
cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
notPtx = false;
}
if (notPtx &&
cmSystemTools::VersionCompareGreaterEq(
"8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
// Explicitly state that we want this file to be treated as a
// CUDA file no matter what the file extensions is
// This is only needed for < CUDA 9
cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
}
// CUDA automatically passes the proper '--machine' flag to nvcc

View File

@@ -21,14 +21,8 @@ set(release_compile_defs DEFREL)
#this verifies we can pass things such as '_','(' to nvcc
add_definitions("-DPACKED_DEFINE=__attribute__((packed))")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
# CUDA MSBuild rules do not pass '-x cu' to nvcc
set(main main_for_vs.cu)
else()
set(main main.notcu)
set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
endif()
add_executable(CudaOnlyWithDefs ${main})
add_executable(CudaOnlyWithDefs main.notcu)
set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
target_compile_options(CudaOnlyWithDefs
PRIVATE

View File

@@ -1 +0,0 @@
#include "main.notcu"