-
Notifications
You must be signed in to change notification settings - Fork 752
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
[SYCL][Offload] Add SYCLBIN format and dump tool #16873
base: sycl
Are you sure you want to change the base?
Changes from 7 commits
1b9f3a1
43c6227
86e3128
1685f0f
a024f11
716bdab
d07b06c
b598b66
a4324ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ enum ImageKind : uint16_t { | |
IMG_Cubin, | ||
IMG_Fatbinary, | ||
IMG_PTX, | ||
IMG_SYCLBIN, | ||
IMG_LAST, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,86 @@ | ||||
//===- SYCLBIN.h - SYCLBIN binary format support ----------------*- C++ -*-===// | ||||
// | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | ||||
//===----------------------------------------------------------------------===// | ||||
|
||||
#ifndef LLVM_OBJECT_SYCLBIN_H | ||||
#define LLVM_OBJECT_SYCLBIN_H | ||||
|
||||
#include "llvm/ADT/SmallString.h" | ||||
#include "llvm/Object/Binary.h" | ||||
#include "llvm/SYCLLowerIR/ModuleSplitter.h" | ||||
#include "llvm/Support/MemoryBuffer.h" | ||||
#include <string> | ||||
|
||||
namespace llvm { | ||||
|
||||
namespace object { | ||||
|
||||
class SYCLBIN : public Binary { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main question I have here is why don't we re-use existing
If we need a hierarchical structure, then we just make it nested by putting one OpenMP offloading emits this data structure and I also think that whatever we produce for regular SYCL app compilation, for online compilation from SYCL sources and for SYCLBIN should have the same format for simplicity and uniformity of handling it in SYCL RT. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, we should eventually switch even the common structure of kernel code over to this new format. However, I think making this a subclass of
SYCLBIN does not have architecture at the top-level, as different contained modules can target different device architectures, so I worry that merging the two would make getters like it confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh, so the idea is to put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a comment to this class declaration to describe that it is supposed to be used as a more complicated from of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment and removed its inheritance from |
||||
public: | ||||
SYCLBIN(MemoryBufferRef Source); | ||||
|
||||
enum class BundleState : uint8_t { Input = 0, Object = 1, Executable = 2 }; | ||||
enum class IRType : uint8_t { SPIRV = 0, PTX = 1, AMDGCN = 2 }; | ||||
|
||||
struct ModuleDesc { | ||||
BundleState State; | ||||
std::string ArchString; | ||||
std::vector<module_split::SplitModule> SplitModules; | ||||
}; | ||||
|
||||
/// The current version of the binary used for backwards compatibility. | ||||
static constexpr uint32_t Version = 1; | ||||
|
||||
/// Magic number used to identify SYCLBIN files. | ||||
static constexpr uint8_t MagicNumber[4] = {0x53, 0x59, 0x42, 0x49}; | ||||
|
||||
/// Serialize the contents of \p ModuleDescs to a binary buffer to be read | ||||
/// later. | ||||
static Expected<SmallString<0>> write(const SmallVector<ModuleDesc> &); | ||||
|
||||
static Expected<std::unique_ptr<SYCLBIN>> read(MemoryBufferRef Source); | ||||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation of read/write is quite complex, it has to be exhaustively tested. I'm not saying that all the testing should be here from day 1, but we at least need to lay some groundwork for it. For example what you can do is to have a unit-test which does |
||||
|
||||
static uint64_t getAlignment() { return 8; } | ||||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
static bool classof(const Binary *V) { return V->isSYCLBINFile(); } | ||||
|
||||
struct IRModule { | ||||
IRType Type; | ||||
SmallVector<char> RawIRBytes; | ||||
}; | ||||
struct NativeDeviceCodeImage { | ||||
SmallString<0> ArchString; | ||||
SmallVector<char> RawDeviceCodeImageBytes; | ||||
}; | ||||
|
||||
struct AbstractModule { | ||||
SmallVector<SmallString<0>> KernelNames; | ||||
SmallVector<SmallString<0>> ImportedSymbols; | ||||
SmallVector<SmallString<0>> ExportedSymbols; | ||||
std::unique_ptr<llvm::util::PropertySetRegistry> Properties; | ||||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
SmallVector<IRModule> IRModules; | ||||
SmallVector<NativeDeviceCodeImage> NativeDeviceCodeImages; | ||||
}; | ||||
|
||||
struct { | ||||
uint8_t Magic[4]; | ||||
uint32_t Version; | ||||
BundleState State; | ||||
} Header; | ||||
|
||||
SmallVector<AbstractModule, 4> AbstractModules; | ||||
|
||||
private: | ||||
SYCLBIN(const SYCLBIN &Other) = delete; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need it to be declared as |
||||
}; | ||||
|
||||
} // namespace object | ||||
|
||||
} // namespace llvm | ||||
|
||||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "llvm/ADT/SetVector.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: do we need this instead of forward declaring? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do. Unlike There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why do we need this in a header file which is otherwise unchanged? It seems like either this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to be a dependency bug that just wasn't noticed because |
||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/PropertySetIO.h" | ||
|
||
|
@@ -29,7 +30,6 @@ | |
namespace llvm { | ||
|
||
class Function; | ||
class Module; | ||
|
||
namespace cl { | ||
class OptionCategory; | ||
|
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.
hopefully we're planning on upstreaming this?
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.
Absolutely! I am told there are some refactorings coming in for ClangLinkerWrapper, so I wanted to get some pieces in for now so development of other parts, like the driver, can go ahead in parallel.