Skip to content

[mlir] Makes zip_shortest an optional keyword in transform.foreach #98492

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
Jul 19, 2024
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
5 changes: 3 additions & 2 deletions mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,12 @@ def ForeachOp : TransformDialectOp<"foreach",
}];

let arguments = (ins Variadic<Transform_AnyHandleOrParamType>:$targets,
UnitAttr:$zip_shortest);
UnitAttr:$with_zip_shortest);
let results = (outs Variadic<Transform_AnyHandleOrParamType>:$results);
let regions = (region SizedRegion<1>:$body);
let assemblyFormat =
"$targets attr-dict `:` type($targets) (`->` type($results)^)? $body";
"$targets oilist(`with_zip_shortest` $with_zip_shortest) `:` "
"type($targets) (`->` type($results)^)? $body attr-dict";
let hasVerifier = 1;

let extraClassDeclaration = [{
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/Transform/IR/TransformOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,11 +1396,11 @@ transform::ForeachOp::apply(transform::TransformRewriter &rewriter,
SmallVector<SmallVector<MappedValue>> payloads;
detail::prepareValueMappings(payloads, getTargets(), state);
size_t numIterations = payloads.empty() ? 0 : payloads.front().size();
bool isZipShortest = getZipShortest();
bool withZipShortest = getWithZipShortest();

// In case of `zip_shortest`, set the number of iterations to the
// smallest payload in the targets.
if (isZipShortest) {
if (withZipShortest) {
numIterations =
llvm::min_element(payloads, [&](const SmallVector<MappedValue> &A,
const SmallVector<MappedValue> &B) {
Expand All @@ -1414,7 +1414,7 @@ transform::ForeachOp::apply(transform::TransformRewriter &rewriter,
// As we will be "zipping" over them, check all payloads have the same size.
// `zip_shortest` adjusts all payloads to the same size, so skip this check
// when true.
for (size_t argIdx = 1; !isZipShortest && argIdx < payloads.size();
for (size_t argIdx = 1; !withZipShortest && argIdx < payloads.size();
argIdx++) {
if (payloads[argIdx].size() != numIterations) {
return emitSilenceableError()
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/Linalg/continuous-tiling-full.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module attributes {transform.with_named_sequence} {
%0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op
%tile_sizes, %chunk_sizes = transform.structured.continuous_tile_sizes %0 { dimension = 0, target_size = 9 } : (!transform.any_op) -> !transform.any_op
%linalg_splits, %empty = transform.structured.split %0 after %chunk_sizes { dimension = 0, multiway } : !transform.any_op, !transform.any_op
transform.foreach %linalg_splits, %tile_sizes {zip_shortest} : !transform.any_op, !transform.any_op {
transform.foreach %linalg_splits, %tile_sizes with_zip_shortest : !transform.any_op, !transform.any_op {
^bb1(%linalg_split: !transform.any_op, %tile_size: !transform.any_op):
%tiled_linalg_split, %dim0_loop = transform.structured.tile_using_for %linalg_split tile_sizes [%tile_size] : (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
transform.yield
Expand Down
Loading