This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Add vectorization support for conv_1d
ClosedPublic

Authored by devajith-huawei on Mar 2 2023, 6:49 AM.

Details

Summary

This MR add vectorization support for linalg.conv_1D operation.

Diff Detail

Event Timeline

devajith-huawei created this revision.Mar 2 2023, 6:49 AM
Herald added a project: Restricted Project. · View Herald Transcript
devajith-huawei requested review of this revision.Mar 2 2023, 6:49 AM
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
2024

Thanks for your contribution!

Can we extract all these if/else into separate static helper functions with the right parameters and proper doc comment?
This is starting to look too much like spaghetti and will be hard to further evolve.

vmurali added a subscriber: vmurali.Mar 2 2023, 7:43 AM
vmurali added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
1876–1879

Can we please not apply demorgan's law ourselves, and let the compiler optimize it if it wants - this condition is getting way too complicated to apply demorgan's law ourself. Instead write it as:

if (!((lhsShapedType.getRank() == 3 && resShapedType.getRank() == 3) ||
       (lhsShapedType.getRank() == 3 && resShapedType.getRank() == 3)))
  return;

And that is exactly what the comment says.

vmurali added inline comments.Mar 2 2023, 7:45 AM
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
1876–1879
if (!((lhsShapedType.getRank() == 3 && resShapedType.getRank() == 3) ||
      (lhsShapedType.getRank() == 1 && resShapedType.getRank() == 1)))
  return;

(Fixed the expression)

devajith-huawei added inline comments.Mar 2 2023, 8:41 AM
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
2024

Thank you!

In this case, should the code look like the following after adding the helper functions?

auto lhs = readConvSlice(loc, lhsType, lhsShaped, conv1DOpOrder, oper);
auto rhs = readConvSlice(loc, rhsType, rhsType, conv1DOpOrder, oper);
auto lhs = readConvSlice(loc, resType, resShaped, conv1DOpOrder, oper);
devajith-huawei marked an inline comment as not done.Mar 2 2023, 12:26 PM

Build fails due to "mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp" not formatted (clang-format) properly in the current upstream branch. Not sure if the formatting change should go with this MR.

vmurali requested changes to this revision.Mar 2 2023, 12:27 PM
vmurali added a reviewer: vmurali.
This revision now requires changes to proceed.Mar 2 2023, 12:28 PM
  • Fixed expression to match the comment (not applying demorgan's law ourselves) @vmurali
  • Extracted conv_1d if/else into separate static helper functions with the right parameters and proper doc comment @nicolasvasilache
  • Fixed a formatting error causing build error (clang format applied to the whole file and not just the diff).
vmurali accepted this revision.Mar 3 2023, 7:59 AM

Please wait for others to chime in. I am fine with the current patch.

This revision is now accepted and ready to land.Mar 3 2023, 7:59 AM
dcaballe accepted this revision.Mar 3 2023, 11:47 AM

Thanks for the contribution! Just a couple of nits! LGTM

mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
126–140

Move loop invariant ArrayRefs to SmallVectors outside the loop?

149

SmallVector -> SmallVectorImpl?

Build fails due to "mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp" not formatted (clang-format) properly in the current upstream branch. Not sure if the formatting change should go with this MR.

Feel free to submit a separate patch with the formatting fixes.

Build fails due to "mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp" not formatted (clang-format) properly in the current upstream branch. Not sure if the formatting change should go with this MR.

Feel free to submit a separate patch with the formatting fixes.

I've made a separate patch here: https://reviews.llvm.org/D145267

nicolasvasilache accepted this revision.Mar 6 2023, 7:14 AM

Nice, thank you!

Updated the same diff with context.

hanchung accepted this revision.Mar 6 2023, 10:14 AM
hanchung added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
2671

Maybe rename this to generateNonChanneledConv?

Renamed generateConv -> generateNonChanneledConv

devajith-huawei marked an inline comment as done.Mar 7 2023, 1:40 AM
devajith-huawei added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
2671

Thanks. Renamed!

It will be great if someone can commit this for me (if it is good to go).

It will be great if someone can commit this for me (if it is good to go).

I can help land the commit. Your git commit author information is not preserved after I apply the patch locally. Let me know what author information you'd like to put in the landing. E.g., mine is "Hanhan Wang <hanchung@google.com>".

You can either comment the information here or send a mail to hanchung@google.com. Both work for me.

This comment was removed by devajith-huawei.

It will be great if someone can commit this for me (if it is good to go).

I can help land the commit. Your git commit author information is not preserved after I apply the patch locally. Let me know what author information you'd like to put in the landing. E.g., mine is "Hanhan Wang <hanchung@google.com>".

You can either comment the information here or send a mail to hanchung@google.com. Both work for me.

Thank you very much @hanchung.
Author information: "Devajith Valaparambil Sreeramaswamy <devajith.sreeramaswamy@huawei.com>".

Same for the patch https://reviews.llvm.org/D145162.

This revision was automatically updated to reflect the committed changes.