Skip to content

Enable multi-use fusion for cases where the shapes of the two ops are the same. - #13747

Merged
MaheshRavishankar merged 3 commits into
iree-org:mainfrom
MaheshRavishankar:multi_use_parallel
Jul 24, 2023
Merged

MaheshRavishankar merged 3 commits into
iree-org:mainfrom
MaheshRavishankar:multi_use_parallel

Conversation

@MaheshRavishankar

@MaheshRavishankar MaheshRavishankar commented May 23, 2023 •

Copy link
Copy Markdown
Collaborator

Previous implementation of multi-use fusion was too aggressive making
it hard to enable by default. For example it would fuse a reduction
producer with its consumer which generates outputs of different shapes
making it hard for backends to handle this. Making the conditions for
fusion less aggressive to restrict this to all parallel
producers/consumers of the same shape, should make this handalable on
all backends.

Issue #13545

@MaheshRavishankar
MaheshRavishankar force-pushed the multi_use_parallel branch 2 times, most recently from 4d84548 to d89a099 Compare May 24, 2023 21:01
@MaheshRavishankar MaheshRavishankar added benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU labels May 24, 2023
@MaheshRavishankar
MaheshRavishankar force-pushed the multi_use_parallel branch 2 times, most recently from 941a1e7 to 4574f81 Compare May 25, 2023 22:43
@MaheshRavishankar
MaheshRavishankar marked this pull request as ready for review May 25, 2023 23:12
@MaheshRavishankar
MaheshRavishankar requested review from hanhanW and pzread and removed request for hanhanW May 25, 2023 23:13
@ScottTodd

Copy link
Copy Markdown
Member

We're discussing the test failures (logs here) in a thread on Discord. Looks like just mnist_train_test is failing with numerical differences, and that test is difficult to debug. Would be nice to have a reduced test case.

