[Mlir-commits] [mlir] [mlir][tosa][tosa-to-linalg] Add NaN Mode Lowering (PR #125668)
Jack Frankland
llvmlistbot at llvm.org
Wed Feb 19 05:24:55 PST 2025
================
@@ -802,11 +802,47 @@ class MaxPool2dConverter : public OpConversionPattern<tosa::MaxPool2dOp> {
rewriter.replaceOpWithNewOp<linalg::PoolingNhwcMaxUnsignedOp>(
op, ArrayRef<Type>{resultTy}, ValueRange{paddedInput, fakeWindowDims},
filledEmptyTensor, strideAttr, dilationAttr);
- } else {
- rewriter.replaceOpWithNewOp<linalg::PoolingNhwcMaxOp>(
- op, ArrayRef<Type>{resultTy}, ValueRange{paddedInput, fakeWindowDims},
- filledEmptyTensor, strideAttr, dilationAttr);
+ return llvm::success();
}
+
+ auto resultOp = rewriter.create<linalg::PoolingNhwcMaxOp>(
+ op->getLoc(), ArrayRef<Type>{resultTy},
+ ValueRange{paddedInput, fakeWindowDims}, filledEmptyTensor, strideAttr,
+ dilationAttr);
+
+ // Check the NaN propgation mode is present.
+ const auto nanMode = getNanMode(op, rewriter);
+ if (!nanMode)
+ return failure();
+
+ // "PROPAGATE" mode matches the behaviour of the LinAlg named op, so no
+ // compare and select materialization is required.
+ //
+ // In the case of "IGNORE" we need to insert a compare and select. Since
+ // we've already produced a named op we will just take its body and modify
+ // it to include the appropriate checks. If the current value is NaN the
+ // old value of pool will be taken otherwise we use the result.
+ if (nanMode == "IGNORE") {
----------------
FranklandJack wrote:
I don't think the `linalg::PoolingNhwcMaxOp` says anything about NaN propagation semantics so presumably any transformations on this op can't make assumptions about its semantics. We can replace this with a generic though by just expanding it and then doing the same modifications in place.
https://github.com/llvm/llvm-project/pull/125668
More information about the Mlir-commits
mailing list