[Mlir-commits] [mlir] [mlir][sparse] Change DimLevelType Enum (PR #67192)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 22 13:53:31 PDT 2023


github-actions[bot] wrote:


<!--LLVM CODE FORMAT COMMENT: {clang-format}-->

:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 43aa6e6bf3d5ca1dde3e839f4c6ebd0e524055a1 6d4116e8fbcbabbd278e2847f596e92650f41e26 -- mlir/include/mlir-c/Dialect/SparseTensor.h mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h mlir/lib/CAPI/Dialect/SparseTensor.cpp mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.cpp mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.h mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h mlir/lib/ExecutionEngine/SparseTensor/NNZ.cpp mlir/lib/ExecutionEngine/SparseTensor/Storage.cpp mlir/test/CAPI/sparse_tensor.c
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
index 565f139cc431..986ecef78d6f 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h
@@ -171,41 +171,41 @@ enum class Action : uint32_t {
 // TODO: We should generalize TwoOutOfFour to N out of M and use property to
 // encode the value of N and M.
 enum class DimLevelType : uint16_t {
-  Undef = 0,                    // 0b00000000_00000000
-  Dense = 1,                    // 0b00000000_00000001
-  Compressed = 2,               // 0b00000000_00000010
-  CompressedNu = 258,           // 0b00000001_00000010
-  CompressedNo = 514,           // 0b00000010_00000010
-  CompressedNuNo = 770,         // 0b00000011_00000010
-  Singleton = 4,                // 0b00000000_00000100
-  SingletonNu = 260,            // 0b00000001_00000100
-  SingletonNo = 516,            // 0b00000010_00000100
-  SingletonNuNo = 772,          // 0b00000011_00000100
-  CompressedWithHi = 1026,      // 0b00000100_00000010
-  CompressedWithHiNu = 1282,    // 0b00000101_00000010
-  CompressedWithHiNo = 1538,    // 0b00000110_00000010
-  CompressedWithHiNuNo = 1794,  // 0b00000111_00000010
-  TwoOutOfFour = 2050,          // 0b00001000_00000010
+  Undef = 0,                   // 0b00000000_00000000
+  Dense = 1,                   // 0b00000000_00000001
+  Compressed = 2,              // 0b00000000_00000010
+  CompressedNu = 258,          // 0b00000001_00000010
+  CompressedNo = 514,          // 0b00000010_00000010
+  CompressedNuNo = 770,        // 0b00000011_00000010
+  Singleton = 4,               // 0b00000000_00000100
+  SingletonNu = 260,           // 0b00000001_00000100
+  SingletonNo = 516,           // 0b00000010_00000100
+  SingletonNuNo = 772,         // 0b00000011_00000100
+  CompressedWithHi = 1026,     // 0b00000100_00000010
+  CompressedWithHiNu = 1282,   // 0b00000101_00000010
+  CompressedWithHiNo = 1538,   // 0b00000110_00000010
+  CompressedWithHiNuNo = 1794, // 0b00000111_00000010
+  TwoOutOfFour = 2050,         // 0b00001000_00000010
 };
 
 /// This enum defines all the storage formats supported by the sparse compiler,
 /// without the level properties.
 enum class LevelFormat : uint16_t {
-  Dense = 1,                    // 0b00000000_00000001
-  Compressed = 2,               // 0b00000000_00000010
-  Singleton = 4,                // 0b00000000_00000100
+  Dense = 1,      // 0b00000000_00000001
+  Compressed = 2, // 0b00000000_00000010
+  Singleton = 4,  // 0b00000000_00000100
   // TODO: Remove CompressedWithHi and TwoOutOfFour from LevelFormat
   // once internal change lands.
-  CompressedWithHi = 1026,      // 0b00000100_00000010
-  TwoOutOfFour = 2050,          // 0b00001000_00000010
+  CompressedWithHi = 1026, // 0b00000100_00000010
+  TwoOutOfFour = 2050,     // 0b00001000_00000010
 };
 
 /// This enum defines all the nondefault properties for storage formats.
 enum class LevelNondefaultProperty : uint16_t {
-  Nonunique = 256,              // 0b00000001_00000000
-  Nonordered = 512,             // 0b00000010_00000000
-  High = 1024,                  // 0b00000100_00000000
-  Block2_4 = 2048               // 0b00001000_00000000
+  Nonunique = 256,  // 0b00000001_00000000
+  Nonordered = 512, // 0b00000010_00000000
+  High = 1024,      // 0b00000100_00000000
+  Block2_4 = 2048   // 0b00001000_00000000
 };
 
 /// Returns string representation of the given dimension level type.
@@ -389,55 +389,47 @@ static_assert(
       static_cast<uint16_t>(LevelNondefaultProperty::Block2_4)) == 0),
     "unique bit assignment for each level format and property is broken");
 
