Skip to content

Commit

Permalink
[CUDA] Fix output from ptxas being removes as a temporary file
Browse files Browse the repository at this point in the history
Summary:
The logic here is to add the `.cubin` temporary file if we had to create
a new filename to handle it. Unfortuantely the logic was wrong because
we compare `const char *` values here. This logic seems to have been
wrong for some time, but was never noticed since we never used the
relocatable output.
  • Loading branch information
jhuber6 authored and tstellar committed Feb 8, 2023
1 parent c4392bc commit aa2bbfa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("--gpu-name");
CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
CmdArgs.push_back("--output-file");
const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
std::string OutputFileName = TC.getInputFilename(Output);

// If we are invoking `nvlink` internally we need to output a `.cubin` file.
// Checking if the output is a temporary is the cleanest way to determine
Expand All @@ -455,12 +455,12 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
C.getTempFiles().end()) {
SmallString<256> Filename(Output.getFilename());
llvm::sys::path::replace_extension(Filename, "cubin");
OutputFileName = Args.MakeArgString(Filename);
OutputFileName = Filename.str();
}
if (Output.isFilename() && OutputFileName != Output.getFilename())
C.addTempFile(OutputFileName);
C.addTempFile(Args.MakeArgString(OutputFileName));

CmdArgs.push_back(OutputFileName);
CmdArgs.push_back(Args.MakeArgString(OutputFileName));
for (const auto &II : Inputs)
CmdArgs.push_back(Args.MakeArgString(II.getFilename()));

Expand Down

0 comments on commit aa2bbfa

Please sign in to comment.