Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize Linalg ops for dynamic cases. #8888

Merged
merged 3 commits into from
Apr 14, 2022
Merged

Conversation

hanhanW
Copy link
Contributor

@hanhanW hanhanW commented Apr 13, 2022

This is a fallback solution which tile dynamic dims with 1. The tiling logic of first level is not changed.

This adds more lit tests which include static cases and dynamic cases.

@hanhanW hanhanW marked this pull request as draft April 13, 2022 23:27
@hanhanW hanhanW added the (deprecated) buildkite:benchmark-android Deprecated. Please use benchmarks:android-* label Apr 13, 2022
@iree-github-actions-bot
Copy link
Contributor

iree-github-actions-bot commented Apr 14, 2022

Abbreviated Benchmark Summary

@ commit 3ea7d40312999f7828e882e86e81304774e84302 (vs. base 41ff121a12b06300227ae0f3bf95a5fca3dbd80d)

Regressed Benchmarks 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small [fp32,imagenet] (TFLite) 1-thread,big-core,full-inference,default-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 13 (vs. 12, 8.33%↑) 13 0
PoseNet [fp32] (TFLite) full-inference,default-flags with IREE-Vulkan @ Pixel-6-Pro (GPU-Mali-G78) 17 (vs. 16, 6.25%↑) 17 0
MobileBertSquad [fp32] (TFLite) little-core,full-inference,experimental-flags with IREE-Dylib-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 2888 (vs. 2739, 5.44%↑) 2891 15

[Top 3 out of 4 benchmark results showed]

Improved Benchmarks 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small [fp32,imagenet] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 10 (vs. 11, 9.09%↓) 10 0

For more information:

@hanhanW hanhanW marked this pull request as ready for review April 14, 2022 00:39
Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work for convolutions as well. Might be worth adding a lit test for that as well.

@hanhanW
Copy link
Contributor Author

hanhanW commented Apr 14, 2022

This should work for convolutions as well. Might be worth adding a lit test for that as well.

There are lit tests for dynamic and static convolutions. The change and test are included in this PR as well.

@hanhanW hanhanW enabled auto-merge (squash) April 14, 2022 19:13
SmallVectorImpl<int64_t> &reductionSizes) {
Optional<SmallVector<int64_t, 4>> staticLoopRanges = op.getStaticLoopRanges();
for (auto en :
llvm::enumerate(llvm::zip(*staticLoopRanges, op.iterator_types()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm a bit confused. I thought this would se tile sizes to 1 for dynamic dims but it's doing the opposite? Could you please add some doc to the method? That would be very helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the implementation is setting tile sizes to 1 for dynamic dims. If it is not dynamic dim, it will run into continue statement. If it is dynamic dim, the tile size will be set to 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed the ! :). Thanks for clarifying! In any case, I think it would be good to add a small doc comment to the method. It's not easy to infer that setAlwaysVectorizeSizes is only about dynamic dims.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, it's auto-merged. Good point, I'll send out a PR to add the comment!

static void setAlwaysVectorizeSizes(linalg::LinalgOp op,
SmallVectorImpl<int64_t> &parallelSizes,
SmallVectorImpl<int64_t> &reductionSizes) {
Optional<SmallVector<int64_t, 4>> staticLoopRanges = op.getStaticLoopRanges();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this crash if the op doesn't have static loop ranges? Maybe we should return gracefully intead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ShapedType::kDynamic (i.e., -1) will be returned if there are dynamic dims. It's very wrong if we can't get ranges. The ranges are inferred based on indexing_maps and operands. It should be an invalid Linalg op if we can't get ranges.

Maybe we should add it to upstream verifier and remove Optional from this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to removing Optional from there. Not sure why it was added to begin with. I think I reviewed that change and suggested dropping the Optional as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll update upstream method and send out fixes to IREE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could land this without those changes. If you look at the method today it never returns None

SmallVectorImpl<int64_t> &reductionSizes) {
Optional<SmallVector<int64_t, 4>> staticLoopRanges = op.getStaticLoopRanges();
for (auto en :
llvm::enumerate(llvm::zip(*staticLoopRanges, op.iterator_types()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed the ! :). Thanks for clarifying! In any case, I think it would be good to add a small doc comment to the method. It's not easy to infer that setAlwaysVectorizeSizes is only about dynamic dims.

@hanhanW hanhanW merged commit 81a9f30 into iree-org:main Apr 14, 2022
@hanhanW hanhanW deleted the always-vec branch April 14, 2022 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(deprecated) buildkite:benchmark-android Deprecated. Please use benchmarks:android-*
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants