-
Couldn't load subscription status.
- Fork 791
[SYCL][ABI Break]Removing Manifest from the offload binary structure. #20062
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
abb7f65
Removing Manifest from the offload binary structure.
YuriPlyakhin 7f78327
format
YuriPlyakhin 25ea27e
fixed e2e preview tests
YuriPlyakhin d37451a
addressed feedback
YuriPlyakhin 6078b1b
format
YuriPlyakhin 72f31eb
addressed comments
YuriPlyakhin 38e0a72
Update clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
YuriPlyakhin 3d0252d
Update llvm/lib/Frontend/Offloading/SYCLOffloadWrapper.cpp
YuriPlyakhin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
clang/test/Driver/clang-offload-wrapper-exe-preview.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| // End-to-end clang-offload-wrapper executable test: check that -batch options | ||
| // works, and that the tool generates data properly accessible at runtime. | ||
|
|
||
| // Prepare test data. Create the first binary image. | ||
YuriPlyakhin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // RUN: echo -e -n 'device binary image1\n' > %t.bin | ||
| // RUN: echo -e -n '[Category1]\nint_prop1=1|10\n[Category2]\nint_prop2=1|20\n' > %t.props | ||
| // RUN: echo -e -n 'kernel1\nkernel2\n' > %t.sym | ||
|
|
||
| // Create the second binary image with byte array property values. | ||
| // RUN: echo -e -n 'device binary image2\n' > %t_1.bin | ||
| // RUN: echo -e -n '[Category3]\n' > %t_1.props | ||
| // RUN: echo -e -n 'kernel1=2|IAAAAAAAAAQA\n' >> %t_1.props | ||
| // RUN: echo -e -n 'kernel2=2|oAAAAAAAAAw///3/wB\n' >> %t_1.props | ||
|
|
||
| // Create the batch file input for the wrapper. | ||
| // RUN: echo '[Code|Properties|Symbols]' > %t.batch | ||
| // RUN: echo %t.bin"|"%t.props"|"%t.sym >> %t.batch | ||
| // RUN: echo %t_1.bin"|"%t_1.props"|" >> %t.batch | ||
srividya-sundaram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Generate "gold" output. | ||
YuriPlyakhin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // RUN: cat %t.bin %t.props %t.sym > %t.all | ||
|
|
||
| // Create the wrapper object. | ||
| #ifdef __INTEL_PREVIEW_BREAKING_CHANGES | ||
| /// TODO: Remove -fpreview-breaking-changes from the command line, when removing the macro. | ||
| // RUN: clang-offload-wrapper -kind=sycl -target=TARGET -format=native -batch %t.batch -o %t.wrapped.bc -fpreview-breaking-changes | ||
| #endif // __INTEL_PREVIEW_BREAKING_CHANGES | ||
| // RUN: llc --filetype=obj %t.wrapped.bc -o %t.wrapped.o | ||
|
|
||
| // Compile & link the test with the wrapper. | ||
| // RUN: %clangxx %t.wrapped.o %s -o %t.batch.exe -v | ||
|
|
||
YuriPlyakhin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Run and check ignoring white spaces. | ||
| // RUN: %t.batch.exe > %t.batch.exe.out | ||
| // RUN: diff -b %t.batch.exe.out %t.all | ||
|
|
||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| // Data types created by the offload wrapper and inserted in the wrapper object. | ||
| // Match those defined in SYCL runtime Plugin Interface. | ||
| struct _pi_offload_entry_struct { | ||
YuriPlyakhin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void *addr; | ||
| char *name; | ||
| size_t size; | ||
| int32_t flags; | ||
| int32_t reserved; | ||
| }; | ||
|
|
||
| typedef _pi_offload_entry_struct *_pi_offload_entry; | ||
|
|
||
| struct _pi_device_binary_property_struct { | ||
| char *Name; // Null-terminated property name. | ||
| void *ValAddr; // Address of property value. | ||
| uint32_t Type; // pi_property_type. | ||
| uint64_t ValSize; // Size of property value in bytes. | ||
| }; | ||
|
|
||
| typedef _pi_device_binary_property_struct *pi_device_binary_property; | ||
|
|
||
| struct _pi_device_binary_property_set_struct { | ||
| char *Name; // The name. | ||
| pi_device_binary_property PropertiesBegin; // Array start. | ||
| pi_device_binary_property PropertiesEnd; // Array end. | ||
| }; | ||
|
|
||
| typedef _pi_device_binary_property_set_struct *pi_device_binary_property_set; | ||
|
|
||
| struct pi_device_binary_struct { | ||
| uint16_t Version; | ||
| uint8_t Kind; // 4 for SYCL. | ||
| uint8_t Format; // 1 for native. | ||
YuriPlyakhin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const char *DeviceTargetSpec; | ||
| const char *CompileOptions; | ||
| const char *LinkOptions; | ||
| const unsigned char *BinaryStart; | ||
| const unsigned char *BinaryEnd; | ||
| _pi_offload_entry EntriesBegin; | ||
| _pi_offload_entry EntriesEnd; | ||
| pi_device_binary_property_set PropertySetsBegin; | ||
| pi_device_binary_property_set PropertySetsEnd; | ||
| }; | ||
| typedef pi_device_binary_struct *pi_device_binary; | ||
|
|
||
| struct pi_device_binaries_struct { | ||
| uint16_t Version; | ||
| uint16_t NumDeviceBinaries; | ||
| pi_device_binary DeviceBinaries; | ||
| _pi_offload_entry *HostEntriesBegin; | ||
| _pi_offload_entry *HostEntriesEnd; | ||
| }; | ||
| typedef pi_device_binaries_struct *pi_device_binaries; | ||
|
|
||
| static pi_device_binaries BinDesc = nullptr; | ||
|
|
||
| // Wrapper object has code which calls these 2 functions below. | ||
| extern "C" void __sycl_register_lib(pi_device_binaries desc) { | ||
| BinDesc = desc; | ||
| } | ||
|
|
||
| extern "C" void __sycl_unregister_lib() {} | ||
|
|
||
| #define ASSERT(Cond, Msg) \ | ||
| if (!(Cond)) { \ | ||
| std::cerr << "*** ERROR: wrong " << Msg << "\n"; \ | ||
| return 1; \ | ||
| } | ||
|
|
||
| static std::string getString(const unsigned char *B, const unsigned char *E) { | ||
| return std::string(reinterpret_cast<const char *>(B), E - B); | ||
| } | ||
|
|
||
| static int getInt(void *Addr) { | ||
| const char *Ptr = reinterpret_cast<const char *>(Addr); | ||
| return Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16) | (Ptr[3] << 24); | ||
| } | ||
|
|
||
| using byte = unsigned char; | ||
|
|
||
| static void printProp(const pi_device_binary_property &Prop) { | ||
| std::cerr << "Property " << Prop->Name << " {\n"; | ||
| std::cerr << " Type: " << Prop->Type << "\n"; | ||
| if (Prop->Type != 1) | ||
| std::cerr << " Size = " << Prop->ValSize << "\n"; | ||
|
|
||
| std::cerr << " Value = "; | ||
| if (Prop->Type == 1) | ||
| std::cerr << getInt(&Prop->ValSize); | ||
| else { | ||
| std::cerr << " {\n "; | ||
|
|
||
| byte *Ptr = (byte *)Prop->ValAddr; | ||
|
|
||
| for (auto I = 0; I < Prop->ValSize && I < 100; ++I) { | ||
| std::cerr << " 0x" << std::hex << (unsigned int)Ptr[I]; | ||
| std::cerr << std::dec; | ||
| } | ||
| std::cerr << "\n }"; | ||
| } | ||
| std::cerr << "\n"; | ||
| std::cerr << "}\n"; | ||
| } | ||
|
|
||
| static int dumpBinary0() { | ||
| pi_device_binary Bin = &BinDesc->DeviceBinaries[0]; | ||
| ASSERT(Bin->Kind == 4, "Bin->Kind"); | ||
| ASSERT(Bin->Format == 1, "Bin->Format"); | ||
|
|
||
| // Dump code. | ||
| std::cout << getString(Bin->BinaryStart, Bin->BinaryEnd); | ||
| // Dump properties. | ||
| for (pi_device_binary_property_set PropSet = Bin->PropertySetsBegin; PropSet != Bin->PropertySetsEnd; ++PropSet) { | ||
| std::cout << "[" << PropSet->Name << "]" | ||
| << "\n"; | ||
|
|
||
| for (pi_device_binary_property Prop = PropSet->PropertiesBegin; Prop != PropSet->PropertiesEnd; ++Prop) { | ||
| ASSERT(Prop->Type == 1, "Prop->Type"); | ||
| std::cout << Prop->Name << "=" << Prop->Type << "|" << getInt(&Prop->ValSize) << "\n"; | ||
| } | ||
| } | ||
| // Dump symbols. | ||
| for (_pi_offload_entry Entry = Bin->EntriesBegin; Entry != Bin->EntriesEnd; ++Entry) | ||
| std::cout << Entry->name << "\n"; | ||
| return 0; | ||
| } | ||
|
|
||
| // Clang offload wrapper does Base64 decoding on byte array property values, so | ||
| // they can't be dumped as is and compared to the original. Instead, this | ||
| // testcase checks that the byte array in the property value is equal to the | ||
| // pre-decoded byte array. | ||
| static int checkBinary1() { | ||
| // Decoded from "IAAAAAAAAAQA": | ||
| const byte Arr0[] = {8, 0, 0, 0, 0, 0, 0, 0, 0x1}; | ||
| // Decoded from "oAAAAAAAAAw///3/wB": | ||
| const byte Arr1[] = {40, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0x7F, 0xFF, 0x70}; | ||
|
|
||
| struct { | ||
| const byte *Ptr; | ||
| const size_t Size; | ||
| } GoldArrays[] = { | ||
| {Arr0, sizeof(Arr0)}, | ||
| {Arr1, sizeof(Arr1)}}; | ||
| pi_device_binary Bin = &BinDesc->DeviceBinaries[1]; | ||
| ASSERT(Bin->Kind == 4, "Bin->Kind"); | ||
| ASSERT(Bin->Format == 1, "Bin->Format"); | ||
|
|
||
| for (pi_device_binary_property_set PropSet = Bin->PropertySetsBegin; PropSet != Bin->PropertySetsEnd; ++PropSet) { | ||
| int Cnt = 0; | ||
|
|
||
| for (pi_device_binary_property Prop = PropSet->PropertiesBegin; Prop != PropSet->PropertiesEnd; ++Prop, ++Cnt) { | ||
| ASSERT(Prop->Type == 2, "Prop->Type"); // Must be a byte array. | ||
| char *Ptr = reinterpret_cast<char *>(Prop->ValAddr); | ||
| int Cmp = std::memcmp(Prop->ValAddr, GoldArrays[Cnt].Ptr, GoldArrays[Cnt].Size); | ||
| ASSERT(Cmp == 0, "byte array property"); | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| int main(int argc, char **argv) { | ||
| ASSERT(BinDesc->NumDeviceBinaries == 2, "BinDesc->NumDeviceBinaries"); | ||
| ASSERT(BinDesc->Version == 1, "BinDesc->Version"); | ||
|
|
||
| if (dumpBinary0() != 0) | ||
| return 1; | ||
| if (checkBinary1() != 0) | ||
| return 1; | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,7 +303,6 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File, | |
|
|
||
| StringRef Prefix = | ||
| sys::path::stem(Binary.getMemoryBufferRef().getBufferIdentifier()); | ||
| StringRef Suffix = getImageKindName(Binary.getImageKind()); | ||
|
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. not used. removed. |
||
|
|
||
| StringRef BinArch = (Binary.getArch() == "*") ? "any" : Binary.getArch(); | ||
| auto TempFileOrErr = createOutputFile( | ||
|
|
@@ -1129,7 +1128,9 @@ wrapSYCLBinariesFromFile(std::vector<module_split::SplitModule> &SplitModules, | |
| errs() << formatv(" offload-wrapper: compile-opts: {0}, link-opts: {1}\n", | ||
| CompileOptions, LinkOptions); | ||
| } | ||
| if (Error E = offloading::wrapSYCLBinaries(M, Images, WrappingOptions)) | ||
| if (Error E = offloading::wrapSYCLBinaries( | ||
| M, Images, WrappingOptions, | ||
| Args.hasArg(OPT_preview_breaking_changes))) | ||
| return E; | ||
|
|
||
| if (Args.hasArg(OPT_print_wrapped_module)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.