[Mlir-commits] [mlir] [mlir][sparse] code cleanup using the assumption that dim2lvl maps ar… (PR #72894)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Nov 20 09:35:01 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-sparse
Author: Peiming Liu (PeimingLiu)
<details>
<summary>Changes</summary>
…e simplified.
---
Full diff: https://github.com/llvm/llvm-project/pull/72894.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp (+16-19)
- (modified) mlir/test/Dialect/SparseTensor/codegen.mlir (+1-1)
``````````diff
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
index 9f41db73a5091120..1549ada203b4ae32 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp
@@ -745,8 +745,13 @@ class SparseTensorAllocConverter
const auto resType = getSparseTensorType(op);
if (!resType.hasEncoding())
return failure();
- Location loc = op.getLoc();
+ if (!resType.isIdentity()) {
+ return rewriter.notifyMatchFailure(
+ op, "try run --sparse-reinterpret-map before codegen");
+ }
+
+ Location loc = op.getLoc();
// Deal with copy.
if (op.getCopy()) {
auto desc = getDescriptorFromTensorTuple(adaptor.getCopy());
@@ -768,16 +773,10 @@ class SparseTensorAllocConverter
return success();
}
- // Construct the dim/lvl sizes and the (unused) dim2lvl/lvl2dim buffers.
- SmallVector<Value> dimSizesValues;
+ // Level size equals to dimension size since lvl2dim map is an identity map.
SmallVector<Value> lvlSizesValues;
- Value dimSizesBuffer;
- Value dim2lvlBuffer;
- Value lvl2dimBuffer;
createDimSizes(rewriter, loc, resType, adaptor.getDynamicSizes(),
- dimSizesValues);
- genMapBuffers(rewriter, loc, resType, dimSizesValues, dimSizesBuffer,
- lvlSizesValues, dim2lvlBuffer, lvl2dimBuffer);
+ lvlSizesValues);
// Construct allocation for each field.
Value sizeHint = op.getSizeHint();
@@ -809,19 +808,17 @@ class SparseTensorEmptyConverter : public OpConversionPattern<tensor::EmptyOp> {
const auto resType = getSparseTensorType(op);
if (!resType.hasEncoding())
return failure();
- Location loc = op.getLoc();
- // Construct the dim/lvl sizes and the (unused) dim2lvl/lvl2dim buffers.
- SmallVector<Value> dimSizesValues;
+ if (!resType.isIdentity()) {
+ return rewriter.notifyMatchFailure(
+ op, "try run --sparse-reinterpret-map before codegen");
+ }
+
+ Location loc = op.getLoc();
+ // Level size equals to dimension size since lvl2dim map is an identity map.
SmallVector<Value> lvlSizesValues;
- Value dimSizesBuffer;
- Value dim2lvlBuffer;
- Value lvl2dimBuffer;
createDimSizes(rewriter, loc, resType, adaptor.getDynamicSizes(),
- dimSizesValues);
- genMapBuffers(rewriter, loc, resType, dimSizesValues, dimSizesBuffer,
- lvlSizesValues, dim2lvlBuffer, lvl2dimBuffer);
-
+ lvlSizesValues);
// Construct allocation for each field.
Value sizeHint; // none
SmallVector<Value> fields;
diff --git a/mlir/test/Dialect/SparseTensor/codegen.mlir b/mlir/test/Dialect/SparseTensor/codegen.mlir
index e63595bed53e5998..a3b26972d66ff5d8 100644
--- a/mlir/test/Dialect/SparseTensor/codegen.mlir
+++ b/mlir/test/Dialect/SparseTensor/codegen.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s --lower-sparse-ops-to-foreach --lower-sparse-foreach-to-scf --sparse-tensor-codegen --canonicalize -cse | FileCheck %s
+// RUN: mlir-opt %s --lower-sparse-ops-to-foreach --lower-sparse-foreach-to-scf --sparse-reinterpret-map --sparse-tensor-codegen --canonicalize -cse | FileCheck %s
#SV = #sparse_tensor.encoding<{ map = (d0) -> (d0 : compressed) }>
``````````
</details>
https://github.com/llvm/llvm-project/pull/72894
More information about the Mlir-commits
mailing list