From 8b124c19f52cb8ed0236b602df56787553e1e1b6 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Tue, 5 Jan 2021 13:29:28 -0800 Subject: [PATCH] [mlir][sparse] adjust output shape inference to new tensor abstraction Nicolas changed the tensor abstraction so that every output has its own shape definition. This simplifies the "inference" that was used in the sparse compiler. Reviewed By: penpornk Differential Revision: https://reviews.llvm.org/D94119 --- .../lib/Dialect/Linalg/Transforms/Sparsification.cpp | 11 ++--------- mlir/test/Dialect/Linalg/sparse_2d.mlir | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp b/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp index a6b7277..ed81d5e 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp @@ -538,15 +538,8 @@ static void genBuffers(Merger &merger, CodeGen &codegen, // Find lower and upper bound in current dimension. Value up; if (shape[d] == TensorType::kDynamicSize) { - // For the output tensor, we may need to infer the upper bound. - // For all others, we look at the incoming argument. - if (t == numInputs && !op.getNumInitTensors()) { - up = codegen.sizes[i]; - assert(up); // TODO: what else? - } else { - Value arg = t < numInputs ? op.getInput(t) : op.getInitTensors()[0]; - up = rewriter.create(loc, arg, d); - } + Value arg = t < numInputs ? op.getInput(t) : op.getOutput(0); + up = rewriter.create(loc, arg, d); args.push_back(up); } else { up = rewriter.create(loc, shape[d]); diff --git a/mlir/test/Dialect/Linalg/sparse_2d.mlir b/mlir/test/Dialect/Linalg/sparse_2d.mlir index 6612a72..9bb68ca 100644 --- a/mlir/test/Dialect/Linalg/sparse_2d.mlir +++ b/mlir/test/Dialect/Linalg/sparse_2d.mlir @@ -1139,19 +1139,19 @@ func @sum_reduction(%arga: tensor<10x20xf32>, %argx: tensor) -> tensor // CHECK: %[[VAL_2:.*]] = constant 999 : index // CHECK: %[[VAL_3:.*]] = constant 0 : index // CHECK: %[[VAL_4:.*]] = constant 1 : index -// CHECK: %[[VAL_5:.*]] = dim %[[VAL_0]], %[[VAL_3]] : tensor +// CHECK: %[[VAL_5:.*]] = alloca(%[[VAL_2]]) : memref // CHECK: %[[VAL_6:.*]] = alloca(%[[VAL_2]]) : memref -// CHECK: %[[VAL_7:.*]] = alloca(%[[VAL_2]]) : memref -// CHECK: %[[VAL_8:.*]] = dim %[[VAL_0]], %[[VAL_4]] : tensor -// CHECK: %[[VAL_9:.*]] = alloca(%[[VAL_2]]) : memref -// CHECK: %[[VAL_10:.*]] = alloca(%[[VAL_5]], %[[VAL_8]]) : memref -// CHECK: scf.for %[[VAL_11:.*]] = %[[VAL_3]] to %[[VAL_5]] step %[[VAL_4]] { -// CHECK: %[[VAL_12:.*]] = load %[[VAL_6]]{{\[}}%[[VAL_11]]] : memref +// CHECK: %[[VAL_7:.*]] = alloca(%[[VAL_2]]) : memref +// CHECK: %[[VAL_8:.*]] = dim %[[VAL_0]], %[[VAL_3]] : tensor +// CHECK: %[[VAL_9:.*]] = dim %[[VAL_0]], %[[VAL_4]] : tensor +// CHECK: %[[VAL_10:.*]] = alloca(%[[VAL_8]], %[[VAL_9]]) : memref +// CHECK: scf.for %[[VAL_11:.*]] = %[[VAL_3]] to %[[VAL_8]] step %[[VAL_4]] { +// CHECK: %[[VAL_12:.*]] = load %[[VAL_5]]{{\[}}%[[VAL_11]]] : memref // CHECK: %[[VAL_13:.*]] = addi %[[VAL_11]], %[[VAL_4]] : index -// CHECK: %[[VAL_14:.*]] = load %[[VAL_6]]{{\[}}%[[VAL_13]]] : memref +// CHECK: %[[VAL_14:.*]] = load %[[VAL_5]]{{\[}}%[[VAL_13]]] : memref // CHECK: scf.for %[[VAL_15:.*]] = %[[VAL_12]] to %[[VAL_14]] step %[[VAL_4]] { -// CHECK: %[[VAL_16:.*]] = load %[[VAL_7]]{{\[}}%[[VAL_15]]] : memref -// CHECK: %[[VAL_17:.*]] = load %[[VAL_9]]{{\[}}%[[VAL_15]]] : memref +// CHECK: %[[VAL_16:.*]] = load %[[VAL_6]]{{\[}}%[[VAL_15]]] : memref +// CHECK: %[[VAL_17:.*]] = load %[[VAL_7]]{{\[}}%[[VAL_15]]] : memref // CHECK: %[[VAL_18:.*]] = mulf %[[VAL_17]], %[[VAL_1]] : f64 // CHECK: store %[[VAL_18]], %[[VAL_10]]{{\[}}%[[VAL_11]], %[[VAL_16]]] : memref // CHECK: } -- 2.7.4