[Offload][SYCL] Refactor OffloadKind implementation#135809
Conversation
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
|
@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.
Good catch. I will update.
Thanks
| OFK_Cuda, | ||
| OFK_HIP, | ||
| OFK_LAST, | ||
| OFK_OpenMP = (1 << 1), |
| auto LinkerArgs = getLinkerArgs(Input, BaseArgs); | ||
|
|
||
| DenseSet<OffloadKind> ActiveOffloadKinds; | ||
| uint16_t ActiveOffloadKindMask = 0u; |
There was a problem hiding this comment.
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.
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 <arvind.sudarsanam@intel.com>
…P from 3 to 4 Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
|
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:
Thanks