Skip to content

Redo handling of operand reuse to prevent stack allocation. - #12041

Merged
MaheshRavishankar merged 1 commit into
iree-org:mainfrom
MaheshRavishankar:fix_convert_to_dest
Feb 9, 2023
Merged

MaheshRavishankar merged 1 commit into
iree-org:mainfrom
MaheshRavishankar:fix_convert_to_dest

Conversation

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

For dispatches with

%r = <some compute op>
%store = linalg.generic ... ins(%r, ...) outs(%empty :)

where the value of %store is the final result of the dispatch, to avoid creation of stacks for %r when vectorization does not kick in, the user is converted to

%store = linalg.generic ... ins(, ...) outs(%r :)

This is a very specific change to work around something that really should be handled later on during bufferization (but is outside scope of bufferization today). This change needs to kick in very specific conditions (since its a work-around, and really the created linalg.generic is somewhat of an anti-pattern), using a pattern rewrite to make this change does not allow controlling the transformation. Change this to use a walk and trigger only when needed.

Fixes #12019.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

FYI @matthias-springer leaving this as a placeholder for us to chat about more. You dont need to worry about the actual changes, just the PR description is something we can use as a seed for the discussion.

@iree-github-actions-bot

iree-github-actions-bot commented Feb 2, 2023 •

Copy link
Copy Markdown
Contributor

Abbreviated Linux Benchmark Summary

@ commit 3dc539223bc3eb1529713d6e4d9dd856435e4c85 (vs. base dd3ea1d9084da4b23b382bc1085ef6d2322c13f1)

No improved or regressed benchmarks 🏖️

Regressed Compilation Times 🚩

Benchmark Name Compilation Time (ms)
EfficientNetV2STF [fp32] (TF) CPU-x86\_64-CascadeLake 8-thread,full-inference,default-flags 34068 (vs. 28644, 18.94%↑)
EfficientNetV2STF [fp32] (TF) CPU-x86\_64-CascadeLake full-inference,default-flags 34068 (vs. 28644, 18.94%↑)
EfficientNetV2STF [fp32] (TF) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 34068 (vs. 28644, 18.94%↑)

[Top 3 out of 40 results showed]

Improved Compilation Times 🎉

Benchmark Name Compilation Time (ms)
BertForMaskedLM [fp32,seqlen512] (TF) CPU-x86\_64-CascadeLake 8-thread,full-inference,default-flags 12046 (vs. 15761, 23.57%↓)
BertForMaskedLM [fp32,seqlen512] (TF) CPU-x86\_64-CascadeLake full-inference,default-flags 12046 (vs. 15761, 23.57%↓)
BertForMaskedLM [fp32,seqlen512] (TF) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 12046 (vs. 15761, 23.57%↓)

[Top 3 out of 5 results showed]

For more information:

@iree-github-actions-bot

iree-github-actions-bot commented Feb 2, 2023 •

Copy link
Copy Markdown
Contributor

Abbreviated Android Benchmark Summary

@ commit 3dc539223bc3eb1529713d6e4d9dd856435e4c85 (vs. base dd3ea1d9084da4b23b382bc1085ef6d2322c13f1)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileBertSquad [fp16] (TFLite) full-inference,default-flags with IREE-Vulkan @ Pixel-6-Pro (GPU-Mali-G78) 127.647 (vs. 113.633, 12.33%↑) 127.269 2.113
PoseNet [fp32] (TFLite) little-core,full-inference,experimental-flags with IREE-LLVM-CPU-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 305.886 (vs. 288.746, 5.94%↑) 307.782 7.741
MobileSSD [fp32] (TFLite) 1-thread,big-core,full-inference,experimental-flags with IREE-LLVM-CPU @ Pixel-4 (CPU-ARMv8.2-A) 74.355 (vs. 70.754, 5.09%↑) 74.340 0.055

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV2 [fp32,imagenet] (TFLite) little-core,full-inference,experimental-flags with IREE-LLVM-CPU-Sync @ Pixel-6-Pro (CPU-ARMv8.2-A) 185.539 (vs. 204.666, 9.35%↓) 185.539 0.210
MobileBertSquad [fp32] (TFLite) 1-thread,little-core,full-inference,default-flags with IREE-LLVM-CPU @ Pixel-6-Pro (CPU-ARMv8.2-A) 3688.908 (vs. 3897.688, 5.36%↓) 3676.519 33.760
PoseNet [fp32] (TFLite) 4-thread,big-core,full-inference,default-flags with IREE-LLVM-CPU @ Pixel-4 (CPU-ARMv8.2-A) 80.209 (vs. 84.453, 5.02%↓) 80.550 1.787

