Skip to content

[Offload][SYCL] Refactor OffloadKind implementation #135809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
});
auto LinkerArgs = getLinkerArgs(Input, BaseArgs);

DenseSet<OffloadKind> ActiveOffloadKinds;
uint16_t ActiveOffloadKindMask = 0u;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't need to be modified, but I guess we could if we wanted to get rid of the set. I don't think it's necessary now though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good optimization to have (16-bit mask instead of a Set). Also, it will be easier to pass the mask to callee function when introducing support for SYCL in my original PR.

Thanks

for (const auto &File : Input)
if (File.getBinary()->getOffloadKind() != OFK_None)
ActiveOffloadKinds.insert(File.getBinary()->getOffloadKind());
ActiveOffloadKindMask |= File.getBinary()->getOffloadKind();

// Write any remaining device inputs to an output file.
SmallVector<StringRef> InputFiles;
Expand All @@ -943,7 +942,10 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
return OutputOrErr.takeError();

// Store the offloading image for each linked output file.
for (OffloadKind Kind : ActiveOffloadKinds) {
for (OffloadKind Kind = OFK_OpenMP; Kind != OFK_LAST;
Kind = static_cast<OffloadKind>((uint16_t)(Kind) << 1)) {
if ((ActiveOffloadKindMask & Kind) == 0)
continue;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileOrErr =
llvm::MemoryBuffer::getFileOrSTDIN(*OutputOrErr);
if (std::error_code EC = FileOrErr.getError()) {
Expand Down
9 changes: 5 additions & 4 deletions llvm/include/llvm/Object/OffloadBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ namespace object {
/// The producer of the associated offloading image.
enum OffloadKind : uint16_t {
OFK_None = 0,
OFK_OpenMP,
OFK_Cuda,
OFK_HIP,
OFK_LAST,
OFK_OpenMP = (1 << 0),
OFK_Cuda = (1 << 1),
OFK_HIP = (1 << 2),
OFK_SYCL = (1 << 3),
OFK_LAST = (1 << 4),
};

/// The type of contents the offloading image contains.
Expand Down
Loading