This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP]Fix PR50336: Remove temporary files in the offload bundler tool
ClosedPublic

Authored by jhuber6 on Aug 6 2021, 2:23 PM.

Details

Summary

Temporary files created by the offloading device toolchain are not removed
after compilation when using a two-step compilation. The offload-bundler uses a
different filename for the device binary than the .o file present in the
Job's input list. This is not listed as a temporary file so it is never
removed. This patch explicitly adds the device binary as a temporary file to
consume it. This fixes PR50336.

Diff Detail

Event Timeline

jhuber6 created this revision.Aug 6 2021, 2:23 PM
jhuber6 requested review of this revision.Aug 6 2021, 2:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 2:23 PM

Why the else?

Why the else?

If this input isn't an OffloadingAction then it is a .o file which we already list as a temporary file. If it was an OffloadingAction then we have an extra device-specific filename like .cubin that we don't automatically list as a temporary file.

This revision is now accepted and ready to land.Aug 10 2021, 9:10 PM

This may break -save-temps since the input to clang-offload-bundler may not be temporary files when -save-temps is enabled.

I think clang-offload-bundler is not the right place to decide whether a file is a temporary file. Whether a file is a temporary file should be determined at its point of creation and if it is a temporary file it should be addTempFile there, instead of guessing that later.

This may break -save-temps since the input to clang-offload-bundler may not be temporary files when -save-temps is enabled.

I think clang-offload-bundler is not the right place to decide whether a file is a temporary file. Whether a file is a temporary file should be determined at its point of creation and if it is a temporary file it should be addTempFile there, instead of guessing that later.

The .cubin files are still present when I tested it with save-temps. We already do something similar in the OpenMPLinker job for the Cuda driver, which is why these files were removed for straight compilation but kept when using the offload bundler when compiling with -c.

Any rational for not calling addTempFile during the binding rather than the call setup ? I had a brief look there and it seems to me this is the root of the problem.

I got bitten by this patch in a downstream project where some of the files in the offload action are actual inputs and so got deleted.

Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2022, 2:09 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

Any rational for not calling addTempFile during the binding rather than the call setup ? I had a brief look there and it seems to me this is the root of the problem.

I got bitten by this patch in a downstream project where some of the files in the offload action are actual inputs and so got deleted.

Sorry to hear that. If I recall the main problem was that the bindings always use the .o suffix while CUDA requires the .cubin suffix to work. There was a similar hack somewhere else so I just copied it here and didn't think too much about it. If you have a solution that solves your problem I could take a look at it. However, we're moving away from this tool anyway, upstream it's no longer used for OpenMP offloading and I'm currently working on making that true for HIP as well.

Thanks for your answer, make sense.

If we are moving away I won't bother looking fixing my issue upstream as it is very niche (I don't think you can trigger this with the upstream clang driver).