From 2e6b18b3f3924d150c8837175938e76c3402f83f Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Mon, 18 Mar 2024 17:06:02 -0700 Subject: [PATCH] [mlir][sparse] add example to new operation doc, and roundtrip test (#85711) --- .../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 1b2981ac751f3..29cf8c32447ec 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 e9e458e805ba4..a47a3d5119f96 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 +}