Regressed Compilation Times 🚩

Benchmark Name Compilation Time (ms)
MobileNetV3Small [fp32,imagenet] (TFLite) GPU-Adreno full-inference,default-flags 19592 (vs. 17222, 13.76%↑)
DeepLabV3 [fp32] (TFLite) GPU-Mali-Valhall full-inference,experimental-flags 9645 (vs. 8504, 13.42%↑)
PoseNet [fp32] (TFLite) CPU-ARM64-v8A 1-thread,big-core,full-inference,experimental-flags 15397 (vs. 14286, 7.78%↑)

[Top 3 out of 8 results showed]

Improved Compilation Times 🎉

Benchmark Name Compilation Time (ms)
PoseNet [fp32] (TFLite) GPU-Mali-Valhall kernel-execution,experimental-flags 8490 (vs. 16614, 48.90%↓)
MobileNetV2 [fp32,imagenet] (TFLite) GPU-Mali-Valhall full-inference,default-flags 21518 (vs. 39019, 44.85%↓)
MobileSSD [fp32] (TFLite) GPU-Mali-Valhall full-inference,default-flags 25781 (vs. 46299, 44.32%↓)

[Top 3 out of 67 results showed]

Improved Total Dispatch Sizes 🎉

Benchmark Name Total Dispatch Size (bytes)
MobileBertSquad [fp32] (TFLite) CPU-ARM64-v8A 1-thread,big-core,full-inference,experimental-flags 38448 (vs. 40640, 5.39%↓)
MobileBertSquad [fp32] (TFLite) CPU-ARM64-v8A little-core,full-inference,experimental-flags 38448 (vs. 40640, 5.39%↓)
MobileBertSquad [fp32] (TFLite) CPU-ARM64-v8A 4-thread,big-core,full-inference,experimental-flags 38448 (vs. 40640, 5.39%↓)

[Top 3 out of 4 results showed]

For more information:

For dispatches with

```
%r = <some compute op>
%store = linalg.generic ... ins(%r, ...) outs(%empty :)
```

where the value of `%store` is the final result of the dispatch, to
avoid creation of stacks for `%r` when vectorization does not kick in,
the user is converted to

```
%store = linalg.generic ... ins(, ...) outs(%r :)
```

This is a very specific change to work around something that really
should be handled later on during bufferization (but is outside scope
of bufferization today). This change needs to kick in very specific
conditions (since its a work-around, and really the created
`linalg.generic` is somewhat of an anti-pattern), using a pattern
rewrite to make this change does not allow controlling the
transformation. Change this to use a walk and trigger only when
needed.

Fixes iree-org#12019.
@MaheshRavishankar
MaheshRavishankar enabled auto-merge (squash) February 9, 2023 02:44
@MaheshRavishankar
MaheshRavishankar merged commit 36dd21f into iree-org:main Feb 9, 2023
Comment on lines +146 to +149
nestedModulePM.addNestedPass<func::FuncOp>(
IREE::LinalgExt::createTileAndDecomposeAttentionPass());
nestedModulePM.addNestedPass<func::FuncOp>(
IREE::LinalgExt::createDecomposeSoftmaxPass());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something in this PR triggered failures on Emscripten (llvm cpu with that target triple): https://github.com/iree-org/iree/actions/runs/4130706149/jobs/7137719751

