summaryrefslogtreecommitdiffstats
path: root/Source/cmLinkLineDeviceComputer.cxx
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2018-07-13 18:44:16 (GMT)
committerBrad King <brad.king@kitware.com>2018-07-17 14:42:57 (GMT)
commitfd0523a215c70b75d7830a18e050b79fcdf333aa (patch)
tree66ffa8a1d0c13ff91428eb166f2d611b8c30fbc0 /Source/cmLinkLineDeviceComputer.cxx
parentb07c71831c2ea42023dc27eb81e3099cefe35dd2 (diff)
downloadCMake-fd0523a215c70b75d7830a18e050b79fcdf333aa.zip
CMake-fd0523a215c70b75d7830a18e050b79fcdf333aa.tar.gz
CMake-fd0523a215c70b75d7830a18e050b79fcdf333aa.tar.bz2
CUDA: Properly de-duplicate libs when doing device linking
The nvcc device linker is designed so that each static library with device symbols only needs to be listed once as it doesn't care about link order. If you provide the same static library multiple times it will error out. To make sure this occurs we find the unique set of link items.
Diffstat (limited to 'Source/cmLinkLineDeviceComputer.cxx')
-rw-r--r--Source/cmLinkLineDeviceComputer.cxx22
1 files changed, 17 insertions, 5 deletions
diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx
index 557fa41..c9bbde1 100644
--- a/Source/cmLinkLineDeviceComputer.cxx
+++ b/Source/cmLinkLineDeviceComputer.cxx
@@ -3,7 +3,9 @@
#include "cmLinkLineDeviceComputer.h"
+#include <set>
#include <sstream>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
@@ -28,6 +30,12 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
{
// Write the library flags to the build rule.
std::ostringstream fout;
+
+ // Generate the unique set of link items when device linking.
+ // The nvcc device linker is designed so that each static library
+ // with device symbols only needs to be listed once as it doesn't
+ // care about link order.
+ std::set<std::string> emitted;
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& items = cli.GetItems();
std::string config = cli.GetConfig();
@@ -50,20 +58,24 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
}
}
+ std::string out;
if (item.IsPath) {
// nvcc understands absolute paths to libraries ending in '.a' should
// be passed to nvlink. Other extensions like '.so' or '.dylib' are
// rejected by the nvcc front-end even though nvlink knows to ignore
// them. Bypass the front-end via '-Xnvlink'.
if (!cmHasLiteralSuffix(item.Value, ".a")) {
- fout << "-Xnvlink ";
+ out += "-Xnvlink ";
}
- fout << this->ConvertToOutputFormat(
- this->ConvertToLinkReference(item.Value));
+ out +=
+ this->ConvertToOutputFormat(this->ConvertToLinkReference(item.Value));
} else {
- fout << item.Value;
+ out += item.Value;
+ }
+
+ if (emitted.insert(out).second) {
+ fout << out << " ";
}
- fout << " ";
}
if (!stdLibString.empty()) {