-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SYCL][LLVM] Adding property set I/O library for SYCL #110771
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
Closed
+778
−0
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7350a52
[SYCL][LLVM] Adding property set I/O library for SYCL
asudarsa 526633f
Move from union to variant
asudarsa 944841a
Add missing implementation of encode/decode functions
asudarsa f528b64
More changes due to shift from Union to std::variant
asudarsa 0b4ad71
Address review comments
asudarsa cd9874a
Fix clang format issue
asudarsa de19806
Remove changes to Base64 implementation and use existing implementation
asudarsa 20a7d75
Add SYCL prefix to PropertySet etc.
asudarsa 025503a
Add tests expected to fail and make sure errors are caught
asudarsa 6550bf5
Update test to pass when assertions are turned on
asudarsa 4de3158
Replace simple llvm_unreachable with asserts
asudarsa b15e201
Addressed the following comments:
asudarsa 50de423
Avoid memory leak for byte array
asudarsa 0d5af17
Use unique_ptr for Byte Array
asudarsa 269d661
Minor change to use switch-case instead of if-then-else
asudarsa 60526f4
Fix formatting issue
asudarsa 498eaf0
Add more tests for PropertySetIO usage
asudarsa dec58b4
Remove redundant print statements
asudarsa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "llvm/Support/SYCLPropertySetIO.h" | ||
| #include "llvm/ADT/MapVector.h" | ||
| #include "llvm/Support/MemoryBuffer.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
| #include "llvm/Testing/Support/Error.h" | ||
|
|
@@ -19,70 +20,121 @@ using namespace llvm::util; | |
|
|
||
| namespace { | ||
|
|
||
| TEST(SYCLPropertySet, IncorrectValuesIO) { | ||
| TEST(SYCLPropertySet, IncorrectValuesReadIO) { | ||
| auto Content = "Staff/Ages]\n"; | ||
| auto MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| auto PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid line"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("property category missing"))); | ||
|
|
||
| Content = "[Staff/Ages\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid line"; | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid line"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property line"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid property line"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=|10\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property value"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid property value"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=abc|10\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property type"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid property type"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=1|IAQ\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property value"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid property value"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=2|IAQ\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property value"; | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr( | ||
| "Base64 encoded strings must be a multiple of 4 bytes in length"))); | ||
|
|
||
| Content = "[Staff/Ages]\n" | ||
| "person1=100|10\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), Failed()) | ||
| << "Invalid property type"; | ||
| EXPECT_THAT_ERROR(std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("bad property type"))); | ||
|
|
||
| Content = "[Opt/Param]\n" | ||
| "kernel1=2|IAAAAAAAAAQA\tIAAAAAAAAAQ\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("Invalid Base64 character"))); | ||
|
|
||
| Content = "[Opt/Param]\n" | ||
| "kernel1=2|IAAAAAAAAAQA\nIAAAAAAAAAQ\n"; | ||
| MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
| EXPECT_THAT_ERROR( | ||
| std::move(PropSetsPtr.takeError()), | ||
| FailedWithMessage(testing::HasSubstr("invalid property line"))); | ||
| } | ||
|
|
||
| TEST(SYCLPropertySet, DuplicateKeysRead) { | ||
| // '1' in '1|20' means 'integer property' | ||
| auto Content = "[Staff/Ages]\n" | ||
| "person1=1|20\n" | ||
| "person1=1|25\n"; | ||
| // For duplicate keys, the latest key is selected | ||
| auto ExpectedContent = "[Staff/Ages]\n" | ||
| "person1=1|25\n"; | ||
| auto MemBuf = MemoryBuffer::getMemBuffer(Content); | ||
| // Parse a property set registry | ||
| auto PropSetsPtr = SYCLPropertySetRegistry::read(MemBuf.get()); | ||
|
|
||
| if (!PropSetsPtr) | ||
| FAIL() << "SYCLPropertySetRegistry::read failed\n"; | ||
|
|
||
| std::string Serialized; | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSetsPtr->get()->write(OS); | ||
| } | ||
| // Check that the original and the serialized version are equal | ||
| EXPECT_EQ(Serialized, ExpectedContent); | ||
| } | ||
|
|
||
| // Test read-then-write of a list of integer values | ||
| TEST(SYCLPropertySet, IntValuesIO) { | ||
| // '1' in '1|20' means 'integer property' | ||
| auto Content = "[Staff/Ages]\n" | ||
|
|
@@ -109,6 +161,7 @@ TEST(SYCLPropertySet, IntValuesIO) { | |
| EXPECT_EQ(Serialized, Content); | ||
| } | ||
|
|
||
| // Test read-then-write of a list of byte arrays | ||
| TEST(SYCLPropertySet, ByteArrayValuesIO) { | ||
| // '2' in '2|...' means 'byte array property', Base64-encoded | ||
| // encodes the following byte arrays: | ||
|
|
@@ -135,4 +188,127 @@ TEST(SYCLPropertySet, ByteArrayValuesIO) { | |
| // Check that the original and the serialized version are equal | ||
| EXPECT_EQ(Serialized, Content); | ||
| } | ||
|
|
||
| // Test write-then-read of boolean values | ||
| TEST(SYCLPropertySet, Mask) { | ||
| SYCLPropertySetRegistry PropSet; | ||
| uint32_t Mask = 0; | ||
| std::map<StringRef, uint32_t> DevMask = {{"Mask", Mask}}; | ||
| PropSet.add("MaskCategory", DevMask); | ||
| std::string Serialized; | ||
| std::string Expected("[MaskCategory]\nMask=1|0\n"); | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSet.write(OS); | ||
| } | ||
| llvm::errs() << Serialized << "\n"; | ||
| EXPECT_EQ(Serialized, Expected); | ||
| } | ||
|
|
||
| // Test write-then-read of std::map<StringRef, SYCLPropertyValue> | ||
| // SYClPropertyValue is a class which contains one member, which is | ||
| // std::variant<uint32_t, std::unique_ptr<std::byte, Deleter>> Val; | ||
| TEST(SYCLPropertySet, SYCLPropertyValues) { | ||
| std::map<StringRef, SYCLPropertyValue> PropValues; | ||
| std::vector<uint32_t> Values = {1, 2, 3, 4}; | ||
| uint32_t Size = 4; | ||
| PropValues["Values"] = std::move(Values); | ||
| PropValues["Size"] = Size; | ||
| SYCLPropertySetRegistry PropSet; | ||
| PropSet.add("Property Values", PropValues); | ||
| std::string Serialized; | ||
| std::string Expected( | ||
| "[Property Values]\nSize=1|4\nValues=2|AQAAAAIAAAADAAAABAAAAA==\n"); | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSet.write(OS); | ||
| } | ||
| llvm::errs() << Serialized << "\n"; | ||
| EXPECT_EQ(Serialized, Expected); | ||
| } | ||
|
|
||
| // Test write-then-read of MapVector of StringRef to a simple struct datatype. | ||
| // Example of simple data structure: | ||
| // struct SimpleDS { | ||
| // unsigned ID; | ||
| // unsigned Offset; | ||
| // unsigned Size; | ||
| // }; | ||
| struct SimpleDS { | ||
| unsigned ID; | ||
| unsigned Offset; | ||
| unsigned Size; | ||
| }; | ||
| using MapTy = MapVector<StringRef, std::vector<SimpleDS>>; | ||
| TEST(SYCLPropertySet, MapToStruct) { | ||
| MapTy Values; | ||
| std::vector<SimpleDS> SimpleDSVal(2); | ||
| unsigned Start = 0; | ||
| for (unsigned I = Start; I < Start + 2; ++I) { | ||
| SimpleDSVal[I - Start].ID = I; | ||
| SimpleDSVal[I - Start].Offset = I * 4; | ||
| SimpleDSVal[I - Start].Size = 4; | ||
| } | ||
| Values["Value0"] = SimpleDSVal; | ||
| Start += 8; | ||
| for (unsigned I = Start; I < Start + 2; ++I) { | ||
| SimpleDSVal[I - Start].ID = I; | ||
| SimpleDSVal[I - Start].Offset = I * 4; | ||
| SimpleDSVal[I - Start].Size = 4; | ||
| } | ||
| Values["Value1"] = SimpleDSVal; | ||
| SYCLPropertySetRegistry PropSet; | ||
| PropSet.add("Values", Values); | ||
| std::string Serialized; | ||
| std::string Expected( | ||
| "[Values]\nValue0=2|AAAAAAAAAAAEAAAAAQAAAAQAAAAEAAAA\nValue1=2|" | ||
| "CAAAACAAAAAEAAAACQAAACQAAAAEAAAA\n"); | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSet.write(OS); | ||
| } | ||
| llvm::errs() << Serialized << "\n"; | ||
| EXPECT_EQ(Serialized, Expected); | ||
| } | ||
|
|
||
| // Test write-then-read of vector of chars | ||
| TEST(SYCLPropertySet, VectorOfChars) { | ||
| std::vector<char> Values; | ||
| for (unsigned I = 0; I < 8; ++I) | ||
| Values.push_back((char)(I + '0')); | ||
| SYCLPropertySetRegistry PropSet; | ||
| PropSet.add("Values", "all", Values); | ||
| std::string Serialized; | ||
| std::string Expected("[Values]\nall=2|MDEyMzQ1Njc=\n"); | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSet.write(OS); | ||
| } | ||
| llvm::errs() << Serialized << "\n"; | ||
| EXPECT_EQ(Serialized, Expected); | ||
| } | ||
|
|
||
| // Test write-then-read of a list of Name-Value pairs | ||
| TEST(SYCLPropertySet, ListOfNameValuePairs) { | ||
| SYCLPropertySetRegistry PropSet; | ||
| std::vector<std::string> Names = {"Name0", "Name1", "Name2", "Name3"}; | ||
| for (unsigned I = 0; I < 4; ++I) { | ||
| auto Value = I * 8; | ||
| PropSet.add("Values", Names[I], Value); | ||
| } | ||
| std::string Serialized; | ||
| std::string Expected( | ||
| "[Values]\nName0=1|0\nName1=1|8\nName2=1|16\nName3=1|24\n"); | ||
| { | ||
| llvm::raw_string_ostream OS(Serialized); | ||
| // Serialize | ||
| PropSet.write(OS); | ||
| } | ||
| llvm::errs() << Serialized << "\n"; | ||
| EXPECT_EQ(Serialized, Expected); | ||
| } | ||
| } // namespace | ||
|
Collaborator
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. What about something like this? |
||
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.