-
Notifications
You must be signed in to change notification settings - Fork 793
[SYCL][Offload] Add SYCLBIN format and dump tool #16873
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
Conversation
This commit adds a new option `--syclbin` to the clang-linker-wrapper tool to produce SYCLBIN files from packaged device code binaries. The SYCLBIN format parsing added with these changes follow the format defined in the SYCLBIN design document. To help both users and the testing framework, a tool (syclbin-dump) for printing information about a SYCLBIN file is added. Signed-off-by: Larsen, Steffen <[email protected]>
Design document: #16872 |
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.
just a quick first pass
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
We do. Unlike shared_ptr
, unique_ptr
insists on the contained type not being incomplete.
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.
But why do we need this in a header file which is otherwise unchanged? It seems like either this #include
should be moved straight into .cpp
file, or into another .h
file
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.
It seems to be a dependency bug that just wasn't noticed because Module.h
was included before ModuleSplitter.h
in all other cases.
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
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.
Haven't yet looked at clang-linker-wrapper
and SYCLBIN::read/write
implementations
llvm/include/llvm/Object/SYCLBIN.h
Outdated
SmallVector<AbstractModule, 4> AbstractModules; | ||
|
||
private: | ||
SYCLBIN(const SYCLBIN &Other) = delete; |
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.
Why do you need it to be declared as private
to delete it? If we explicitly deleting it, then I think it is better to put it next to other constructors so that they are all next to each other.
llvm/lib/Object/SYCLBIN.cpp
Outdated
for (const ModuleDesc &Desc : ModuleDescs) { | ||
for (const module_split::SplitModule &SM : Desc.SplitModules) { |
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 a very long for
loop, I suggest that we outline some elements of it into smaller helper functions so that it is easier to grasp high-level logic and keep track of indentation levels
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've separated it a bit.
llvm/include/llvm/Object/SYCLBIN.h
Outdated
static Expected<SmallString<0>> write(const SmallVector<ModuleDesc> &); | ||
|
||
static Expected<std::unique_ptr<SYCLBIN>> read(MemoryBufferRef Source); |
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.
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 write
, then read
and checks that result is the same as the initial input. See e471ba3 for inspiration.
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.
Unittest has been added. Definitely could use some expanding on, but there are also a handful of TODOs in the current version, so it will be expanded upon over time.
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@maksimsab & @AlexeySachkov & @asudarsa - I've refactored the implementation based on discussions with @maksimsab. It should reduce the memory relocation now by pre-calculating the size needed for the serialized SYCLBIN in memory. Let me know what you think! |
if (!BlobOrError) | ||
return BlobOrError.takeError(); | ||
|
||
std::string PropStr{BlobOrError->str()}; |
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.
nit.
We could create here a MemoryBuffer
right from the StringRef
.
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.
Sadly it won't work. PropertySetRegistry::read
expects null-termination and the binary blob doesn't have that. It gets it when we copy it to a string though.
|
||
namespace { | ||
|
||
class SYCLBINBlockReader { |
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.
nit.
These 3 classes could be replaced with simple functions making the maintenance easier for developers.
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 the benefit of the class is that we can implicitly track how much memory is left. This lets us avoid reading outside the buffer, which is good for security. We could of course track that through functions as well, but it would require some additional variables we pass around. Personally I think this is cleaner, but if you think having free-functions for it is better, I won't die on this hill. 😉
Signed-off-by: Larsen, Steffen <[email protected]>
Friendly ping @KseniyaTikhomirova . |
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.
LGTM
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.
LGTM.
This commit avoids a warning produced by intel#16873 when building syclbin-dump using compilers other than gcc and clang, where the -fno-rtti option isn't available. Signed-off-by: Larsen, Steffen <[email protected]>
Windows post-commit failure should be addressed by #18233. |
This commit avoids a warning produced by #16873 when building syclbin-dump using compilers other than gcc and clang, where the -fno-rtti option isn't available. Signed-off-by: Larsen, Steffen <[email protected]>
This commit adds a new option
--syclbin
to the clang-linker-wrapper tool to produce SYCLBIN files from packaged device code binaries. The SYCLBIN format parsing added with these changes follow the format defined in the SYCLBIN design document.To help both users and the testing framework, a tool (syclbin-dump) for printing information about a SYCLBIN file is added.