diff options
author | Brad King <brad.king@kitware.com> | 2017-03-07 21:21:29 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-03-10 15:19:57 (GMT) |
commit | 94255511a6d59b14159544e2489905c62dab9fca (patch) | |
tree | 585ae5293bf524dd1a5532907737cb787ecb8b35 /Source/cmVisualStudioGeneratorOptions.cxx | |
parent | 253594d0aec0cbe34694cac59ef1a8e42a532118 (diff) | |
download | CMake-94255511a6d59b14159544e2489905c62dab9fca.zip CMake-94255511a6d59b14159544e2489905c62dab9fca.tar.gz CMake-94255511a6d59b14159544e2489905c62dab9fca.tar.bz2 |
VS: Select CUDA code generation architectures
Parse the `-gencode=`, `-arch`, and `-code` flags and generate a
`CodeGeneration` field in the project file.
Diffstat (limited to 'Source/cmVisualStudioGeneratorOptions.cxx')
-rw-r--r-- | Source/cmVisualStudioGeneratorOptions.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index c79dc11..1ca6b9c 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -208,6 +208,57 @@ cmVisualStudioGeneratorOptions::GetCudaRuntime() const return CudaRuntimeStatic; } +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(); + } + + if (arch.empty() && gencode.empty()) { + return; + } + + // 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"]; + + // First entries for the -arch=<arch> [-code=<code>,...] pair. + if (!arch.empty()) { + std::string arch_name = arch[0]; + std::vector<std::string> codes; + if (!code.empty()) { + codes = cmSystemTools::tokenize(code[0], ","); + } + if (codes.empty()) { + codes.push_back(arch_name); + // nvcc -arch=<arch> has a special case that allows a real + // architecture to be specified instead of a virtual arch. + // It translates to -arch=<virtual> -code=<real>. + cmSystemTools::ReplaceString(arch_name, "sm_", "compute_"); + } + for (std::vector<std::string>::iterator ci = codes.begin(); + ci != codes.end(); ++ci) { + std::string entry = arch_name + "," + *ci; + result.push_back(entry); + } + } + + // Now add entries for the -gencode=<arch>,<code> pairs. + for (std::vector<std::string>::iterator ei = gencode.begin(); + ei != gencode.end(); ++ei) { + std::string entry = *ei; + cmSystemTools::ReplaceString(entry, "arch=", ""); + cmSystemTools::ReplaceString(entry, "code=", ""); + result.push_back(entry); + } +} + void cmVisualStudioGeneratorOptions::Parse(const char* flags) { // Parse the input string as a windows command line since the string |