[Mlir-commits] [mlir] [mlir][sparse] add example to new operation doc, and roundtrip test (PR #85711)

Aart Bik llvmlistbot at llvm.org
Mon Mar 18 15:36:20 PDT 2024


https://github.com/aartbik created https://github.com/llvm/llvm-project/pull/85711

None

>From a0b6448a74dbe1c4d9ed891f4c1f8a47749b451a Mon Sep 17 00:00:00 2001
From: Aart Bik <ajcbik at google.com>
Date: Mon, 18 Mar 2024 15:35:41 -0700
Subject: [PATCH] [mlir][sparse] add example to new operation doc, and
 roundtrip test

---
 .../Dialect/SparseTensor/IR/SparseTensorOps.td   | 16 +++++++++++++---
 mlir/test/Dialect/SparseTensor/roundtrip.mlir    | 10 ++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
index 1b2981ac751f3e..29cf8c32447ecf 100644
--- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
+++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
@@ -1444,9 +1444,19 @@ def SparseTensor_HasRuntimeLibraryOp
     : SparseTensor_Op<"has_runtime_library", []>, Results<(outs I1:$result)> {
   string summary = "Indicates whether running in runtime/codegen mode";
   string description = [{
-    Returns a boolean value that indicates whether the sparse compiler runs in
-    runtime library mode or not. For testing only: This op is useful for writing
-    test cases that require different IR depending on runtime/codegen mode.
+    Returns a boolean value that indicates whether the sparsifier runs in
+    runtime library mode or not. For testing only! This operation is useful
+    for writing test cases that require different code depending on
+    runtime/codegen mode.
+
+    Example:
+
+    ```mlir
+    %has_runtime = sparse_tensor.has_runtime_library
+    scf.if %has_runtime {
+      ...
+    }
+    ```
   }];
   let assemblyFormat = "attr-dict";
 }
diff --git a/mlir/test/Dialect/SparseTensor/roundtrip.mlir b/mlir/test/Dialect/SparseTensor/roundtrip.mlir
index e9e458e805ba47..a47a3d5119f96d 100644
--- a/mlir/test/Dialect/SparseTensor/roundtrip.mlir
+++ b/mlir/test/Dialect/SparseTensor/roundtrip.mlir
@@ -728,3 +728,13 @@ func.func @sparse_print(%arg0: tensor<10x10xf64, #CSR>) {
   sparse_tensor.print %arg0 : tensor<10x10xf64, #CSR>
   return
 }
+
+// -----
+
+// CHECK-LABEL:   func.func @sparse_has_runtime() -> i1
+// CHECK:           %[[H:.*]] = sparse_tensor.has_runtime_library
+// CHECK:           return %[[H]] : i1
+func.func @sparse_has_runtime() -> i1 {
+  %has_runtime = sparse_tensor.has_runtime_library
+  return %has_runtime : i1
+}



More information about the Mlir-commits mailing list