[Mlir-commits] [mlir] 059da56 - [MLIR][Lianlg] Add memory effects for softmax
Lorenzo Chelini
llvmlistbot at llvm.org
Mon Aug 14 02:42:45 PDT 2023
Author: Lorenzo Chelini
Date: 2023-08-14T11:42:39+02:00
New Revision: 059da566bc8a45ac8ffb16ddc1c8fecc2be57969
URL: https://github.com/llvm/llvm-project/commit/059da566bc8a45ac8ffb16ddc1c8fecc2be57969
DIFF: https://github.com/llvm/llvm-project/commit/059da566bc8a45ac8ffb16ddc1c8fecc2be57969.diff
LOG: [MLIR][Lianlg] Add memory effects for softmax
Reviewed By: qcolombet
Differential Revision: https://reviews.llvm.org/D157629
Added:
Modified:
mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/test/Dialect/Linalg/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
index fdb043000ae6c5..4d06747a05d635 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
@@ -95,6 +95,7 @@ def Linalg_SoftmaxOp : Linalg_Op<"softmax",
PredOpTrait<"input and output have same element type", TCopVTEtIsSameAs<0, 1>>,
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
DeclareOpInterfaceMethods<AggregatedOpInterface, ["decomposeOperation"]>,
+ DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
DeclareOpInterfaceMethods<TilingInterface,
["getIterationDomain",
"getLoopIteratorTypes",
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index c19ccfd83017dd..bcc36d6bd3e95e 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -2345,6 +2345,13 @@ SoftmaxOp::reifyResultShapes(OpBuilder &b,
.reifyResultShapes(b, reifiedReturnShapes);
}
+void SoftmaxOp::getEffects(
+ SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
+ &effects) {
+ getGenericEffectsImpl(effects, getOperation()->getResults(),
+ getDpsInputOperands(), getDpsInitOperands());
+}
+
// Helper functions for softmax decomposition.
// @{
diff --git a/mlir/test/Dialect/Linalg/canonicalize.mlir b/mlir/test/Dialect/Linalg/canonicalize.mlir
index d3bb48d5a442d4..783660727ce163 100644
--- a/mlir/test/Dialect/Linalg/canonicalize.mlir
+++ b/mlir/test/Dialect/Linalg/canonicalize.mlir
@@ -897,3 +897,14 @@ func.func @cast_producer_mixed(%arg0 : tensor<5xf32>, %arg1: memref<?xf32>) {
// CHECK-SAME: iterator_types = ["parallel"]
// CHECK-SAME: } ins(%[[ARG1]] : tensor<5xf32>)
// CHECK-SAME: outs(%[[ARG2]] : memref<?xf32>) {
+
+// -----
+
+// CHECK-LABEL: dead_softmax
+func.func @dead_softmax(%arg0: tensor<16x64x256xf32>) -> tensor<16x64x256xf32> {
+ %0 = tensor.empty() : tensor<16x64x256xf32>
+ // CHECK-NOT: linalg.softmax
+ %1 = linalg.softmax dimension(1)
+ ins(%arg0 : tensor<16x64x256xf32>) outs(%0 : tensor<16x64x256xf32>) -> tensor<16x64x256xf32>
+ return %arg0 : tensor<16x64x256xf32>
+}
More information about the Mlir-commits
mailing list