[Mlir-commits] [mlir] [MLIR][Python] fix class name of powf and negf in linalg (PR #97696)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 4 01:51:52 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-linalg
Author: Bimo (xurui1995)
<details>
<summary>Changes</summary>
The following logic can lead to a class name mismatch when using `linalg.powf` in Python. This PR fixed the issue and also renamed `NegfOp` to `NegFOp` in linalg to adhere to the naming convention, as exemplified by `arith::NegFOp`.
https://github.com/llvm/llvm-project/blob/173514d58ec4e6166670f1e37a038df3865c8b96/mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py#L140-L143
```
# linalg.powf(arg0, arg1, outs=[init_result.result])
NotImplementedError: Unknown named op_name / op_class_name: powf / PowfOp
```
---
Full diff: https://github.com/llvm/llvm-project/pull/97696.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml (+1-1)
- (modified) mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py (+2-2)
- (modified) mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py (+4)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
index fad234a9dcae9..a344add6a4e54 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
@@ -271,7 +271,7 @@ structured_op: !LinalgStructuredOpConfig
--- !LinalgOpConfig
metadata: !LinalgOpMetadata
name: negf
- cpp_class_name: NegfOp
+ cpp_class_name: NegFOp
doc: |-
Applies negf(x) elementwise.
diff --git a/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py b/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
index 43410aaa6af1b..cbb2d1cec103c 100644
--- a/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
+++ b/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
@@ -96,7 +96,7 @@ def floor(
O[None] = UnaryFn.floor(I[None])
- at linalg_structured_op
+ at linalg_structured_op(op_class_name="NegFOp")
def negf(
I=TensorDef(T1),
O=TensorDef(T1, output=True),
@@ -330,7 +330,7 @@ def min(
O[None] = BinaryFn.min_signed(lhs[None], rhs[None])
- at linalg_structured_op
+ at linalg_structured_op(op_class_name="PowFOp")
def powf(
lhs=TensorDef(T1),
rhs=TensorDef(T1),
diff --git a/mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py b/mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py
index 0dceba9c13a46..0a068bff7715f 100644
--- a/mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py
+++ b/mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py
@@ -2,3 +2,7 @@
# Just verify that at least one known op is generated.
# CHECK: name: matmul
+
+# verify some special cases: negf->NegFOp, powf->PowFOp
+# CHECK cpp_class_name: NegFOp
+# CHECK cpp_class_name: PowFOp
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/97696
More information about the Mlir-commits
mailing list