Skip to content

Disable LLVM's vectorizers by default - #9642

Merged
dcaballe merged 4 commits into
iree-org:mainfrom
dcaballe:measure-lv-impact
Jul 12, 2022
Merged

dcaballe merged 4 commits into
iree-org:mainfrom
dcaballe:measure-lv-impact

Conversation

@dcaballe

@dcaballe dcaballe commented Jun 28, 2022 •

Copy link
Copy Markdown
Contributor

This PR disables both LLVM’s loop and SLP vectorizers from our pipeline by default. We can still enable them on demand with flags iree-llvm-loop-vectorization and iree-llvm-slp-vectorization. Relying on LLVM vectorization (and unrolling) is dangerous since we may inadvertently reach wrong conclusions when evaluating the performance of new tiling/vectorization/unrolling features/configurations. For example, we might enable new vectorization features in MLIR to target non-vectorized code and observe no performance change or even a regression because the target code was being vectorized/unrolled by LLVM. We can enable it back if we observe significant regressions but our current benchmarks don't seem to point to that.

@iree-github-actions-bot

iree-github-actions-bot commented Jun 28, 2022 •

Copy link
Copy Markdown
Contributor

Abbreviated x86_64 Benchmark Summary (experimental)

@ commit 7e48ae6764051ba676d8698219baf0172a88d79a (vs. base 70503f2bd89e525482b24bf1cd8407eb6f769b06)

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
PoseNet [fp32] (TFLite) 4-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 9 (vs. 10, 10.00%↓) 9 0
DeepLabV3 [fp32] (TFLite) full-inference,default-flags with IREE-Dylib-Sync @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 28 (vs. 31, 9.68%↓) 28 0
DeepLabV3 [fp32] (TFLite) 1-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 30 (vs. 33, 9.09%↓) 30 0

[Top 3 out of 7 results showed]

No improved or regressed compilation metrics 🏖️

For more information:

@iree-github-actions-bot

iree-github-actions-bot commented Jun 28, 2022 •

Copy link
Copy Markdown
Contributor

Abbreviated Benchmark Summary

@ commit 957ae7d2bf336263c8f8f7dd6475047f1828fe9d (vs. base b16530057e05fb51d23a9a96946b46eb6eb83414)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileBertSquad [int8] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 238 (vs. 208, 14.42%↑) 238 1
MobileBertSquad [fp32] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-6-Pro (CPU-ARMv8.2-A) 441 (vs. 408, 8.09%↑) 450 24
DeepLabV3 [fp32] (TFLite) little-core,full-inference,default-flags with IREE-Dylib-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 430 (vs. 406, 5.91%↑) 432 5

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
DeepLabV3 [fp32] (TFLite) 4-thread,little-core,full-inference,default-flags with IREE-Dylib @ Pixel-6-Pro (CPU-ARMv8.2-A) 138 (vs. 160, 13.75%↓) 137 9
MobileBertSquad [fp32] (TFLite) little-core,full-inference,default-flags with IREE-Dylib-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 3935 (vs. 4173, 5.70%↓) 3836 133

No improved or regressed compilation metrics 🏖️

For more information:

@dcaballe dcaballe changed the title Measure performance impact of LLVM's Loop Vectorizer Disable LLVM's Vectorizers by default Jun 28, 2022
@dcaballe dcaballe changed the title Disable LLVM's Vectorizers by default Disable LLVM's vectorizers by default Jun 28, 2022
@dcaballe
dcaballe marked this pull request as ready for review June 28, 2022 22:50
@dcaballe
dcaballe requested a review from benvanik as a code owner June 28, 2022 22:50
@ThomasRaoux

Copy link
Copy Markdown
Contributor

This PR disables both LLVM’s loop and SLP vectorizers from our pipeline by default. We can still enable them on demand with flags iree-llvm-loop-vectorization and iree-llvm-slp-vectorization. Relying on LLVM vectorization (and unrolling) is dangerous since we may inadvertently reach wrong conclusions when evaluating the performance of new tiling/vectorization/unrolling features/configurations. For example, we might enable new vectorization features in MLIR to target non-vectorized code and observe no performance change or even a regression because the target code was being vectorized/unrolled by LLVM. We can enable it back if we observe significant regressions but our current benchmarks don't seem to point to that.

