From e3983168dace026301b6b398691ffb66b6c816e4 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 16 Jun 2022 08:13:57 -0400 Subject: CUDA: MSVC pass all cuda gencode flags via AdditionalOptions Fixes #23491 --- Source/cmVisualStudio10TargetGenerator.cxx | 25 ++++--- Source/cmVisualStudioGeneratorOptions.cxx | 71 ++---------------- Templates/MSBuild/FlagTables/v10_Cuda.json | 112 ----------------------------- 3 files changed, 22 insertions(+), 186 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c79331c..8e1c06e 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3852,21 +3852,28 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( this->GeneratorTarget->GetLinkOptions(linkOpts, configName, "CUDA"); // LINK_OPTIONS are escaped. this->LocalGenerator->AppendCompileOptions(linkFlags, linkOpts); + + cmComputeLinkInformation* pcli = + this->GeneratorTarget->GetLinkInformation(configName); + if (doDeviceLinking && pcli) { + + cmLinkLineDeviceComputer computer( + this->LocalGenerator, + this->LocalGenerator->GetStateSnapshot().GetDirectory()); + std::string ignored_; + this->LocalGenerator->GetDeviceLinkFlags(computer, configName, ignored_, + linkFlags, ignored_, ignored_, + this->GeneratorTarget); + + this->LocalGenerator->AddLanguageFlagsForLinking( + linkFlags, this->GeneratorTarget, "CUDA", configName); + } cudaLinkOptions.AppendFlagString("AdditionalOptions", linkFlags); // For static libraries that have device linking enabled compute // the libraries if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY && doDeviceLinking) { - cmComputeLinkInformation* pcli = - this->GeneratorTarget->GetLinkInformation(configName); - if (!pcli) { - cmSystemTools::Error( - "CMake can not compute cmComputeLinkInformation for target: " + - this->Name); - return false; - } - cmComputeLinkInformation& cli = *pcli; cmLinkLineDeviceComputer computer( this->LocalGenerator, diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 00c65ed..16584f5 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -161,71 +161,12 @@ bool cmVisualStudioGeneratorOptions::UsingSBCS() const void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration() { - // Extract temporary values stored by our flag table. - FlagValue arch = this->TakeFlag("cmake-temp-arch"); - FlagValue code = this->TakeFlag("cmake-temp-code"); - FlagValue gencode = this->TakeFlag("cmake-temp-gencode"); - - // No -code allowed without -arch. - if (arch.empty()) { - code.clear(); - } - - // Create a CodeGeneration field with [arch],[code] syntax in each entry. - // CUDA will convert it to `-gencode=arch=[arch],code="[code],[arch]"`. - FlagValue& result = this->FlagMap["CodeGeneration"]; - - // If there are no flags, leave the CodeGeneration field empty. - if (arch.empty() && gencode.empty()) { - return; - } - - // First entries for the -arch= [-code=,...] pair. - if (!arch.empty()) { - std::string arch_name = arch[0]; - if (arch_name == "all" || arch_name == "all-major" || - arch_name == "native") { - AppendFlagString("AdditionalOptions", "-arch=" + arch_name); - return; - } - std::vector codes; - if (!code.empty()) { - codes = cmTokenize(code[0], ","); - } - if (codes.empty()) { - codes.push_back(arch_name); - // nvcc -arch= has a special case that allows a real - // architecture to be specified instead of a virtual arch. - // It translates to -arch= -code=. - cmSystemTools::ReplaceString(arch_name, "sm_", "compute_"); - } - for (std::string const& c : codes) { - std::string entry = arch_name + "," + c; - result.push_back(entry); - } - } - - // Now add entries for the following signatures: - // -gencode=, - // -gencode=,[,] - // -gencode=,"," - for (std::string const& e : gencode) { - std::string entry = e; - cmSystemTools::ReplaceString(entry, "arch=", ""); - cmSystemTools::ReplaceString(entry, "code=", ""); - cmSystemTools::ReplaceString(entry, "[", ""); - cmSystemTools::ReplaceString(entry, "]", ""); - cmSystemTools::ReplaceString(entry, "\"", ""); - - std::vector codes = cmTokenize(entry, ","); - if (codes.size() >= 2) { - auto gencode_arch = cm::cbegin(codes); - for (auto ci = gencode_arch + 1; ci != cm::cend(codes); ++ci) { - std::string code_entry = *gencode_arch + "," + *ci; - result.push_back(code_entry); - } - } - } + // Create an empty CodeGeneration field, and pass the the actual + // compile flags via additional options so that we have consistent + // behavior and avoid issues with MSBuild extensions injecting + // virtual code when we request real only. + FlagValue& code_gen_flag = this->FlagMap["CodeGeneration"]; + code_gen_flag = ""; } void cmVisualStudioGeneratorOptions::FixManifestUACFlags() diff --git a/Templates/MSBuild/FlagTables/v10_Cuda.json b/Templates/MSBuild/FlagTables/v10_Cuda.json index b3230ac..b0765f5 100644 --- a/Templates/MSBuild/FlagTables/v10_Cuda.json +++ b/Templates/MSBuild/FlagTables/v10_Cuda.json @@ -70,118 +70,6 @@ ] }, { - "name": "cmake-temp-gencode", - "switch": "gencode=", - "comment": "", - "value": "", - "flags": [ - "UserValue", - "SemicolonAppendable" - ] - }, - { - "name": "cmake-temp-gencode", - "switch": "gencode", - "comment": "", - "value": "", - "flags": [ - "UserFollowing", - "SemicolonAppendable" - ] - }, - { - "name": "cmake-temp-gencode", - "switch": "-generate-code=", - "comment": "", - "value": "", - "flags": [ - "UserValue", - "SemicolonAppendable" - ] - }, - { - "name": "cmake-temp-gencode", - "switch": "-generate-code", - "comment": "", - "value": "", - "flags": [ - "UserFollowing", - "SemicolonAppendable" - ] - }, - { - "name": "cmake-temp-code", - "switch": "code=", - "comment": "", - "value": "", - "flags": [ - "UserValue" - ] - }, - { - "name": "cmake-temp-code", - "switch": "code", - "comment": "", - "value": "", - "flags": [ - "UserFollowing" - ] - }, - { - "name": "cmake-temp-code", - "switch": "-gpu-code=", - "comment": "", - "value": "", - "flags": [ - "UserValue" - ] - }, - { - "name": "cmake-temp-code", - "switch": "-gpu-code", - "comment": "", - "value": "", - "flags": [ - "UserFollowing" - ] - }, - { - "name": "cmake-temp-arch", - "switch": "arch=", - "comment": "", - "value": "", - "flags": [ - "UserValue" - ] - }, - { - "name": "cmake-temp-arch", - "switch": "arch", - "comment": "", - "value": "", - "flags": [ - "UserFollowing" - ] - }, - { - "name": "cmake-temp-arch", - "switch": "-gpu-architecture=", - "comment": "", - "value": "", - "flags": [ - "UserValue" - ] - }, - { - "name": "cmake-temp-arch", - "switch": "-gpu-architecture", - "comment": "", - "value": "", - "flags": [ - "UserFollowing" - ] - }, - { "name": "FastMath", "switch": "use_fast_math", "comment": "", -- cgit v0.12