Skip to content

Commit

Permalink
[nvlink-wrapper] Use a symbolic link instead of copying the file (llv…
Browse files Browse the repository at this point in the history
…m#110139)

Summary:
We need all inputs to `nvlink` to end in `.cubin` while the rest of the
compiler toolchain wants `.o`. Previously we copied `.o` file to
`.cubin` files, but this is wasteful. Instead, we can just create a link
against it. This saves some disk space during link time.
  • Loading branch information
jhuber6 authored Sep 27, 2024
1 parent f6a756f commit 44950de
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,11 @@ Expected<SmallVector<StringRef>> getInput(const ArgList &Args) {
}
}

// Copy all of the input files to a new file ending in `.cubin`. The 'nvlink'
// Create a link for each file to a new file ending in `.cubin`. The 'nvlink'
// linker requires all NVPTX inputs to have this extension for some reason.
// Windows cannot create symbolic links so we just copy the whole file.
for (auto &Input : LinkerInput) {
#ifdef _WIN32
auto TempFileOrErr = createTempFile(
Args, sys::path::stem(Input->getBufferIdentifier()), "cubin");
if (!TempFileOrErr)
Expand All @@ -671,6 +673,18 @@ Expected<SmallVector<StringRef>> getInput(const ArgList &Args) {
if (Error E = Output->commit())
return E;
Files.emplace_back(Args.MakeArgString(*TempFileOrErr));
#else
SmallString<128> TempFile;
if (std::error_code EC = sys::fs::getPotentiallyUniqueTempFileName(
sys::path::stem(Input->getBufferIdentifier()), "cubin", TempFile))
reportError(createFileError(TempFile, EC));
if (std::error_code EC =
sys::fs::create_link(Input->getBufferIdentifier(), TempFile)) {
reportError(createFileError(TempFile, EC));
}
Files.emplace_back(Args.MakeArgString(TempFile));
TempFiles.emplace_back(std::move(TempFile));
#endif
}

return Files;
Expand Down

0 comments on commit 44950de

Please sign in to comment.