big +1 for all this. I think relying on llvm vectorization hurt us in the past. I wonder if there is any benchmark we really don't want to regress we may want to look at. The only I'm thinking about is probably miniLM tracked by Nod team (cc @powderluv) but I think they can enable llvm vectorization on their side if there is a regression and they don't want to disturb their production flow.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

I approved but it would be good to have others weight in on this before merging it.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

If there is a regression, I would rather leave it on.

@bjacob

bjacob commented Jun 29, 2022

Copy link
Copy Markdown
Collaborator

+1, compiler auto vectorization was worth trying circa 2005 :-)

@ThomasRaoux

Copy link
Copy Markdown
Contributor

If there is a regression, I would rather leave it on.

interestingly there seem to be more improvements than regressions

@dcaballe

Copy link
Copy Markdown
Contributor Author

Yes, we won't be moving this PR forward unless everybody is ok with it and there are no relevant regressions. @powderluv, could you please give this a try and let us know? If there are major regressions we should at least identify where the gap is on our side and add it to our roadmap.

On the unrolling side, things look worse (#9658) and, IMO, having LLVM unrolling enabled by default is much more misleading/problematic. If we can't disable it by default, you should seriously consider disabling it when running a search.

@hanhanW

hanhanW commented Jun 29, 2022

Copy link
Copy Markdown
Contributor

It looks like there are no regressions for our tracking models. The flag was turned on by default long time ago. At that point, we haven't invested much effort on vectorization. It's good to see that we've improved the vectorization and we can disable the flag by default. It's easier to apply optimization ourselves and make sure LLVM doesn't break it. I'd suggest to disable them by default, and keep the flag for future evaluation/development.

The MiniLM Bert on x86 side is tracking on our dashboard, and it looks good. Nod folks can control the flag on their side. If there are mismatch between the flags, we should investigate the reason and file issues for tracking them.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Yes, we won't be moving this PR forward unless everybody is ok with it and there are no relevant regressions. @powderluv, could you please give this a try and let us know? If there are major regressions we should at least identify where the gap is on our side and add it to our roadmap.

On the unrolling side, things look worse (#9658) and, IMO, having LLVM unrolling enabled by default is much more misleading/problematic. If we can't disable it by default, you should seriously consider disabling it when running a search.

It's not surprising that disabling unrolling causes more problem as we haven't been doing much unrolling for ops others than GEMM. I do agree that relying on heuristic outside of IREE makes things very hard to tune so I think having it off by default makes our job simpler but I can see how it is a harder problem than auto-vectorization.

@hanhanW

hanhanW commented Jun 29, 2022

Copy link
Copy Markdown
Contributor

Unrolling is another interesting topic. IIRC, the flag was asked to be on by default for performance. We haven't prototyped loop/vector unrolling much at MLIR level in IREE, so I'm not surprised that there are regressions.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

+1, compiler auto vectorization was worth trying circa 2005 :-)
@bjacob we are trading one form of compiler auto-vectorization to another form of compiler auto-vectorization :)

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

I think everybody would like to get rid of using LLVM for vectorization and unrolling. There is a cost though associated with it. I think at this stage we might be relying on LLVM auto-vectorization only for pathological cases. So it shouldnt make a difference today w.r.t to performance whether we use it or not. So then not using makes sense.
I held the line for a long time on enabling LLVM unrolling by default. Finally couldnt argue with the numbers. Its not a few percentage difference, it is a few X difference. So then it becomes a matter of prioritization. So we took the easy way out to focus on other things. If someone is willing to put in the time, then definitely we should avoid using unrolling as well. If I had to pick using unrolling is more of an issue for me than using the LLVM auto-vectorizer. There are less heuristics involved in vectorization (more about if the compiler can find opportunities to vectorize). There are a lot more shady heuristics involved in unrolling.

