This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add `ComplexType` conversion support for `convertScalarToDtype`
ClosedPublic

Authored by rsuderman on Jul 7 2023, 12:43 PM.

Details

Summary

Linalg operations can include complex types in the src/target types.
This should include conversion between arith and complex types when
constructing linalg operations.

Diff Detail

Event Timeline

rsuderman created this revision.Jul 7 2023, 12:43 PM
Herald added a project: Restricted Project. · View Herald Transcript
rsuderman requested review of this revision.Jul 7 2023, 12:43 PM
kuhar added inline comments.Jul 7 2023, 1:38 PM
mlir/lib/Dialect/Arith/Utils/Utils.cpp
126

nit: this function seems to be getting long, I wonder if a type switch and dispatching to helper functions would help here

149

nit: use free cast functions: https://mlir.llvm.org/deprecation/

also below

rsuderman updated this revision to Diff 538280.Jul 7 2023, 3:14 PM

Factored into helper functions and performed general var name cleanup.

rsuderman marked 2 inline comments as done.Jul 7 2023, 3:14 PM
jpienaar added inline comments.
mlir/lib/Dialect/Arith/Utils/Utils.cpp
127

Should operand be returned if width is equal or is it expected that canonicalized or fold would have handled that?

rsuderman updated this revision to Diff 538292.Jul 7 2023, 3:56 PM

Add operand bailout

rsuderman marked an inline comment as done.Jul 7 2023, 3:57 PM
rsuderman added inline comments.
mlir/lib/Dialect/Arith/Utils/Utils.cpp
127

Added the return operand;. It was technically unnecessary due to the parent function checking quality, but best to handle defense in depth.

jpienaar added inline comments.Jul 11 2023, 9:45 AM
mlir/lib/Dialect/Arith/Utils/CMakeLists.txt
9

This feels off.

rsuderman marked an inline comment as done.Jul 11 2023, 2:59 PM
rsuderman added inline comments.
mlir/lib/Dialect/Arith/Utils/CMakeLists.txt
9

I agree. The question is where would be the right place to move the conversion?

kuhar added a comment.Jul 12 2023, 1:13 PM

Do you plan to add some tests, or is this covered by some existing one?

Do you plan to add some tests, or is this covered by some existing one?

Happy to add some. I am less familiar with this area in the codebase so thoughts on how / where to test is appreciate.

mravishankar added inline comments.Jul 12 2023, 4:21 PM
mlir/lib/Dialect/Arith/Utils/Utils.cpp
97

Nit: I think the static methods need some comments to say what each one of these are for? Also maybe call this convertScalarToIntDtype and so on to make it clearer that these are implementations of parts of convertScalarToDtype?

kuhar added a comment.Jul 12 2023, 6:34 PM

Do you plan to add some tests, or is this covered by some existing one?

Happy to add some. I am less familiar with this area in the codebase so thoughts on how / where to test is appreciate.

I checked and the code from this patch is not exercised by any lit test. The helper is used with the other types in these:

Dialect/Linalg/IR/LinalgOps.cpp
Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp
Dialect/SparseTensor/Transforms/CodegenUtils.cpp

So I'd think we either add some linalg/sparse tensor tests, or a new test pass.

Added testing and added complex type support for ConvertConv2DtoImg2Col

Do you plan to add some tests, or is this covered by some existing one?

Happy to add some. I am less familiar with this area in the codebase so thoughts on how / where to test is appreciate.

I checked and the code from this patch is not exercised by any lit test. The helper is used with the other types in these:

Dialect/Linalg/IR/LinalgOps.cpp
Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp
Dialect/SparseTensor/Transforms/CodegenUtils.cpp

So I'd think we either add some linalg/sparse tensor tests, or a new test pass.

Added tests to the Img2Col case. This included fixing the pass to work for complex types and expanding support for mixed types.

rsuderman marked an inline comment as done.Jul 14 2023, 1:08 PM
kuhar accepted this revision.Jul 14 2023, 6:30 PM

LGTM

This revision is now accepted and ready to land.Jul 14 2023, 6:30 PM