Skip to content

A pipeline for multi level tiling and vectorization of linalg ops on tensors - #7038

Merged
asaadaldien merged 3 commits into
mainfrom
ataei-tile_and_vectorize
Sep 15, 2021
Merged

asaadaldien merged 3 commits into
mainfrom
ataei-tile_and_vectorize

Conversation

@asaadaldien

@asaadaldien asaadaldien commented Sep 14, 2021 •

Copy link
Copy Markdown
Contributor
  • A new pipeline to tile and vectorize linalg ops on tensors prior to bufferization.
  • Drop padding from tile-pad-and-vectorize pass and use it as the tensor -> vector pass.
  • Enable the new pipeline for matmul, dot benchmarks shows no regressions, also looking at the IR at the buffer level its identical:
Baseline:
------------------------------------------------------------------------------------
Benchmark                                          Time             CPU   Iterations
------------------------------------------------------------------------------------
BM_dot_384x384x512/process_time/real_time       5.23 ms         5.22 ms          132
BM_dot_384x128x128/process_time/real_time      0.406 ms        0.405 ms         1749
BM_dot_384x128x512/process_time/real_time       1.70 ms         1.70 ms          411
BM_dot_384x512x128/process_time/real_time       1.52 ms         1.52 ms          461
BM_dot_384x512x2/process_time/real_time        0.502 ms        0.501 ms         1393
BM_dot_384x384x32/process_time/real_time       0.272 ms        0.272 ms         2569
BM_dot_1x1024x1024/process_time/real_time       1.94 ms         1.93 ms          360
BM_dot_1x1024x2048/process_time/real_time       6.59 ms         6.55 ms          106
BM_dot_1x1024x3072/process_time/real_time       7.10 ms         7.06 ms           98
BM_dot_1x1024x512/process_time/real_time       0.723 ms        0.721 ms          968
BM_dot_1x128x2/process_time/real_time          0.003 ms        0.003 ms       261416
BM_dot_1x256x512/process_time/real_time        0.166 ms        0.166 ms         4212
BM_dot_1x3072x1024/process_time/real_time       8.93 ms         8.88 ms           79
BM_dot_1x3072x512/process_time/real_time        3.48 ms         3.46 ms          195
BM_dot_1x512x1024/process_time/real_time       0.745 ms        0.743 ms          939
BM_dot_1x512x3072/process_time/real_time        2.99 ms         2.97 ms          235
BM_dot_1x512x512/process_time/real_time        0.352 ms        0.352 ms         1985
BM_dot_1x528x128/process_time/real_time        0.088 ms        0.088 ms         7948
BM_dot_2x3072x512/process_time/real_time        5.71 ms         5.68 ms          120
BM_dot_2x512x1024/process_time/real_time        1.38 ms         1.38 ms          506
BM_dot_2x512x3072/process_time/real_time        5.13 ms         5.11 ms          136
BM_dot_2x512x512/process_time/real_time        0.655 ms        0.654 ms         1067
BM_dot_2x528x512/process_time/real_time        0.737 ms        0.736 ms          949
BM_dot_6x513x128/process_time/real_time        0.521 ms        0.520 ms         1343
This PR:
------------------------------------------------------------------------------------
Benchmark                                          Time             CPU   Iterations
------------------------------------------------------------------------------------
BM_dot_384x384x512/process_time/real_time       5.30 ms         5.28 ms          130
BM_dot_384x128x128/process_time/real_time      0.403 ms        0.402 ms         1742
BM_dot_384x128x512/process_time/real_time       1.78 ms         1.77 ms          398
BM_dot_384x512x128/process_time/real_time       1.50 ms         1.50 ms          467
BM_dot_384x512x2/process_time/real_time        0.524 ms        0.522 ms         1336
BM_dot_384x384x32/process_time/real_time       0.261 ms        0.260 ms         2683
BM_dot_1x1024x1024/process_time/real_time       2.25 ms         2.23 ms          311
BM_dot_1x1024x2048/process_time/real_time       6.69 ms         6.65 ms          105
BM_dot_1x1024x3072/process_time/real_time       6.96 ms         6.91 ms          100
BM_dot_1x1024x512/process_time/real_time       0.764 ms        0.762 ms          915
BM_dot_1x128x2/process_time/real_time          0.003 ms        0.003 ms       265439
BM_dot_1x256x512/process_time/real_time        0.169 ms        0.169 ms         4126
BM_dot_1x3072x1024/process_time/real_time       9.03 ms         8.99 ms           78
BM_dot_1x3072x512/process_time/real_time        3.45 ms         3.43 ms          209
BM_dot_1x512x1024/process_time/real_time       0.753 ms        0.751 ms          928
BM_dot_1x512x3072/process_time/real_time        2.92 ms         2.90 ms          240
BM_dot_1x512x512/process_time/real_time        0.341 ms        0.340 ms         2051
BM_dot_1x528x128/process_time/real_time        0.087 ms        0.086 ms         8098
BM_dot_2x3072x512/process_time/real_time        5.90 ms         5.87 ms          118
BM_dot_2x512x1024/process_time/real_time        1.49 ms         1.49 ms          469
BM_dot_2x512x3072/process_time/real_time        4.81 ms         4.78 ms          146
BM_dot_2x512x512/process_time/real_time        0.674 ms        0.672 ms         1038
BM_dot_2x528x512/process_time/real_time        0.696 ms        0.694 ms         1006
BM_dot_6x513x128/process_time/real_time        0.484 ms        0.483 ms         1445

