Skip to content

Commit bfa762a

Browse files
authored
[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 ```
1 parent 4762f3b commit bfa762a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ structured_op: !LinalgStructuredOpConfig
271271
--- !LinalgOpConfig
272272
metadata: !LinalgOpMetadata
273273
name: negf
274-
cpp_class_name: NegfOp
274+
cpp_class_name: NegFOp
275275
doc: |-
276276
Applies negf(x) elementwise.
277277

mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def floor(
9696
O[None] = UnaryFn.floor(I[None])
9797

9898

99-
@linalg_structured_op
99+
@linalg_structured_op(op_class_name="NegFOp")
100100
def negf(
101101
I=TensorDef(T1),
102102
O=TensorDef(T1, output=True),
@@ -330,7 +330,7 @@ def min(
330330
O[None] = BinaryFn.min_signed(lhs[None], rhs[None])
331331

332332

333-
@linalg_structured_op
333+
@linalg_structured_op(op_class_name="PowFOp")
334334
def powf(
335335
lhs=TensorDef(T1),
336336
rhs=TensorDef(T1),

mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22

33
# Just verify that at least one known op is generated.
44
# CHECK: name: matmul
5+
6+
# verify some special cases: negf->NegFOp, powf->PowFOp
7+
# CHECK cpp_class_name: NegFOp
8+
# CHECK cpp_class_name: PowFOp

0 commit comments

Comments
 (0)