return;
Operation *fusableProducer = nullptr;
for (OpOperand &operand : genericOp->getOpOperands()) {
// 2. Only fuse with `linalg.generic` producers that arent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
// 2. Only fuse with `linalg.generic` producers that arent
// 2. Only fuse with `linalg.generic` producers that aren't

@github-actions

github-actions Bot commented Jun 23, 2023 •

Copy link
Copy Markdown

Abbreviated Benchmark Summary

@ commit db4aa8e853fb3efbd9996e0df7d2228ad18b9199 (vs. base 23409007dd246a74d4c0cfdf6d1342364f878237)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
BertLargefp16PTBatch1(linalg) [cuda-sm\_80-linux\_gnu-cuda][default-flags] cuda(none)[full-inference,default-flags] with zeros @ a2-highgpu-1g[gpu] 12.453 (vs. 10.095, 23.37%↑) 12.415 0.093
MiniLML12H384Uncased(stablehlo) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][default-flags] local\_task(embedded\_elf)[8-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 24.131 (vs. 19.856, 21.53%↑) 24.289 1.382
MobileNetV2\_fp32(tflite) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][default-flags] local\_task(embedded\_elf)[1-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 14.935 (vs. 12.798, 16.70%↑) 14.952 0.103

[Top 3 out of 10 results showed]

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MiniLML12H384Uncased(stablehlo) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][experimental-flags,data-tiling,ukernel] local\_task(embedded\_elf)[8-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 20.080 (vs. 22.898, 12.31%↓) 19.321 1.529
PersonDetect\_int8(tflite) [arm-valhall-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,max-concurrency] vulkan(none)[full-inference,default-flags] with zeros @ pixel-6-pro[gpu] 1.666 (vs. 1.812, 8.11%↓) 1.665 0.005
MobileBertSquad\_int8(tflite) [armv8.2-a-generic-linux\_android29-llvm\_cpu][experimental-flags,mmt4d,dotprod] local\_task(embedded\_elf)[1-thread,full-inference,system-scheduling] with zeros @ pixel-6-pro[big-core] 268.479 (vs. 291.415, 7.87%↓) 269.191 2.244

[Top 3 out of 13 results showed]

Regressed Total Dispatch Sizes 🚩

Benchmark Name Total Dispatch Size (bytes)
MobileBertSquad\_fp32(tflite) [arm-valhall-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,max-concurrency,compile-stats] 140454 (vs. 128986, 8.89%↑)
MobileBertSquad\_fp32(tflite) [arm-valhall-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,max-concurrency,repeated-kernel,compile-stats] 140454 (vs. 128986, 8.89%↑)
MobileBertSquad\_fp32(tflite) [qualcomm-adreno-vulkan\_android31-vulkan\_spirv][default-flags,compile-stats] 247454 (vs. 230322, 7.44%↑)

[Top 3 out of 8 results showed]

Improved Stream IR Dispatch Count (# of cmd.dispatch ops) 🎉

Benchmark Name Stream IR Dispatch Count (# of cmd.dispatch ops)
MobileNetV3Small\_fp32(tflite) [qualcomm-adreno-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,compile-stats] 84 (vs. 94, 10.64%↓)
MobileNetV3Small\_fp32(tflite) [qualcomm-adreno-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,repeated-kernel,compile-stats] 84 (vs. 94, 10.64%↓)
MobileNetV3Small\_fp32(tflite) [arm-valhall-vulkan\_android31-vulkan\_spirv][experimental-flags,fuse-padding,max-concurrency,compile-stats] 84 (vs. 94, 10.64%↓)

[Top 3 out of 38 results showed]

For more information:

Source Workflow Run

@MaheshRavishankar
MaheshRavishankar force-pushed the multi_use_parallel branch 2 times, most recently from 65bffd9 to fa0f589 Compare June 24, 2023 17:10
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

@KoolJBlack This is the PR I am seeing a regression on.... If you see the metrics the number of dispatches reduces by 10% on average.

@KoolJBlack

Copy link
Copy Markdown
Contributor

I took a look at profiles with and without your 3 commit on BertLargefp16PTBatch1. Bear in mind its hard to point out %100 all the changes here right away since there are a different arrangement of dispatches between the two models.

I benchmarked these on my local machine with a 3080ti (recompiling on the a100 machines takes hours). There is still roughly a %10 difference in perf (which seems close enough to the benchmark results here). The thing that stands out immediately is a matmul_384x1024x4096_f16 which goes from ~90us before this change to 105us after.

This is forward_dispatch_19_matmul_384x1024x4096_f16 before your commits and forward_dispatch_17_matmul_384x1024x4096_f16. The matmul after tile/distribute is dumped here: https://gist.github.com/KoolJBlack/7e68df0a600901e21ca98556e9e37c4e

There seems to be a double scf.for following the matmul with more fused operations in it.

The next leading difference is forward_dispatch_14_matmul_384x1024x1024_f16 before your commits a forward_dispatch_13_matmul_384x1024x1024_f16. The change is roughly 23us to 34us. The matmul after tile/distribute is dumped here:https://gist.github.com/KoolJBlack/cc47b5e1aee5f9e7d921f054de66e8e8

The situation here is similar.

Looking at the other critical dispatches that take up more than %5 of the runtime seem to have similar perf between the models.

@MaheshRavishankar can you take a look at these IR dumps? Let me know if you want dumps at other levels of the stack or if you can identify whats going on here.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

I took a look at profiles with and without your 3 commit on BertLargefp16PTBatch1. Bear in mind its hard to point out %100 all the changes here right away since there are a different arrangement of dispatches between the two models.

I benchmarked these on my local machine with a 3080ti (recompiling on the a100 machines takes hours). There is still roughly a %10 difference in perf (which seems close enough to the benchmark results here). The thing that stands out immediately is a matmul_384x1024x4096_f16 which goes from ~90us before this change to 105us after.

This is forward_dispatch_19_matmul_384x1024x4096_f16 before your commits and forward_dispatch_17_matmul_384x1024x4096_f16. The matmul after tile/distribute is dumped here: gist.github.com/KoolJBlack/7e68df0a600901e21ca98556e9e37c4e

There seems to be a double scf.for following the matmul with more fused operations in it.

The next leading difference is forward_dispatch_14_matmul_384x1024x1024_f16 before your commits a forward_dispatch_13_matmul_384x1024x1024_f16. The change is roughly 23us to 34us. The matmul after tile/distribute is dumped here:gist.github.com/KoolJBlack/cc47b5e1aee5f9e7d921f054de66e8e8

The situation here is similar.

Looking at the other critical dispatches that take up more than %5 of the runtime seem to have similar perf between the models.

@MaheshRavishankar can you take a look at these IR dumps? Let me know if you want dumps at other levels of the stack or if you can identify whats going on here.

Thanks a lot @KoolJBlack ! This is very helpful! Can you post the IR for the dispatches before tile and distribute (Ideally before LLVMGPULowerExecutableTarget).

@KoolJBlack

Copy link
Copy Markdown
Contributor

These are the dispatches before tile/distribute: https://gist.github.com/KoolJBlack/3d56c69cfbeee69893b38c45fa3e0bb4

The should correspond to the state before LLVMGPULowerExecutableTarget runs

Mahesh Ravishankar added 2 commits July 24, 2023 17:50
… the same.

Previous implementation of multi-use fusion was too aggressive making
it hard to enable by default. For example it would fuse a reduction
producer with its consumer which generates outputs of different shapes
making it hard for backends to handle this. Making the conditions for
fusion less aggressive to restrict this to all parallel
producers/consumers of the same shape, should make this handalable on
all backends.

Issue iree-org#13545
@MaheshRavishankar
MaheshRavishankar merged commit b375669 into iree-org:main Jul 24, 2023
@MaheshRavishankar
MaheshRavishankar deleted the multi_use_parallel branch July 24, 2023 21:38
nhasabni pushed a commit to plaidml/iree that referenced this pull request Aug 24, 2023
… the same. (iree-org#13747)

Previous implementation of multi-use fusion was too aggressive making
it hard to enable by default. For example it would fuse a reduction
producer with its consumer which generates outputs of different shapes
making it hard for backends to handle this. Making the conditions for
fusion less aggressive to restrict this to all parallel
producers/consumers of the same shape, should make this handalable on
all backends.

Issue iree-org#13545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:cuda Run default CUDA benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU benchmarks:x86_64 Run default x86_64 benchmarks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants