[Mlir-commits] [mlir] [mlir][tosa][tosa-to-linalg] Add NaN Mode Lowering (PR #125668)

Suraj Sudhir llvmlistbot at llvm.org
Thu Feb 13 11:31:34 PST 2025


================
@@ -267,6 +267,26 @@ extractConvZpPair(TosaConvOp op, PatternRewriter &rewriter) {
 
   return std::make_optional<ConvZpPair>(*maybeInputZp, *maybeWeightZp);
 }
+
+// Helper function to extract the NaN propagation mode from an operation.
+// Note that the for operations which support NaN mode propagation the attribute
+// is optional and its default value is "PROPAGATE".
+//
+// If the function is called with an operator that doesn't support the NaN mode
+// attribute it will return a std::nullopt.
+inline std::optional<std::string> getNanMode(Operation *op,
+                                             PatternRewriter &rewriter) {
+  if (isa<tosa::ClampOp>(op) || isa<tosa::MaxPool2dOp>(op) ||
----------------
sjarus wrote:

Per-op checks across a number of ops might be better located in one place, e.g. within a dialect level op interface. It would make this more future-proof. 

This can be a later refactor however. 

https://github.com/llvm/llvm-project/pull/125668


More information about the Mlir-commits mailing list