-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
[Offload][SYCL] Refactor OffloadKind implementation #135809
Conversation
Signed-off-by: Arvind Sudarsanam <[email protected]>
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Arvind Sudarsanam (asudarsa) ChangesFollowing are the changes:
Thanks Full diff: https://github.com/llvm/llvm-project/pull/135809.diff 2 Files Affected:
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 52d922abbcaec..a76b6f1da1e1d 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -923,10 +923,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
});
auto LinkerArgs = getLinkerArgs(Input, BaseArgs);
- DenseSet<OffloadKind> ActiveOffloadKinds;
+ uint16_t ActiveOffloadKindMask = 0u;
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;
@@ -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_FIRST; 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()) {
diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index c02aec8d956ed..858c7a59bce4a 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -32,10 +32,12 @@ 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 << 1),
+ OFK_FIRST = OFK_OpenMP,
+ OFK_Cuda = (1 << 2),
+ OFK_HIP = (1 << 3),
+ OFK_SYCL = (1 << 4),
+ OFK_LAST = (1 << 5),
};
/// The type of contents the offloading image contains.
|
OFK_HIP, | ||
OFK_LAST, | ||
OFK_OpenMP = (1 << 1), | ||
OFK_FIRST = OFK_OpenMP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need first
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I will update.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c0bc689
Thanks
OFK_Cuda, | ||
OFK_HIP, | ||
OFK_LAST, | ||
OFK_OpenMP = (1 << 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is 2, not 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c0bc689
Thanks
@@ -923,10 +923,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles( | |||
}); | |||
auto LinkerArgs = getLinkerArgs(Input, BaseArgs); | |||
|
|||
DenseSet<OffloadKind> ActiveOffloadKinds; | |||
uint16_t ActiveOffloadKindMask = 0u; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Signed-off-by: Arvind Sudarsanam <[email protected]>
…P from 3 to 4 Signed-off-by: Arvind Sudarsanam <[email protected]>
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/16286 Here is the relevant piece of the build log for the reference
|
AddressSanitizer test is passing in subsequent runs. Mostly a flaky issue. Thanks |
Following are the changes: 1. Make OffloadKind enum values to be powers of two so we can use them like a bitfield 2. Include OFK_SYCL enum value 3. Modify ActiveOffloadKinds support in clang-linker-wrapper to use bitfields instead of a vector. Thanks --------- Signed-off-by: Arvind Sudarsanam <[email protected]>
Following are the changes:
Thanks