This is an archive of the discontinued LLVM Phabricator instance.

[CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode
ClosedPublic

Authored by jhuber6 on Sep 19 2022, 9:01 AM.

Details

Summary

Previously when using the clang-offload-packager we did not pass the
active offloading kinds. Then in Clang when we attempted to detect when
there was host-offloading action that needed to be embedded in the host
we did not find it. This patch adds the active offloading kinds so we
know when there is input to be embedded.

Diff Detail

Event Timeline

jhuber6 created this revision.Sep 19 2022, 9:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 9:01 AM
jhuber6 requested review of this revision.Sep 19 2022, 9:01 AM
Herald added a project: Restricted Project. · View Herald Transcript
tra added inline comments.Sep 19 2022, 10:43 AM
clang/lib/Driver/Driver.cpp
4394

getActiveOffloadKinds returns a mask of offload kinds, yet we cast it to OffloadKind in DeviceDependences::add above. This mixing of OffloadKind and sets of them looks questionable to me.

If we are relying on passing sets of OffloadKindnow, then we should make it clear in the code that it is the intent, including a more detailed description that DeviceOffloadKinds is a list of OffloadKind sets, so whoever iterates over elements does not attempt to compare its elements with OffloadKind values. I think it would be helpful to change DeviceOffloadKinds element type to a new class with a helper method hasOffloadKind(OffloadKind) to avoid accidental comparison of a mask with enum value.

jhuber6 updated this revision to Diff 461286.Sep 19 2022, 11:32 AM

Mixing the concept of the mask passing via an unsigned and a single enum value was incorrect. Add a new interface that accepts a mask and adds all active values instead.

jhuber6 marked an inline comment as done.Sep 19 2022, 11:32 AM
jhuber6 added inline comments.
clang/lib/Driver/Driver.cpp
4394

Yeah I think I shouldn't mix the logic here. I updated it.

tra accepted this revision.Sep 19 2022, 11:59 AM

LGTM with a few nits.

clang/include/clang/Driver/Action.h
304

Nit: Add a*n* action

307

Nit: OffloadKindMask?

clang/lib/Driver/Action.cpp
320

It would be good to clear processed bits in Mask and then assert that it's zero after we're done. Otherwise it would be easy to miss handling a new offload kind if/when it gets added.

This revision is now accepted and ready to land.Sep 19 2022, 11:59 AM
jhuber6 marked 3 inline comments as done.Sep 19 2022, 12:02 PM
jhuber6 added inline comments.
clang/lib/Driver/Action.cpp
320

I was also considering just putting something like this next to the declarations since we already do this for the new driver as well.

constexpr OffloadKind[] DeviceOffloadingKinds = {OFK_OpenMP, OFK_Cuda, OFK_HIP};