Skip to content

[MLIR][CAPI][python] expose the python binding for linalgOp.getIndexingMaps #136054

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 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions mlir/lib/Bindings/Python/DialectLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ static void populateDialectLinalgSubmodule(nb::module_ m) {
m.def("infer_convolution_dimensions", &InferConvolutionDimensions,
"Infers convolution dimensions", nb::arg("op"));

m.def("get_indexing_maps_attr", &mlirLinalgGetIndexingMapsAttribute,
"Returns the indexing_maps or memoized_indexing_maps attribute for a "
"Linalg op.",
nb::arg("op"));
m.def(
"get_indexing_maps_attr",
[](MlirOperation op) -> std::optional<MlirAttribute> {
MlirAttribute attr = mlirLinalgGetIndexingMapsAttribute(op);
if (mlirAttributeIsNull(attr))
return std::nullopt;
return attr;
},
"Returns the indexing_maps attribute for a linalg op.");
}

NB_MODULE(_mlirDialectsLinalg, m) {
Expand Down
6 changes: 4 additions & 2 deletions mlir/test/python/dialects/linalg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,18 @@ def test_get_indexing_maps_attr():
@func.FuncOp.from_py_func(a_type, b_type, c_type)
def matmul_func(a, b, c):
zero = arith.ConstantOp(value=FloatAttr.get(f32, 0.0), result=f32)
assert not linalg.get_indexing_maps_attr(
zero.operation
), "Expected no indexing_maps on non-linalg op"

init = linalg.fill(zero, outs=[c])
fill_op = init.owner

fill_maps = linalg.get_indexing_maps_attr(fill_op)
assert fill_maps is not None
assert len(fill_maps) == 2

# The fill op should have maps like (d0, d1) -> () and (d0, d1).
fill_input_map = fill_maps[0].value
print(type(fill_input_map))
fill_output_map = fill_maps[1].value
assert fill_input_map == AffineMap.get(2, 0, [])
assert fill_output_map == AffineMap.get(2, 0, [dim_m, dim_n])
Expand Down
Loading