[PATCH] D117777: [OpenMP] Don't pass empty files to nvlink

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 20 05:34:52 PST 2022

jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, ye-luo, lechenyu.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds and exception to the nvlink wrapper tool to not pass
empty cubin files to the nvlink job. If an empty file is passed to
nvlink it will cause an error indicating that the file could not be
opened. This would occur if the user tried to link object files that
contained offloading code with a file that didnt. This will act as a 
workaround until the new OpenMP offloading driver becomes the default.

  rG LLVM Github Monorepo



Index: clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp
--- clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp
+++ clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp
@@ -55,12 +55,22 @@
 static cl::list<std::string>
     NVArgs(cl::Sink, cl::desc("<options to be passed to nvlink>..."));
+static bool isEmptyFile(StringRef Filename) {
+  ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
+      MemoryBuffer::getFileOrSTDIN(Filename, false, false);
+  if (std::error_code EC = BufOrErr.getError())
+    return false;
+  return (*BufOrErr)->getBuffer().empty();
 static Error runNVLink(std::string NVLinkPath,
                        SmallVectorImpl<std::string> &Args) {
   std::vector<StringRef> NVLArgs;
+  StringRef Output = *(llvm::find(Args, "-o") + 1);
   for (auto &Arg : Args) {
-    NVLArgs.push_back(Arg);
+    if (!(sys::fs::exists(Arg) && Arg != Output && isEmptyFile(Arg)))
+      NVLArgs.push_back(Arg);
   if (sys::ExecuteAndWait(NVLinkPath, NVLArgs))

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117777.401608.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220120/31f4279d/attachment.bin>

More information about the cfe-commits mailing list