diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -1050,6 +1050,19 @@ }, py::arg("offset"), py::arg("strides"), py::arg("context") = py::none(), "Gets a strided layout attribute."); + c.def_static( + "get_fully_dynamic", + [](int64_t rank, DefaultingPyMlirContext ctx) { + auto dynamic = mlirShapedTypeGetDynamicStrideOrOffset(); + std::vector strides(rank); + std::fill(strides.begin(), strides.end(), dynamic); + MlirAttribute attr = mlirStridedLayoutAttrGet( + ctx->get(), dynamic, strides.size(), strides.data()); + return PyStridedLayoutAttribute(ctx->getRef(), attr); + }, + py::arg("rank"), py::arg("context") = py::none(), + "Gets a strided layout attribute with dynamic offset and strides of a " + "given rank."); c.def_property_readonly( "offset", [](PyStridedLayoutAttribute &self) { diff --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py --- a/mlir/test/python/ir/attributes.py +++ b/mlir/test/python/ir/attributes.py @@ -542,3 +542,14 @@ print(attr.strides[1]) # CHECK: 13 print(attr.strides[2]) + + attr = StridedLayoutAttr.get_fully_dynamic(3) + dynamic = ShapedType.get_dynamic_stride_or_offset() + # CHECK: strided<[?, ?, ?], offset: ?> + print(attr) + # CHECK: offset is dynamic: True + print(f"offset is dynamic: {attr.offset == dynamic}") + # CHECK: rank: 3 + print(f"rank: {len(attr.strides)}") + # CHECK: strides are dynamic: [True, True, True] + print(f"strides are dynamic: {[s == dynamic for s in attr.strides]}")