@google-cla google-cla Bot added the cla: yes label Sep 14, 2021
@asaadaldien
asaadaldien force-pushed the ataei-tile_and_vectorize branch 3 times, most recently from ba84e74 to d4c9bc0 Compare September 14, 2021 19:18
@asaadaldien
asaadaldien force-pushed the ataei-tile_and_vectorize branch from d4c9bc0 to d966140 Compare September 14, 2021 19:24
@asaadaldien asaadaldien changed the title Tile and vectorize A pipeline for multi level tiling and vectorization of linalg ops on tensors Sep 14, 2021
@asaadaldien asaadaldien linked an issue Sep 14, 2021 that may be closed by this pull request
4 of 6 tasks

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

THanks! Just a few nits!

Comment thread iree/compiler/Codegen/LLVMCPU/BUILD Outdated
"LLVMCPUPlanConvLoopOrder.cpp",
"LLVMCPUSynchronizeSymbolVisibility.cpp",
"LLVMCPUTilePadAndVectorize.cpp",
"LLVMCPUTileAndVectorize.cpp",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we are changing the name here, mind disambiguating this with what is LLVMCPUVectorization?

namespace mlir {
namespace iree_compiler {

static llvm::cl::opt<bool> clUseTensorPadTileAndVectorize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bonus points for dropping an llvm flag :)

: StrEnumAttrCase<"CPUDefault">;
def CPU_Vectorization
: StrEnumAttrCase<"CPUVectorization">;
def CPU_TensorToVectors : StrEnumAttrCase<"CPUTensorToVectors">;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Style nit: please make consistent with the other lines.

def DispatchLoweringPassPipelineEnum
: StrEnumAttr<"DispatchLoweringPassPipeline",
"identifier for pass pipeline use to lower dispatch region", [
CPU_Default, CPU_Vectorization, CPU_TensorToVectors,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Do you mind making this alphabetical.

@asaadaldien
asaadaldien marked this pull request as ready for review September 14, 2021 22:17
@asaadaldien

Copy link
Copy Markdown
Contributor Author

Mmmmm, seems to breaking MobileNetV2! taking a deeper look..

@asaadaldien

Copy link
Copy Markdown
Contributor Author

I incorrectly parsed the log integrations/tensorflow/bindings/python/iree/tf/support/tf_test_utils_test.py is the failing test not MobileNetV2, Its strange since there is nothing special about the matmul in that test!

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Some of the benchmark models are failing too. Those are easier to triage. I think the steps are you have to set -DIREE_BUILD_BENCHMARKS to true and do cmake --build . --target benchmark_suites. Then you should see benchmark_suites folder in the build directory (I might have the order wrong, you might not need to build). The CMakeLists in iree/benchmarks/TensorFlow/ should have the options to use.

@antiagainst

Copy link
Copy Markdown
Member

Some of the benchmark models are failing too. Those are easier to triage. I think the steps are you have to set -DIREE_BUILD_BENCHMARKS to true and do cmake --build . --target benchmark_suites.

It should be cmake --build . --target iree-benchmark-suites. See here: https://github.com/google/iree/blob/3fa4f8d/CMakeLists.txt#L455-L458. It will automatally download the input MLIR source model and tries to compile them according to the CMake definitions we have in https://github.com/google/iree/tree/main/benchmarks. You can find all input models and artifacts in <build-dir>/benchmark_suites/.

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is fine, but there might be a better way. You can look at the hal.executable.variant to see if this is vmvx or not and then vectorize or not. Then we can drop all of these flags. Fine to do this in a later pass (let me know if you are going to do it in a later pass)

@asaadaldien

Copy link
Copy Markdown
Contributor Author

This is fine, but there might be a better way. You can look at the hal.executable.variant to see if this is vmvx or not and then vectorize or not. Then we can drop all of these flags. Fine to do this in a later pass (let me know if you are going to do it in a later pass)

Sure, I can do this in second pass, but not sure which flags you are looking to drop?

@iree-github-actions-bot

Copy link
Copy Markdown
Contributor

Abbreviated Benchmark Summary

@ commit 869d8023698307991207ad7909986f2abeccb30e (vs. base 0af70597cae209fb5d0fbb8e3c86884f5966d952)

Regressed Benchmarks 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small [fp32,imagenet] (TensorFlow) full-inference with IREE-Vulkan @ Pixel-4 (GPU-Adreno-640) 18 (vs. 17, 5.88%↑) 18 0

Improved Benchmarks 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV2 [fp32,imagenet] (TensorFlow) kernel-execution with IREE-Vulkan @ SM-G980F (GPU-Mali-G77) 15 (vs. 23, 34.78%↓) 15 0

For more information:

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Sure, I can do this in second pass, but not sure which flags you are looking to drop?

This flag here (https://github.com/google/iree/blob/fd7dd286d8cc653b27f85b9bf07a9683d9bf7abe/iree/compiler/Codegen/LLVMCPU/LLVMCPULowerExecutableTarget.cpp#L75). This is set when called from the executable translation. Instead, just look for the backend within the pass itself to figure it out so that all that plumbing can be cleaned up.

@asaadaldien
asaadaldien merged commit 0d7f23a into main Sep 15, 2021
@asaadaldien
asaadaldien deleted the ataei-tile_and_vectorize branch September 15, 2021 23:57
@hcindyl

hcindyl commented Sep 16, 2021

Copy link
Copy Markdown
Contributor

@asaadaldien

Copy link
Copy Markdown
Contributor Author

This PR seems to cause the CI failure at ToT.

https://source.cloud.google.com/results/invocations/6112d1b9-8962-4bb0-8bad-16e1ded18ec8/targets/iree%2Fgcp_ubuntu%2Fbazel%2Flinux%2Fx86-swiftshader%2Fcore%2Fmain/log

Thanks for the heads up, seems like a canonicalized was merged upstream caused this. Should be fixed by #7065

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.

Use tile and fuse upto vector level.

5 participants