@benvanik

Copy link
Copy Markdown
Collaborator

+1 Mahesh! We also haven't been looking at binary sizes enough - when not targeting HPC spending 400KB on a single dispatch isn't really a thing - unrolling the entire problem with an LLVM flag may let us punt on the hard solution but we're only punting it to ourselves: we also need to target non-HPC uses :)

@dcaballe

Copy link
Copy Markdown
Contributor Author

+1! Thanks for all the feedback and interesting discussion! I think we all agree on the direction. Disabling unrolling would require much more work so... let's take one step at a time :)
However, I think it's crucial that we take into account the unrolling situation when introducing new tiling configurations and conduct search experiments. If the tiling configuration is evaluated with LLVM unrolling enabled, we would be increasing our dependency with LLVM unrolling. If search is conducted with LLVM unrolling enabled, we may explore unroll configurations in MLIR that won't faithfully represent the actual unrolling applied at the end of the pipeline (e.g., a given tile size in MLIR may aim at unrolling a dimension by two; LLVM may unroll that dimension later even further).

@antiagainst

Copy link
Copy Markdown
Member

Awesome! Glad to see that we are putting more stuff into our own control with less surprises! On the SPIR-V side we are forced to do that given no existing LLVM functionalities to reuse and we are required to fix lots of cases in MLIR's vector transforms while LLVM side things just seem to work. It is certainly much better now and stressing it further from LLVM side would be even nicer!

@dcaballe

Copy link
Copy Markdown
Contributor Author

So... should we give this a try and see what happens? Worst case, we will have to revert but we'll have some specific models to look into and analyze what is missing on our side.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

So... should we give this a try and see what happens? Worst case, we will have to revert but we'll have some specific models to look into and analyze what is missing on our side.

Based on the response I think we have a consensus that turning off auto-vectorization is the way to go right now

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

I think everyone approved it :)

@iree-github-actions-bot

Copy link
Copy Markdown
Contributor

Abbreviated Linux Benchmark Summary

@ commit 957ae7d2bf336263c8f8f7dd6475047f1828fe9d (vs. base b16530057e05fb51d23a9a96946b46eb6eb83414)

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
DeepLabV3 [fp32] (TFLite) 4-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 13 (vs. 15, 13.33%↓) 13 0
PoseNet [fp32] (TFLite) 4-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 9 (vs. 10, 10.00%↓) 9 0
DeepLabV3 [fp32] (TFLite) full-inference,default-flags with IREE-Dylib-Sync @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 28 (vs. 31, 9.68%↓) 28 0

[Top 3 out of 9 results showed]

Improved Compilation Times 🎉

Benchmark Name Compilation Time (ms)
MobileSSD [fp32] (TFLite) CPU-x86\_64-CascadeLake full-inference,default-flags 20755 (vs. 25988, 20.14%↓)
MobileSSD [fp32] (TFLite) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 20755 (vs. 25988, 20.14%↓)
MobileSSD [fp32] (TFLite) CPU-x86\_64-CascadeLake 8-thread,full-inference,default-flags 20755 (vs. 25988, 20.14%↓)

[Top 3 out of 26 results showed]

Improved Total Dispatch Sizes 🎉

Benchmark Name Total Dispatch Size (bytes)
DeepLabV3 [fp32] (TFLite) CPU-RV64-Generic full-inference,default-flags 173816 (vs. 256616, 32.27%↓)
DeepLabV3 [fp32] (TFLite) CPU-x86\_64-CascadeLake full-inference,default-flags 181184 (vs. 260752, 30.51%↓)
DeepLabV3 [fp32] (TFLite) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 181184 (vs. 260752, 30.51%↓)

[Top 3 out of 22 results showed]

For more information:

@dcaballe
dcaballe merged commit a9c91cd into iree-org:main Jul 12, 2022
@dcaballe
dcaballe deleted the measure-lv-impact branch July 12, 2022 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants