This is an archive of the discontinued LLVM Phabricator instance.

[Clang][OpenMP] Fix the issue that temp cubin files are not removed after compilation when using new OpenMP driver
ClosedPublic

Authored by tianshilei1992 on Apr 22 2022, 5:42 AM.

Details

Summary

The root cause of this is, in NVPTX::Assembler::ConstructJob, the output file name might not match the Output's file name passed into the function because CudaToolChain::getInputFilename is a specialized version. That means the real output file is not added to the temp files list, which will be all removed in the d'tor of Compilation. In order to "fix" it, in the function NVPTX::OpenMPLinker::ConstructJob, before calling clang-nvlink-wrapper, the function calls getToolChain().getInputFilename(II) to get the right output file name for each input, and add it to temp file, and then they can be removed w/o any issue. However, this whole logic doesn't work when using the new OpenMP driver because NVPTX::OpenMPLinker::ConstructJob is not called at all, which causing the issue that the cubin file generated in each single unit compilation is out of track.

In this patch, we add the real output file into temp files if its name doesn't match Output. We add it when the file is an output instead of doing it when it is an input, like what we did in NVPTX::OpenMPLinker::ConstructJob, which makes more sense.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Apr 22 2022, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 5:42 AM
tianshilei1992 requested review of this revision.Apr 22 2022, 5:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 5:42 AM

Is this really the cause? nvptx::assemble should call createOutputFile which makes a temp file to output to that is added to TempFiles.

tianshilei1992 added a comment.EditedApr 22 2022, 5:50 AM

Is this really the cause? nvptx::assemble should call createOutputFile which makes a temp file to output to that is added to TempFiles.

Hmm, that's interesting. After adding that line, the temp file gets removed. Let me check that function.

tianshilei1992 planned changes to this revision.Apr 22 2022, 6:14 AM

The issue is in clang/lib/Driver/ToolChains/Cuda.cpp.

tianshilei1992 retitled this revision from [Clang][OpenMP] Fix the issue that one temp cubin file is not removed after compilation to [Clang][OpenMP] Fix the issue that temp cubin files are not removed after compilation when using new OpenMP driver.Apr 22 2022, 1:17 PM
tianshilei1992 edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Apr 22 2022, 1:51 PM