[Mlir-commits] [mlir] 4aa9b39 - [mlir][sparse] reject sparsity annotation in "scalar" tensors

Aart Bik llvmlistbot at llvm.org
Thu Nov 4 09:49:15 PDT 2021


Author: Aart Bik
Date: 2021-11-04T09:49:05-07:00
New Revision: 4aa9b398240efdddaa69e928e5d7b97331bc696a

URL: https://github.com/llvm/llvm-project/commit/4aa9b398240efdddaa69e928e5d7b97331bc696a
DIFF: https://github.com/llvm/llvm-project/commit/4aa9b398240efdddaa69e928e5d7b97331bc696a.diff

LOG: [mlir][sparse] reject sparsity annotation in "scalar" tensors

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D113152

Added: 
    

Modified: 
    mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
    mlir/test/Dialect/SparseTensor/invalid_encoding.mlir
    mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 1ee943cd7adb..2349ce516c97 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -171,6 +171,8 @@ LogicalResult SparseTensorEncodingAttr::verifyEncoding(
   // Check integrity with tensor type specifics. Dimension ordering is optional,
   // but we always should have dimension level types for the full rank.
   unsigned size = shape.size();
+  if (size == 0)
+    return emitError() << "expected non-scalar sparse tensor";
   if (getDimOrdering() && getDimOrdering().getNumResults() != size)
     return emitError() << "expected an affine map of size " << size
                        << " for dimension ordering";

diff  --git a/mlir/test/Dialect/SparseTensor/invalid_encoding.mlir b/mlir/test/Dialect/SparseTensor/invalid_encoding.mlir
index 2c60c6370533..b78d921b4aa4 100644
--- a/mlir/test/Dialect/SparseTensor/invalid_encoding.mlir
+++ b/mlir/test/Dialect/SparseTensor/invalid_encoding.mlir
@@ -1,5 +1,8 @@
 // RUN: mlir-opt %s -split-input-file -verify-diagnostics
 
+#a = #sparse_tensor.encoding<{dimLevelType = []}>
+func private @scalar(%arg0: tensor<f64, #a>) -> () // expected-error {{expected non-scalar sparse tensor}}
+
 // -----
 
 #a = #sparse_tensor.encoding<{dimLevelType = ["dense", "compressed"]}>

diff  --git a/mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir b/mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
index 4fe805fa97b8..79523598856d 100644
--- a/mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
+++ b/mlir/test/Dialect/SparseTensor/sparse_vector_peeled.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -sparsification="vectorization-strategy=2 vl=16" -for-loop-peeling -canonicalize -split-input-file | \
+// RUN: mlir-opt %s -sparsification="vectorization-strategy=2 vl=16" -for-loop-peeling -canonicalize | \
 // RUN:   FileCheck %s
 
 #SparseVector = #sparse_tensor.encoding<{


        


More information about the Mlir-commits mailing list