diff options
author | Raul Tambre <raul@tambre.ee> | 2020-05-30 11:24:57 (GMT) |
---|---|---|
committer | Raul Tambre <raul@tambre.ee> | 2020-06-12 18:50:05 (GMT) |
commit | 0a056246a1839cbb89b72e8f1f65b583f33f794b (patch) | |
tree | ee8e73526c6f7c7bdfd637e10b6a02eb2f4addfc /Source | |
parent | 9c4397212721a2f18d31ac739d4c3ad9eebafada (diff) | |
download | CMake-0a056246a1839cbb89b72e8f1f65b583f33f794b.zip CMake-0a056246a1839cbb89b72e8f1f65b583f33f794b.tar.gz CMake-0a056246a1839cbb89b72e8f1f65b583f33f794b.tar.bz2 |
CUDA: Pass toolkit path to Clang
Clang isn't very good at finding the installed CUDA toolkit.
The upstream recommendation is that we should pass the toolkit explicitly.
Additionally:
* Avoids Clang having to search for the toolkit on every invocation.
* Allows the user to use a toolkit from a non-standard location by simply
setting CUDAToolkit_ROOT. The same way as with FindCUDAToolkit.
Clang wants the directory containing the device library and version.txt as the
toolkit path.
We thus pass the newly introduced CUDAToolkit_LIBRARY_ROOT as the toolkit path.
We save CUDAToolkit_ROOT_DIR and CUDAToolkit_LIBRARY_ROOT on Clang to have them
available in try_compile() and avoid unnecessary re-searching or a possibly
different installation being found in FindCUDAToolkit.
This however means that the selected toolkit can't be changed after the initial
language enablement.
We now determine CUDA compiler ID before doing actual detection, as we don't
want to spend time finding the CUDA toolkit for NVIDIA.
Implements #20754.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 23 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 1 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 250910a..31da69b 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -37,6 +37,7 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmOutputConverter.h" #include "cmPropertyMap.h" #include "cmRange.h" #include "cmSourceFile.h" @@ -3145,6 +3146,28 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const } } +void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const +{ + std::string const& compiler = + this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID"); + + if (compiler == "Clang") { + // Pass CUDA toolkit explicitly to Clang. + // Clang's searching for the system CUDA toolkit isn't very good and it's + // expected the user will explicitly pass the toolkit path. + // This also avoids Clang having to search for the toolkit on every + // invocation. + std::string toolkitRoot = + this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_LIBRARY_ROOT"); + + if (!toolkitRoot.empty()) { + flags += " --cuda-path=" + + this->LocalGenerator->ConvertToOutputFormat(toolkitRoot, + cmOutputConverter::SHELL); + } + } +} + //---------------------------------------------------------------------------- std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable( std::string const& var, std::string const& lang, diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index a7201dc..3aedbf5 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -426,6 +426,7 @@ public: std::vector<std::string>& archVec) const; void AddCUDAArchitectureFlags(std::string& flags) const; + void AddCUDAToolkitFlags(std::string& flags) const; std::string GetFeatureSpecificLinkRuleVariable( std::string const& var, std::string const& lang, diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index fba9cdb..f748822 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1986,6 +1986,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, } } else if (lang == "CUDA") { target->AddCUDAArchitectureFlags(flags); + target->AddCUDAToolkitFlags(flags); std::string const& compiler = this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID"); |