This is an archive of the discontinued LLVM Phabricator instance.

[mlir][SCF] ValueBoundsOpInterface: Support `scf.for` results and iter_args
ClosedPublic

Authored by springerm on Mar 17 2023, 9:26 AM.

Details

Summary

If an scf.for loop yields an equal index-typed value or a shaped value with the same dimension sizes (in comparison to the corresponding iter_arg), bounds can be computed for the iter_arg and the OpResult of the scf.for op.

This change also adds a dim parameter to stopCondition.

Depends On: D146296

Diff Detail

Event Timeline

springerm created this revision.Mar 17 2023, 9:26 AM
springerm requested review of this revision.Mar 17 2023, 9:26 AM
springerm updated this revision to Diff 509970.Mar 31 2023, 3:30 AM

update API

dcaballe accepted this revision.Apr 6 2023, 4:03 PM

LGTM! Minor comments

mlir/include/mlir/Interfaces/ValueBoundsOpInterface.h
40–41

doc about the arguments?

73

Could you elaborate a bit more on that dependencies are actually used to create the stopCondition function?

mlir/lib/Dialect/Affine/Transforms/ReifyValueBounds.cpp
21–22

update doc

mlir/lib/Dialect/SCF/IR/ValueBoundsOpInterfaceImpl.cpp
26

It looks like the name dim is no longer accurate? Fof scf.for it represents the result index, which is not really a dim? I can't think of a better name, though, other than index...

30

-> dyn_cast new convention

39

I guess there is no gracefully way fail here because if we move forward we might return a incorrect bound...

66

dyn_cast

mlir/test/Dialect/SCF/value-bounds-op-interface-impl.mlir
46

This is pretty cool! We are able to infer that we are actually returning %arg, which is %i

This revision is now accepted and ready to land.Apr 6 2023, 4:03 PM
springerm marked 8 inline comments as done.Apr 6 2023, 7:57 PM
springerm added inline comments.
mlir/lib/Dialect/Affine/Transforms/ReifyValueBounds.cpp
21–22

Nothing to update here. The new parameter is not used. But I fixed a typo.

mlir/lib/Dialect/SCF/IR/ValueBoundsOpInterfaceImpl.cpp
26

dim is still the right name here. This does not refer to the induction variable here. E.g., we could be trying to compute a bound for a shape typed iter_arg.

scf.for ... iter_args(%arg0 = %t) -> tensor<?xf32> {
  "test.reify_bound"(%arg0) {dim = 0}
}
30

This does not work for OpFoldResult yet.

39

The region of the op is SizedRegion<1>:$region, so it guaranteed to have only 1 block. This is just for extra safety.

66

Does not work for OpFoldResult yet.

This revision was automatically updated to reflect the committed changes.
springerm marked 5 inline comments as done.