[Mlir-commits] [mlir] [mlir][sparse] Update verifier for block sparsity and singleton (PR #69389)

Aart Bik llvmlistbot at llvm.org
Wed Oct 18 12:36:17 PDT 2023


================
@@ -818,6 +824,53 @@ AffineMap mlir::sparse_tensor::inverseBlockSparsity(AffineMap dimToLvl,
   return dimToLvl.get(dimToLvl.getNumResults(), 0, lvlExprs, context);
 }
 
+SmallVector<unsigned> mlir::sparse_tensor::getBlockSize(AffineMap dimToLvl) {
+  assert(isBlockSparsity(dimToLvl) &&
+         "expected dimToLvl to be block sparsity for calling getBlockSize");
+  SmallVector<unsigned> blockSize;
+  for (auto result : dimToLvl.getResults()) {
+    if (auto binOp = result.dyn_cast<AffineBinaryOpExpr>()) {
+      if (result.getKind() == AffineExprKind::Mod) {
+        blockSize.push_back(
+            binOp.getRHS().dyn_cast<AffineConstantExpr>().getValue());
+      }
+    } else {
+      blockSize.push_back(1);
----------------
aartbik wrote:

note that 1 could still be used for an explicit floor/mod blocking by 1; this is weird, but would expand that dimension into two. In contrast, a non-expanding dimension does not change rank. So arguable we should return 0...

but it is detail we can debate later too

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


More information about the Mlir-commits mailing list