This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Adopt `DenseI64ArrayAttr` in tensor, memref and linalg transform
ClosedPublic

Authored by chelini on Nov 23 2022, 4:48 AM.

Details

Summary

This commit is a first step toward removing inconsistencies between dynamic
and static attributes (i64 v. index) by dropping I64ArrayAttr and
using DenseI64ArrayAttr in Tensor, Memref and Linalg Transform ops.
In Linalg Transform ops only TileToScfForOp and TileOp have been updated.

See related discussion: https://discourse.llvm.org/t/rfc-inconsistency-between-dynamic-and-static-attributes-i64-v-index/66612/1

Diff Detail

Event Timeline

chelini created this revision.Nov 23 2022, 4:48 AM
Herald added a project: Restricted Project. · View Herald Transcript
chelini requested review of this revision.Nov 23 2022, 4:48 AM

Please consider this a work in progress. Before finalizing, I do have some comments and questions:
a) getMixedValues now requires an extra parameter, an MLIRContext, as we need a builder to create an attribute from an int64_t (staticValues). Do you see any problem with this API change? Do you see better alternatives?
b) The attribute interchange in transform.structured.tile now requires adding array<i64: something as the syntax of dense attribute differs if we use ODS or custom parser/printer (see: https://github.com/llvm/llvm-project/commit/2092d1438c36606d82df20fd36f16de033d31147). I suggested moving transform.structured.tile to use ODS and avoid a custom printer/parser. What do you think? 
c) Do you know how to create a DenseXXXArrayAttr using the Python API?

chelini retitled this revision from [MLIR] Adopt `DenseI64ArrayAttr` in tensor, memeref and linalg transform to [MLIR] Adopt `DenseI64ArrayAttr` in tensor, memref and linalg transform.

Please consider this a work in progress. Before finalizing, I do have some comments and questions:
a) getMixedValues now requires an extra parameter, an MLIRContext, as we need a builder to create an attribute from an int64_t (staticValues). Do you see any problem with this API change? Do you see better alternatives?

See suggestions inline.

b) The attribute interchange in transform.structured.tile now requires adding array<i64: something as the syntax of dense attribute differs if we use ODS or custom parser/printer (see: https://github.com/llvm/llvm-project/commit/2092d1438c36606d82df20fd36f16de033d31147). I suggested moving transform.structured.tile to use ODS and avoid a custom printer/parser. What do you think? 

Yes please!

c) Do you know how to create a DenseXXXArrayAttr using the Python API?

@ftynse ?

mlir/include/mlir/Interfaces/ViewLikeInterface.h
27–28

drop the , 4 part

27–28

This could move to include/mlir/Dialect/Utils/StaticValueUtils.h

27–28

This could take a Builder, to be consistent with the helper below.

33

This could also move to include/mlir/Dialect/Utils/StaticValueUtils.h

c) Do you know how to create a DenseXXXArrayAttr using the Python API?

@ftynse ?

mlir.ir.DenseXXXArrayAttr.get(...)? Python API is quite self-consistent.

chelini updated this revision to Diff 477724.Nov 24 2022, 3:33 AM
  • Fix python tests
  • getMixedValues now takes a builder
chelini marked 2 inline comments as done.Nov 24 2022, 3:33 AM
chelini updated this revision to Diff 477732.Nov 24 2022, 3:52 AM

Move getMixedValues and decomposeMixedValues in StaticValueUtils.h

chelini marked 2 inline comments as done.Nov 24 2022, 3:52 AM

@nicolasvasilache and @ftynse, I made the changes suggested and fixed the Python tests. I am now looking into how we can use the assembly form for TileOp, but it isn't possible to specify the number or results (i.e., loops) based on some constraints in ODS (i.e., tile size equals 0). See: https://github.com/llvm/llvm-project/blob/15e76eed0c7662f8a4bce849a58637070d3b0a75/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp#L1330
If we want to be consistent, we need to modify the parser and printer of DynamicIndexList to parse print array<i64: something>, making the IR more verbose but consistent. Thoughts or suggestions? I am asking because DynamicIndexList touches a lot of operations and I want to agree on the changes before doing.

It is possible to pass a reference to something into a custom printer/parser directive. So you can have an additional custom directive that "parses" the results and takes a reference to the "tile size" attribute. It then doesn't actually parse anything, but populates the list of result types based on the content of the attribute. It's hacky but should work.

mlir/python/mlir/dialects/_structured_transform_ops_ext.py
52

Nit: call this _get_dense_int64_array_attr in case somebody will eventually need a different width.

chelini updated this revision to Diff 477808.Nov 24 2022, 8:36 AM
  • _get_dense_int_array_attr -> _get_dense_int64_array_attr
  • Change parser/printer for TileOp and TileToScfForOp to parse the short form of DenseI64ArrayAttr to be consistent with what we parse via parseDynamicIndexList.
chelini marked an inline comment as done.Nov 24 2022, 8:36 AM
chelini edited the summary of this revision. (Show Details)Nov 24 2022, 8:41 AM
chelini updated this revision to Diff 477863.Nov 24 2022, 11:55 PM

It turned out that there is a way to print a DenseXXXArrayAttr in C++ using the
short form: see https://reviews.llvm.org/D132758. Adjust the code.

Nice cleanup, thanks @chelini !

This revision is now accepted and ready to land.Nov 25 2022, 12:18 AM

Thanks for doing this @chelini!