[Mlir-commits] [mlir] bfa762a - [MLIR][Python] fix class name of powf and negf in linalg (#97696)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 4 18:23:16 PDT 2024
Author: Bimo
Date: 2024-07-05T09:23:12+08:00
New Revision: bfa762a5a59aa8bf64f589b36da24e427e8806c3
URL: https://github.com/llvm/llvm-project/commit/bfa762a5a59aa8bf64f589b36da24e427e8806c3
DIFF: https://github.com/llvm/llvm-project/commit/bfa762a5a59aa8bf64f589b36da24e427e8806c3.diff
LOG: [MLIR][Python] fix class name of powf and negf in linalg (#97696)
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
```
Added:
Modified:
mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py
Removed:
################################################################################
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..ee76b6d25cae1 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
More information about the Mlir-commits
mailing list