Skip to content

[mlir][python] Expose transform param types #67421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions mlir/include/mlir-c/Dialect/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyOpType(MlirType type);

MLIR_CAPI_EXPORTED MlirType mlirTransformAnyOpTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// AnyParamType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyParamType(MlirType type);

MLIR_CAPI_EXPORTED MlirType mlirTransformAnyParamTypeGet(MlirContext ctx);

//===---------------------------------------------------------------------===//
// AnyValueType
//===---------------------------------------------------------------------===//
Expand All @@ -49,6 +57,17 @@ mlirTransformOperationTypeGet(MlirContext ctx, MlirStringRef operationName);
MLIR_CAPI_EXPORTED MlirStringRef
mlirTransformOperationTypeGetOperationName(MlirType type);

//===---------------------------------------------------------------------===//
// ParamType
//===---------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool mlirTypeIsATransformParamType(MlirType type);

MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGet(MlirContext ctx,
MlirType type);

MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGetType(MlirType type);

#ifdef __cplusplus
}
#endif
Expand Down
35 changes: 35 additions & 0 deletions mlir/lib/Bindings/Python/DialectTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ void populateDialectTransformSubmodule(const pybind11::module &m) {
"Get an instance of AnyOpType in the given context.", py::arg("cls"),
py::arg("context") = py::none());

//===-------------------------------------------------------------------===//
// AnyParamType
//===-------------------------------------------------------------------===//

auto anyParamType =
mlir_type_subclass(m, "AnyParamType", mlirTypeIsATransformAnyParamType);
anyParamType.def_classmethod(
"get",
[](py::object cls, MlirContext ctx) {
return cls(mlirTransformAnyParamTypeGet(ctx));
},
"Get an instance of AnyParamType in the given context.", py::arg("cls"),
py::arg("context") = py::none());

//===-------------------------------------------------------------------===//
// AnyValueType
//===-------------------------------------------------------------------===//
Expand Down Expand Up @@ -71,6 +85,27 @@ void populateDialectTransformSubmodule(const pybind11::module &m) {
return py::str(operationName.data, operationName.length);
},
"Get the name of the payload operation accepted by the handle.");

//===-------------------------------------------------------------------===//
// ParamType
//===-------------------------------------------------------------------===//

auto paramType =
mlir_type_subclass(m, "ParamType", mlirTypeIsATransformParamType);
paramType.def_classmethod(
"get",
[](py::object cls, MlirType type, MlirContext ctx) {
return cls(mlirTransformParamTypeGet(ctx, type));
},
"Get an instance of ParamType for the given type in the given context.",
py::arg("cls"), py::arg("type"), py::arg("context") = py::none());
paramType.def_property_readonly(
"type",
[](MlirType type) {
MlirType paramType = mlirTransformParamTypeGetType(type);
return paramType;
},
"Get the type this ParamType is associated with.");
}

PYBIND11_MODULE(_mlirDialectsTransform, m) {
Expand Down
28 changes: 28 additions & 0 deletions mlir/lib/CAPI/Dialect/Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ MlirType mlirTransformAnyOpTypeGet(MlirContext ctx) {
return wrap(transform::AnyOpType::get(unwrap(ctx)));
}

//===---------------------------------------------------------------------===//
// AnyParamType
//===---------------------------------------------------------------------===//

bool mlirTypeIsATransformAnyParamType(MlirType type) {
return isa<transform::AnyParamType>(unwrap(type));
}

MlirType mlirTransformAnyParamTypeGet(MlirContext ctx) {
return wrap(transform::AnyParamType::get(unwrap(ctx)));
}

//===---------------------------------------------------------------------===//
// AnyValueType
//===---------------------------------------------------------------------===//
Expand Down Expand Up @@ -62,3 +74,19 @@ MlirType mlirTransformOperationTypeGet(MlirContext ctx,
MlirStringRef mlirTransformOperationTypeGetOperationName(MlirType type) {
return wrap(cast<transform::OperationType>(unwrap(type)).getOperationName());
}

//===---------------------------------------------------------------------===//
// AnyOpType
//===---------------------------------------------------------------------===//

bool mlirTypeIsATransformParamType(MlirType type) {
return isa<transform::ParamType>(unwrap(type));
}

MlirType mlirTransformParamTypeGet(MlirContext ctx, MlirType type) {
return wrap(transform::ParamType::get(unwrap(ctx), unwrap(type)));
}

MlirType mlirTransformParamTypeGetType(MlirType type) {
return wrap(cast<transform::ParamType>(unwrap(type)).getType());
}
10 changes: 10 additions & 0 deletions mlir/test/python/dialects/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def testTypes():
any_op = transform.AnyOpType.get()
print(any_op)

# CHECK: !transform.any_param
any_param = transform.AnyParamType.get()
print(any_param)

# CHECK: !transform.any_value
any_value = transform.AnyValueType.get()
print(any_value)
Expand All @@ -32,6 +36,12 @@ def testTypes():
print(concrete_op)
print(concrete_op.operation_name)

# CHECK: !transform.param<i32>
# CHECK: i32
param = transform.ParamType.get(IntegerType.get_signless(32))
print(param)
print(param.type)


@run
def testSequenceOp():
Expand Down