[llvm] [SYCL][LLVM] Adding property set I/O library for SYCL (PR #110771)

Arvind Sudarsanam via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 14:44:43 PDT 2024


================
@@ -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);
----------------
asudarsa wrote:

These statements were for 'local' testing/debugging purpose. Removed them throughout.
Thanks for the catch.

https://github.com/llvm/llvm-project/pull/110771


More information about the llvm-commits mailing list