[14/350] Generating check_llvm-cpu_local-task_attention.mlir_module.vmfb from attention.mlir
FAILED: tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb /work/build-emscripten/tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb 
cd /work/build-emscripten/tests/e2e/linalg_ext_ops && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/tests/e2e/linalg_ext_ops/attention.mlir -o check_llvm-cpu_local-task_attention.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-emscripten\" --iree-llvm-target-triple=wasm32-unknown-emscripten
/work/tests/e2e/linalg_ext_ops/attention.mlir:6:8: error: 'linalg.generic' op inferred input/output operand #3 has shape's dimension #0 to be 2, but found 4
  %1 = iree_linalg_ext.attention ins(%query, %key, %value : tensor<1x4x4xf32>,
       ^

#12081 will run that job on presubmit, but it hasn't been merged yet
We should also figure out how to get this sort of test coverage without Emscripten - maybe adding tests that use the llvm cpu path with a different (baseline?) target triple?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah maybe.... Having emscripten on presubmit will automatically do that... Is it OK if I take a look at that tomorrow? Or is this urgent enough to be P0?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In the meantime, is there a way to temporarily disable the flash_attention test on emscipten. Just to unblock CI.... The flash attention stuff is still on the experimental side of things...

@ScottTodd ScottTodd Feb 9, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it OK if I take a look at that tomorrow? Or is this urgent enough to be P0?

Not a P0. While waiting for a fix, we could either

  • revert this PR
  • let the emscripten build stay broken (it is post-submit and doesn't block anyone... but it makes the whole project look broken with the red x :P)
  • disable the emscripten build
  • disable the test on emscripten (trickier)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can see about just disabling that test on Emscripten

ScottTodd added a commit that referenced this pull request Feb 9, 2023
Least-hacky way I could think of to disable building the
`iree_tests_e2e_linalg_ext_ops_check_llvm-cpu_local-task_attention.mlir`
target on Emscripten while we work on a fix.

See #12041 (comment)
and
https://github.com/iree-org/iree/actions/runs/4130706149/jobs/7137719751

```
[14/350] Generating check_llvm-cpu_local-task_attention.mlir_module.vmfb from attention.mlir
FAILED: tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb /work/build-emscripten/tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb 
cd /work/build-emscripten/tests/e2e/linalg_ext_ops && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/tests/e2e/linalg_ext_ops/attention.mlir -o check_llvm-cpu_local-task_attention.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-emscripten\" --iree-llvm-target-triple=wasm32-unknown-emscripten
/work/tests/e2e/linalg_ext_ops/attention.mlir:6:8: error: 'linalg.generic' op inferred input/output operand #3 has shape's dimension #0 to be 2, but found 4
  %1 = iree_linalg_ext.attention ins(%query, %key, %value : tensor<1x4x4xf32>,
       ^
```

#12081 will run the Emscripten CI
on presubmit to catch errors like this sooner.
qedawkins pushed a commit to qedawkins/iree that referenced this pull request Apr 2, 2023
…#12041)

For dispatches with

```
%r = <some compute op>
%store = linalg.generic ... ins(%r, ...) outs(%empty :)
```
where the value of `%store` is the final result of the dispatch, to avoid creation of stacks for `%r` when vectorization does not kick in, the user is converted to

```
%store = linalg.generic ... ins(, ...) outs(%r :)
```
This is a very specific change to work around something that really should be handled later on during bufferization (but is outside scope of bufferization today). This change needs to kick in very specific conditions (since its a work-around, and really the created linalg.generic is somewhat of an anti-pattern), using a pattern rewrite to make this change does not allow controlling the transformation. Change this to use a walk and trigger only when needed.

Fixes iree-org#12019.

Fixes iree-org#12019
qedawkins pushed a commit to qedawkins/iree that referenced this pull request Apr 2, 2023
…org#12127)

Least-hacky way I could think of to disable building the
`iree_tests_e2e_linalg_ext_ops_check_llvm-cpu_local-task_attention.mlir`
target on Emscripten while we work on a fix.

See iree-org#12041 (comment)
and
https://github.com/iree-org/iree/actions/runs/4130706149/jobs/7137719751

```
[14/350] Generating check_llvm-cpu_local-task_attention.mlir_module.vmfb from attention.mlir
FAILED: tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb /work/build-emscripten/tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb 
cd /work/build-emscripten/tests/e2e/linalg_ext_ops && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/tests/e2e/linalg_ext_ops/attention.mlir -o check_llvm-cpu_local-task_attention.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-emscripten\" --iree-llvm-target-triple=wasm32-unknown-emscripten
/work/tests/e2e/linalg_ext_ops/attention.mlir:6:8: error: 'linalg.generic' op inferred input/output operand iree-org#3 has shape's dimension #0 to be 2, but found 4
  %1 = iree_linalg_ext.attention ins(%query, %key, %value : tensor<1x4x4xf32>,
       ^
```

iree-org#12081 will run the Emscripten CI
on presubmit to catch errors like this sooner.
jpienaar pushed a commit that referenced this pull request May 1, 2023
For dispatches with

```
%r = <some compute op>
%store = linalg.generic ... ins(%r, ...) outs(%empty :)
```
where the value of `%store` is the final result of the dispatch, to avoid creation of stacks for `%r` when vectorization does not kick in, the user is converted to

```
%store = linalg.generic ... ins(, ...) outs(%r :)
```
This is a very specific change to work around something that really should be handled later on during bufferization (but is outside scope of bufferization today). This change needs to kick in very specific conditions (since its a work-around, and really the created linalg.generic is somewhat of an anti-pattern), using a pattern rewrite to make this change does not allow controlling the transformation. Change this to use a walk and trigger only when needed.

Fixes #12019.

Fixes #12019
jpienaar pushed a commit that referenced this pull request May 1, 2023
Least-hacky way I could think of to disable building the
`iree_tests_e2e_linalg_ext_ops_check_llvm-cpu_local-task_attention.mlir`
target on Emscripten while we work on a fix.

See #12041 (comment)
and
https://github.com/iree-org/iree/actions/runs/4130706149/jobs/7137719751

```
[14/350] Generating check_llvm-cpu_local-task_attention.mlir_module.vmfb from attention.mlir
FAILED: tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb /work/build-emscripten/tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb 
cd /work/build-emscripten/tests/e2e/linalg_ext_ops && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/tests/e2e/linalg_ext_ops/attention.mlir -o check_llvm-cpu_local-task_attention.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-emscripten\" --iree-llvm-target-triple=wasm32-unknown-emscripten
/work/tests/e2e/linalg_ext_ops/attention.mlir:6:8: error: 'linalg.generic' op inferred input/output operand #3 has shape's dimension #0 to be 2, but found 4
  %1 = iree_linalg_ext.attention ins(%query, %key, %value : tensor<1x4x4xf32>,
       ^
```

#12081 will run the Emscripten CI
on presubmit to catch errors like this sooner.
rengolin pushed a commit to plaidml/iree that referenced this pull request May 2, 2023
…#12041)

For dispatches with

```
%r = <some compute op>
%store = linalg.generic ... ins(%r, ...) outs(%empty :)
```
where the value of `%store` is the final result of the dispatch, to avoid creation of stacks for `%r` when vectorization does not kick in, the user is converted to

```
%store = linalg.generic ... ins(, ...) outs(%r :)
```
This is a very specific change to work around something that really should be handled later on during bufferization (but is outside scope of bufferization today). This change needs to kick in very specific conditions (since its a work-around, and really the created linalg.generic is somewhat of an anti-pattern), using a pattern rewrite to make this change does not allow controlling the transformation. Change this to use a walk and trigger only when needed.

Fixes iree-org#12019.

Fixes iree-org#12019
rengolin pushed a commit to plaidml/iree that referenced this pull request May 2, 2023
…org#12127)

Least-hacky way I could think of to disable building the
`iree_tests_e2e_linalg_ext_ops_check_llvm-cpu_local-task_attention.mlir`
target on Emscripten while we work on a fix.

See iree-org#12041 (comment)
and
https://github.com/iree-org/iree/actions/runs/4130706149/jobs/7137719751

```
[14/350] Generating check_llvm-cpu_local-task_attention.mlir_module.vmfb from attention.mlir
FAILED: tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb /work/build-emscripten/tests/e2e/linalg_ext_ops/check_llvm-cpu_local-task_attention.mlir_module.vmfb 
cd /work/build-emscripten/tests/e2e/linalg_ext_ops && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=llvm-cpu /work/tests/e2e/linalg_ext_ops/attention.mlir -o check_llvm-cpu_local-task_attention.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-emscripten\" --iree-llvm-target-triple=wasm32-unknown-emscripten
/work/tests/e2e/linalg_ext_ops/attention.mlir:6:8: error: 'linalg.generic' op inferred input/output operand iree-org#3 has shape's dimension #0 to be 2, but found 4
  %1 = iree_linalg_ext.attention ins(%query, %key, %value : tensor<1x4x4xf32>,
       ^
```

iree-org#12081 will run the Emscripten CI
on presubmit to catch errors like this sooner.
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.

Bufferization creates allocation that should not be needed.

4 participants