mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 04:09:33 -05:00
Merge topic 'cuda_architectures'
21131ca60cCUDA: Add CudaOnly.CompileFlags testf0931b0790CUDA: Convert tests to use CUDA_ARCHITECTURESe98588aabaCUDA: Add CUDA_ARCHITECTURES target property Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Patrick Stotko <stotko@cs.uni-bonn.de> Merge-request: !4568
This commit is contained in:
@@ -40,6 +40,8 @@ static std::string const kCMAKE_CXX_LINK_NO_PIE_SUPPORTED =
|
||||
"CMAKE_CXX_LINK_NO_PIE_SUPPORTED";
|
||||
static std::string const kCMAKE_CXX_LINK_PIE_SUPPORTED =
|
||||
"CMAKE_CXX_LINK_PIE_SUPPORTED";
|
||||
static std::string const kCMAKE_CUDA_ARCHITECTURES =
|
||||
"CMAKE_CUDA_ARCHITECTURES";
|
||||
static std::string const kCMAKE_CUDA_COMPILER_TARGET =
|
||||
"CMAKE_CUDA_COMPILER_TARGET";
|
||||
static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
|
||||
@@ -713,6 +715,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
||||
vars.insert(kCMAKE_C_COMPILER_TARGET);
|
||||
vars.insert(kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN);
|
||||
vars.insert(kCMAKE_CXX_COMPILER_TARGET);
|
||||
vars.insert(kCMAKE_CUDA_ARCHITECTURES);
|
||||
vars.insert(kCMAKE_CUDA_COMPILER_TARGET);
|
||||
vars.insert(kCMAKE_ENABLE_EXPORTS);
|
||||
vars.insert(kCMAKE_LINK_SEARCH_END_STATIC);
|
||||
|
||||
@@ -3085,6 +3085,95 @@ void cmGeneratorTarget::GetAppleArchs(const std::string& config,
|
||||
}
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const
|
||||
{
|
||||
struct CudaArchitecture
|
||||
{
|
||||
std::string name;
|
||||
bool real{ true };
|
||||
bool virtual_{ true };
|
||||
};
|
||||
std::vector<CudaArchitecture> architectures;
|
||||
|
||||
{
|
||||
std::vector<std::string> options;
|
||||
cmExpandList(this->GetSafeProperty("CUDA_ARCHITECTURES"), options);
|
||||
|
||||
if (options.empty()) {
|
||||
switch (this->GetPolicyStatusCMP0104()) {
|
||||
case cmPolicies::WARN:
|
||||
if (!this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile()) {
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::AUTHOR_WARNING,
|
||||
cmPolicies::GetPolicyWarning(cmPolicies::CMP0104) +
|
||||
"\nCUDA_ARCHITECTURES is empty for target \"" +
|
||||
this->GetName() + "\".");
|
||||
}
|
||||
CM_FALLTHROUGH;
|
||||
case cmPolicies::OLD:
|
||||
break;
|
||||
default:
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
"CUDA_ARCHITECTURES is empty for target \"" + this->GetName() +
|
||||
"\".");
|
||||
}
|
||||
}
|
||||
|
||||
for (std::string& option : options) {
|
||||
CudaArchitecture architecture;
|
||||
|
||||
// Architecture name is up to the first specifier.
|
||||
std::size_t pos = option.find_first_of('-');
|
||||
architecture.name = option.substr(0, pos);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
cm::string_view specifier{ option.c_str() + pos + 1,
|
||||
option.length() - pos - 1 };
|
||||
|
||||
if (specifier == "real") {
|
||||
architecture.real = true;
|
||||
architecture.virtual_ = false;
|
||||
} else if (specifier == "virtual") {
|
||||
architecture.real = false;
|
||||
architecture.virtual_ = true;
|
||||
} else {
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
"Uknown CUDA architecture specifier \"" + std::string(specifier) +
|
||||
"\".");
|
||||
}
|
||||
}
|
||||
|
||||
architectures.emplace_back(architecture);
|
||||
}
|
||||
}
|
||||
|
||||
std::string const& compiler =
|
||||
this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
|
||||
|
||||
if (compiler == "NVIDIA") {
|
||||
for (CudaArchitecture& architecture : architectures) {
|
||||
flags +=
|
||||
" --generate-code=arch=compute_" + architecture.name + ",code=[";
|
||||
|
||||
if (architecture.virtual_) {
|
||||
flags += "compute_" + architecture.name;
|
||||
|
||||
if (architecture.real) {
|
||||
flags += ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (architecture.real) {
|
||||
flags += "sm_" + architecture.name;
|
||||
}
|
||||
|
||||
flags += "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
|
||||
std::string const& var, std::string const& lang,
|
||||
|
||||
@@ -421,6 +421,8 @@ public:
|
||||
void GetAppleArchs(const std::string& config,
|
||||
std::vector<std::string>& archVec) const;
|
||||
|
||||
void AddCUDAArchitectureFlags(std::string& flags) const;
|
||||
|
||||
std::string GetFeatureSpecificLinkRuleVariable(
|
||||
std::string const& var, std::string const& lang,
|
||||
std::string const& config) const;
|
||||
|
||||
@@ -1945,6 +1945,8 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
|
||||
this->AppendFlags(flags, "-swift-version " + std::string(v));
|
||||
}
|
||||
}
|
||||
} else if (lang == "CUDA") {
|
||||
target->AddCUDAArchitectureFlags(flags);
|
||||
}
|
||||
|
||||
// Add MSVC runtime library flags. This is activated by the presence
|
||||
|
||||
+6
-1
@@ -308,6 +308,10 @@ class cmMakefile;
|
||||
3, 17, 0, cmPolicies::WARN) \
|
||||
SELECT(POLICY, CMP0103, \
|
||||
"multiple export() with same FILE without APPEND is not allowed.", \
|
||||
3, 18, 0, cmPolicies::WARN) \
|
||||
SELECT(POLICY, CMP0104, \
|
||||
"CMAKE_CUDA_ARCHITECTURES now detected for NVCC, empty " \
|
||||
"CUDA_ARCHITECTURES not allowed.", \
|
||||
3, 18, 0, cmPolicies::WARN)
|
||||
|
||||
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||
@@ -338,7 +342,8 @@ class cmMakefile;
|
||||
F(CMP0081) \
|
||||
F(CMP0083) \
|
||||
F(CMP0095) \
|
||||
F(CMP0099)
|
||||
F(CMP0099) \
|
||||
F(CMP0104)
|
||||
|
||||
/** \class cmPolicies
|
||||
* \brief Handles changes in CMake behavior and policies
|
||||
|
||||
@@ -363,6 +363,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
|
||||
initProp("CUDA_SEPARABLE_COMPILATION");
|
||||
initProp("CUDA_RESOLVE_DEVICE_SYMBOLS");
|
||||
initProp("CUDA_RUNTIME_LIBRARY");
|
||||
initProp("CUDA_ARCHITECTURES");
|
||||
initProp("LINK_SEARCH_START_STATIC");
|
||||
initProp("LINK_SEARCH_END_STATIC");
|
||||
initProp("Swift_LANGUAGE_VERSION");
|
||||
|
||||
Reference in New Issue
Block a user