This is an archive of the discontinued LLVM Phabricator instance.

Enhance pad transform to handle scf.for producers.
AbandonedPublic

Authored by hanchung on Feb 7 2022, 7:57 PM.

Details

Summary

When padding Linalg input operands, we assumed that the producer are only from
tensor.extract_slice ops. However, this does not work with fusion. In the case
of linalg.matmul + linalg.generic op, we could tile reduction dim firstly. Then
we pad all the Linalg inputs. This pattern would make the result of scf.for be
one of linalg.generic inputs. To handle this case, we have to propagate the
information from scf.for ops, i.e., get the information from the iter_args.

Diff Detail

Event Timeline

hanchung created this revision.Feb 7 2022, 7:57 PM
hanchung updated this revision to Diff 406689.Feb 7 2022, 8:20 PM
This comment was removed by hanchung.
hanchung published this revision for review.Feb 7 2022, 8:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2022, 8:22 PM
gysit added a comment.EditedFeb 7 2022, 11:34 PM

Thanks for identifying the issue! This patch unfortunately reminds me of some dim op canonicalization pattern discussion in the past. The question there was if a dynamic tensor passed as an iteration argument to a for loop has the same shape in every loop iteration. The answer was unfortunately no in general. That means with your patch we may get a wrong shape in general. However, in the context of Linalg the shape of an iteration argument never changes. So it may be OK to assume iteration argument and result have the same shape here. @nicolasvasilache what is your opinion here?

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
184

There is a helper function to get the op operand directly, which should work similar to the following code:

while (auto forOp = opOperand->get().getDefiningOp<scf::ForOp>()) {
  OpResult result = opOperand->get().cast<OpResult>();
  opOperand = &forOp.getOpOperandForResult(result);
}
hanchung updated this revision to Diff 406979.Feb 8 2022, 2:37 PM

Address comments

hanchung planned changes to this revision.Feb 9 2022, 5:43 PM

We might want https://reviews.llvm.org/D119390 instead because scf.for iter types might change during runtime.

hanchung abandoned this revision.Mar 29 2022, 5:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 5:24 PM