[Mlir-commits] [mlir] [mlir][tosa][tosa-to-linalg] Add NaN Mode Lowering (PR #125668)
Georgios Pinitas
llvmlistbot at llvm.org
Wed Feb 19 04:01:14 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") {
----------------
GeorgeARM wrote:
Hmmm, is this clean semantically? Can't we have another `linalg.generic` after this instead of touching the generic block of the `resultOp`?
https://github.com/llvm/llvm-project/pull/125668
More information about the Mlir-commits
mailing list