-static_assert((buildLevelType(LevelFormat::Dense,
-                              toPropertyBits(false, true)) == std::nullopt &&
-               buildLevelType(LevelFormat::Dense,
-                              toPropertyBits(true, false)) == std::nullopt &&
-               buildLevelType(LevelFormat::Dense,
-                              toPropertyBits(false, false)) == std::nullopt &&
-               *buildLevelType(LevelFormat::Dense,
-                               toPropertyBits(true, true)) ==
-                   DimLevelType::Dense &&
-               *buildLevelType(LevelFormat::Compressed,
-		               toPropertyBits(true, true)) ==
-                   DimLevelType::Compressed &&
-               *buildLevelType(LevelFormat::Compressed,
-		               toPropertyBits(true, false)) ==
-                   DimLevelType::CompressedNu &&
-               *buildLevelType(LevelFormat::Compressed,
-		               toPropertyBits(false, true)) ==
-                   DimLevelType::CompressedNo &&
-               *buildLevelType(LevelFormat::Compressed,
-		               toPropertyBits(false, false)) ==
-                   DimLevelType::CompressedNuNo &&
-               *buildLevelType(LevelFormat::Compressed,
-                               toPropertyBits(true, true, true)) ==
-                   DimLevelType::CompressedWithHi &&
-               *buildLevelType(LevelFormat::Compressed,
-                               toPropertyBits(false, true, true)) ==
-                   DimLevelType::CompressedWithHiNo &&
-               *buildLevelType(LevelFormat::Compressed,
-                               toPropertyBits(true, false, true)) ==
-                   DimLevelType::CompressedWithHiNu &&
-               *buildLevelType(LevelFormat::Compressed,
-                               toPropertyBits(false, false, true)) ==
-                   DimLevelType::CompressedWithHiNuNo &&
-               *buildLevelType(LevelFormat::Compressed,
-                               toPropertyBits(true, true, false, true)) ==
-                   DimLevelType::TwoOutOfFour &&
-               *buildLevelType(LevelFormat::Singleton,
-			       toPropertyBits(true, true)) ==
-                   DimLevelType::Singleton &&
-               *buildLevelType(LevelFormat::Singleton,
-			       toPropertyBits(true, false)) ==
-                   DimLevelType::SingletonNu &&
-               *buildLevelType(LevelFormat::Singleton,
-			       toPropertyBits(false, true)) ==
-                   DimLevelType::SingletonNo &&
-               *buildLevelType(LevelFormat::Singleton,
-			       toPropertyBits(false, false)) ==
-                   DimLevelType::SingletonNuNo),
-              "buildLevelType conversion is broken");
+static_assert(
+    (buildLevelType(LevelFormat::Dense, toPropertyBits(false, true)) ==
+         std::nullopt &&
+     buildLevelType(LevelFormat::Dense, toPropertyBits(true, false)) ==
+         std::nullopt &&
+     buildLevelType(LevelFormat::Dense, toPropertyBits(false, false)) ==
+         std::nullopt &&
+     *buildLevelType(LevelFormat::Dense, toPropertyBits(true, true)) ==
+         DimLevelType::Dense &&
+     *buildLevelType(LevelFormat::Compressed, toPropertyBits(true, true)) ==
+         DimLevelType::Compressed &&
+     *buildLevelType(LevelFormat::Compressed, toPropertyBits(true, false)) ==
+         DimLevelType::CompressedNu &&
+     *buildLevelType(LevelFormat::Compressed, toPropertyBits(false, true)) ==
+         DimLevelType::CompressedNo &&
+     *buildLevelType(LevelFormat::Compressed, toPropertyBits(false, false)) ==
+         DimLevelType::CompressedNuNo &&
+     *buildLevelType(LevelFormat::Compressed,
+                     toPropertyBits(true, true, true)) ==
+         DimLevelType::CompressedWithHi &&
+     *buildLevelType(LevelFormat::Compressed,
+                     toPropertyBits(false, true, true)) ==
+         DimLevelType::CompressedWithHiNo &&
+     *buildLevelType(LevelFormat::Compressed,
+                     toPropertyBits(true, false, true)) ==
+         DimLevelType::CompressedWithHiNu &&
+     *buildLevelType(LevelFormat::Compressed,
+                     toPropertyBits(false, false, true)) ==
+         DimLevelType::CompressedWithHiNuNo &&
+     *buildLevelType(LevelFormat::Compressed,
+                     toPropertyBits(true, true, false, true)) ==
+         DimLevelType::TwoOutOfFour &&
+     *buildLevelType(LevelFormat::Singleton, toPropertyBits(true, true)) ==
+         DimLevelType::Singleton &&
+     *buildLevelType(LevelFormat::Singleton, toPropertyBits(true, false)) ==
+         DimLevelType::SingletonNu &&
+     *buildLevelType(LevelFormat::Singleton, toPropertyBits(false, true)) ==
+         DimLevelType::SingletonNo &&
+     *buildLevelType(LevelFormat::Singleton, toPropertyBits(false, false)) ==
+         DimLevelType::SingletonNuNo),
+    "buildLevelType conversion is broken");
 
 // Ensure the above predicates work as intended.
 static_assert((isValidDLT(DimLevelType::Undef) &&
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index ffe2d917b1ef..8e6f03e4d730 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -752,14 +752,12 @@ RankedTensorType sparse_tensor::getCOOFromTypeWithOrdering(RankedTensorType rtt,
   if (lvlRank > 1) {
     // TODO: it is actually ordered at the level for ordered input.
     // Followed by unordered non-unique n-2 singleton levels.
-    std::fill_n(
-        std::back_inserter(lvlTypes), lvlRank - 2,
-        *buildLevelType(LevelFormat::Singleton,
-                        toPropertyBits(ordered, false)));
+    std::fill_n(std::back_inserter(lvlTypes), lvlRank - 2,
+                *buildLevelType(LevelFormat::Singleton,
+                                toPropertyBits(ordered, false)));
     // Ends by a unique singleton level unless the lvlRank is 1.
     lvlTypes.push_back(
-        *buildLevelType(LevelFormat::Singleton,
-                        toPropertyBits(ordered, true)));
+        *buildLevelType(LevelFormat::Singleton, toPropertyBits(ordered, true)));
   }
 
   // TODO: Maybe pick the bitwidth based on input/output tensors (probably the
@@ -835,8 +833,8 @@ static SparseTensorEncodingAttr
 getNormalizedEncodingForSpecifier(SparseTensorEncodingAttr enc) {
   SmallVector<DimLevelType> dlts;
   for (auto dlt : enc.getLvlTypes())
-    dlts.push_back(*buildLevelType(*getLevelFormat(dlt),
-                                   toPropertyBits(true, true)));
+    dlts.push_back(
+        *buildLevelType(*getLevelFormat(dlt), toPropertyBits(true, true)));
 
   return SparseTensorEncodingAttr::get(
       enc.getContext(), dlts,

``````````

</details>


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


More information about the Mlir-commits mailing list