[Mlir-commits] [mlir] [MLIR][Python] enhance python api for tensor.empty (PR #103087)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 13 18:03:15 PDT 2024
================
@@ -43,6 +44,18 @@ def __init__(
super().__init__(result_type, dynamic_sizes, loc=loc, ip=ip)
+def empty(
+ sizes: Sequence[Union[int, Value]],
+ element_type: Type,
+ *,
+ loc=None,
+ ip=None,
+) -> _ods_cext.ir.Value:
+ return _get_op_result_or_op_results(
+ EmptyOp(sizes=sizes, element_type=element_type, loc=loc, ip=ip)
+ )
----------------
xurui1995 wrote:
hi, @makslevental the signature is different, I know the existence of the generated `tensor.empty`, but we do not have any usage of that API, instead, what we are using is the extended `class EmptyOp(EmptyOp)` not the class `EmptyOp(_ods_ir.OpView)` , the signature is a little different and it was easier to use. so I am thinking adding `tensor.empty` method for this extended class.
After this, if users want to use the `tensor.empty`, they can change from `tensor.empty(RankedTensorType.get([3, 4], f32), [])` to ` tensor.empty([3, 4], f32)`
```
@_ods_cext.register_operation(_Dialect, replace=True)
class EmptyOp(EmptyOp):
"""Extends the tensor.empty op."""
def __init__(
self,
sizes: Sequence[Union[int, Value]],
element_type: Type,
*,
loc=None,
ip=None,
):
```
I found a code similar to this for extended `arith.ConstantOp` which has a manual `arith.constant` https://github.com/llvm/llvm-project/blob/16e22a6d49ee148b426cb4285aa479b327f3b0f7/mlir/python/mlir/dialects/arith.py#L107-L110
https://github.com/llvm/llvm-project/pull/103087
More information about the Mlir-commits
mailing list