Skip to content

Don't inline block arguments that can be written - #5247

Merged
antiagainst merged 1 commit into
iree-org:mainfrom
antiagainst:readwrite-inline
Apr 6, 2021
Merged

antiagainst merged 1 commit into
iree-org:mainfrom
antiagainst:readwrite-inline

Conversation

@antiagainst

Copy link
Copy Markdown
Member

We cannot just simply inline and replace all users for the
DispatchWorkgroupsOp if it is an argument that can be written;
for example, the region might perform work after loading a initial
constant from the argument and then write back.

We cannot just simply inline and replace all users for the
DispatchWorkgroupsOp if it is an argument that can be written;
for example, the region might perform work after loading a initial
constant from the argument and then write back.
@antiagainst
antiagainst requested a review from benvanik March 30, 2021 12:58
@google-cla google-cla Bot added the cla: yes label Mar 30, 2021
@benvanik

Copy link
Copy Markdown
Collaborator

What would cause this case to arise? R/W is an antipattern like this in every case I can think of and we shouldn't be making such arguments R/W - it just introduces additional allocations and copies. I'd like to figure out why this is happening and prevent it before we allow it and lose it to time.

@antiagainst

Copy link
Copy Markdown
Member Author

@benvanik: It's an artifact of multiple patterns applying sequentially. More context below:

I encountered this when trying to improve handling for padding. Right now it's done as two steps, first linalg.fill and then subtensor_insert. They will be in two dispatch regions after DispatchLinalgOnTensorsPass, with the second dispatch having a tied argument, like this test shows. I've a following-up commit that turns the first dispatch into a TensorSplatOp so it causes the first dispatch to be eventually folded into a splat constant. So then we are seeing the second dispatch having a tied argument that captures a constant value.

Eventually I think we want to inline only the load and untie the operand-result connection. I didn't do it here because that will cause double linalg.copy in the same dispatch region and we are sort of back to #5042. Regardless of performance, this seems a valid correctness fix to me so I send it out separately. But maybe being separate makes it obscure. I can send out following up patches together if that helps.

@benvanik

Copy link
Copy Markdown
Collaborator

Yep - this is good for correctness, but that example you post and it sounds like your follow up are the precise antipattern we want to avoid, so I wanted to make sure we talk about it :) let's chat in our 1:1

@antiagainst

Copy link
Copy Markdown
Member Author

Discussed during 1:1 and agreed to proceed with this for correctness and progressive performance improvement. We really need to nail down the padding handling issue though. :)

@antiagainst
antiagainst merged commit 652e328 into iree-org:main Apr 6, 2021
@antiagainst
antiagainst deleted the readwrite-inline branch April 6, 2021 23:17
@NatashaKnk NatashaKnk mentioned this pull request Apr 7, 2021
@rsuderman rsuderman mentioned this pull request Apr 7, 2021
copybara-service Bot pushed a commit that referenced this pull request Apr 8, 2021
* 734ec24 Add smoketest_linalg_on_tensors to LLVM and Vulkan-SPIRV targets. (#5324)
* d8bcb78 Drop absl logging and flat_hash_map. (#5334)
* 5c63668 [vulkan] Disable ResNet50 test failing on NVIDIA GPUs (#5332)
* 55d3715 Fix vulkan_device struct manipulation issue with std::vector. (#5333)
* 47d00c6 Fix benchmarking MobileNetV2 on S20 GPU in Linalg on tensor path. (#5331)
* ccae793 Fix bugs in ExtractReduceWindowOpPaddingAttributes. (#5329)
* 652e328 Don't inline block arguments that can be written (#5247)
* 86e7d29 [CodeGen] Enable fusion with consumer elementwise ops (#5282)
* 44ad774 Integrate MLIR-EmitC at iml130/mlir-emitc@3c265bf (#5326)
* 0141857 Added pad test, update LegalizeInputTypes to allow linalg.yield (#5305)
* 5a3653f Add mobile-bert f16 version to Mako benchmark. (#5204)
* f596cdb Add a target_env_conversion test for Linalg on tensors. (#5309)
* f1aa6f4 Print out the status when iree-check-module fails (#5323)
* 40d7589 Check for VMLA and Vulkan components for simple_embedding_test. (#5318)

COPYBARA_INTEGRATE_REVIEW=#5339 from NatashaKnk:main-to-google dea40ed
PiperOrigin-RevId: 367330863
@hanhanW hanhanW mentioned this pull request Apr 9, 2021
@NatashaKnk NatashaKnk mentioned this pull request Apr 9, 2021
@rsuderman rsuderman mentioned this pull request Apr 12, 2021
copybara-service Bot pushed a commit that referenced this pull request Apr 13, 2021
* 0132538 Merge google -> main #5404
* 53e7279 Limit fusion of linalg.generic/indexed_generic ops to avoid redundant computat..
* 516d1ac Merge branch 'main' into google-to-main
* 9630450 Make PrePartitioningConversionPass not recurse into Linalg (#5358)
* 29610ce Merge google -> main (#5388)
* 692c586 Merge branch 'main' into google-to-main
* 9b159c1 [CUDA Codegen] Add support for promotion to workgroup memory. (#5386)
* 11b3bfe MaterializeCPULaunch configurations before bufferization (#5362)
* ee0ddf4 Legalize ui64 to i32 in Flow type converter (#5384)
* 87346a2 Handle tensor.cast bufferization in LinalgBufferizePass (#5369)
* 2922e11 Removes tied transient buffer assignment propagation. (#5365)
* 5b952e4 Making flow.tensor.reshape a tied-op. (#5368)
* 7048463 Fixing ASAN-instrumented dylib library loading. (#5382)
* 2f3ad70 Adding some basic flow.tensor.reshape folders. (#5366)
* 357fa58 Switch simple_embeddding to test on DyLib + Vulkan (#5374)
* cb7d144 Turn on operand fusion flag for benchmarks of Linalg on tensors (#5380)
* f2d74fd Disable fusion of named ops with elementwise operations by default. (#5363)
* 3fc84c3 Add support for returning Python tuples (#5347)
* 8fb65cb Remove handling of shape dialect in flow->hal stream conversion. (#5360)
* 68c27a0 Add logging for Android (#5232)
* 56307e1 Merge pull request #5328 from google/benvanik-constant-io
* d3eb8e4 Merge pull request #5357 from google/benvanik-host-visible
* 4f86152 Materialize interfaces based on usage for flow.dispatch.workgroups.
* f41b25d Splitting -iree-hal-materialize-interfaces into old/new paths. This will insul..
* 62a3dfd Move constant pool ops/hal.constant.subspan into streams. This dramatically re..
* 79dc138 [spirv] NFC: use upstream push constant utility functions (#5352)
* 38daefb Revert "Disable running BERT on Vulkan (see Issue #5268) (#5269)"
* 0995956 Revert "[vulkan] Disable ResNet50 test failing on NVIDIA GPUs (#5332)"
* 0eeb3f8 Removing hack that forced all Vulkan buffers to be host-visible. After removin..
* 8abc33b Tracy fixes for GPU name allocation and allocation callstack mode. (#5356)
* 55f76d3 Fix submodule check failure (#5355)
* 830b547 [CodeGen] Copy constant at the proper place during bufferization (#5343)
* 59ad168 Drop absl flat_hash_set and some unused includes. (#5346)
* de2aabc Control TF MLIR print options via flags (#5336)
* 2e2dfdd Merge google -> main (#5345)
* ef9b787 Merge branch 'main' into google-to-main
* 8b70733 Remove extra comma from context_wrapper.cc
* 8cc6256 Fix linalg-on-tensors smoketests (#5341)
* a578d6a Add TosaToStandard to cpu/gpu target pipeline from ApplyScale lowering (#5288)
* 0c92b88 Add mixed static-dynamic arguments interface for flow.dispatch.tensor.{load|st..
* 9890722 Update Java Bindings To Build In Experimental (#5226)
* 734ec24 Add smoketest_linalg_on_tensors to LLVM and Vulkan-SPIRV targets. (#5324)
* d8bcb78 Drop absl logging and flat_hash_map. (#5334)
* 5c63668 [vulkan] Disable ResNet50 test failing on NVIDIA GPUs (#5332)
* 55d3715 Fix vulkan_device struct manipulation issue with std::vector. (#5333)
* 47d00c6 Fix benchmarking MobileNetV2 on S20 GPU in Linalg on tensor path. (#5331)
* ccae793 Fix bugs in ExtractReduceWindowOpPaddingAttributes. (#5329)
* 652e328 Don't inline block arguments that can be written (#5247)
* 86e7d29 [CodeGen] Enable fusion with consumer elementwise ops (#5282)
* 44ad774 Integrate MLIR-EmitC at iml130/mlir-emitc@3c265bf (#5326)
* 0141857 Added pad test, update LegalizeInputTypes to allow linalg.yield (#5305)
* 5a3653f Add mobile-bert f16 version to Mako benchmark. (#5204)
* f596cdb Add a target_env_conversion test for Linalg on tensors. (#5309)
* f1aa6f4 Print out the status when iree-check-module fails (#5323)
* 40d7589 Check for VMLA and Vulkan components for simple_embedding_test. (#5318)

COPYBARA_INTEGRATE_REVIEW=#5407 from rsuderman:main-to-google c9c3ea7
PiperOrigin-RevId: 368121520
iree-github-actions-bot pushed a commit that referenced this pull request Apr 13, 2021
* 0132538 Merge google -> main #5404
* 53e7279 Limit fusion of linalg.generic/indexed_generic ops to avoid redundant computat..
* 516d1ac Merge branch 'main' into google-to-main
* 9630450 Make PrePartitioningConversionPass not recurse into Linalg (#5358)
* 29610ce Merge google -> main (#5388)
* 692c586 Merge branch 'main' into google-to-main
* 9b159c1 [CUDA Codegen] Add support for promotion to workgroup memory. (#5386)
* 11b3bfe MaterializeCPULaunch configurations before bufferization (#5362)
* ee0ddf4 Legalize ui64 to i32 in Flow type converter (#5384)
* 87346a2 Handle tensor.cast bufferization in LinalgBufferizePass (#5369)
* 2922e11 Removes tied transient buffer assignment propagation. (#5365)
* 5b952e4 Making flow.tensor.reshape a tied-op. (#5368)
* 7048463 Fixing ASAN-instrumented dylib library loading. (#5382)
* 2f3ad70 Adding some basic flow.tensor.reshape folders. (#5366)
* 357fa58 Switch simple_embeddding to test on DyLib + Vulkan (#5374)
* cb7d144 Turn on operand fusion flag for benchmarks of Linalg on tensors (#5380)
* f2d74fd Disable fusion of named ops with elementwise operations by default. (#5363)
* 3fc84c3 Add support for returning Python tuples (#5347)
* 8fb65cb Remove handling of shape dialect in flow->hal stream conversion. (#5360)
* 68c27a0 Add logging for Android (#5232)
* 56307e1 Merge pull request #5328 from google/benvanik-constant-io
* d3eb8e4 Merge pull request #5357 from google/benvanik-host-visible
* 4f86152 Materialize interfaces based on usage for flow.dispatch.workgroups.
* f41b25d Splitting -iree-hal-materialize-interfaces into old/new paths. This will insul..
* 62a3dfd Move constant pool ops/hal.constant.subspan into streams. This dramatically re..
* 79dc138 [spirv] NFC: use upstream push constant utility functions (#5352)
* 38daefb Revert "Disable running BERT on Vulkan (see Issue #5268) (#5269)"
* 0995956 Revert "[vulkan] Disable ResNet50 test failing on NVIDIA GPUs (#5332)"
* 0eeb3f8 Removing hack that forced all Vulkan buffers to be host-visible. After removin..
* 8abc33b Tracy fixes for GPU name allocation and allocation callstack mode. (#5356)
* 55f76d3 Fix submodule check failure (#5355)
* 830b547 [CodeGen] Copy constant at the proper place during bufferization (#5343)
* 59ad168 Drop absl flat_hash_set and some unused includes. (#5346)
* de2aabc Control TF MLIR print options via flags (#5336)
* 2e2dfdd Merge google -> main (#5345)
* ef9b787 Merge branch 'main' into google-to-main
* 8b70733 Remove extra comma from context_wrapper.cc
* 8cc6256 Fix linalg-on-tensors smoketests (#5341)
* a578d6a Add TosaToStandard to cpu/gpu target pipeline from ApplyScale lowering (#5288)
* 0c92b88 Add mixed static-dynamic arguments interface for flow.dispatch.tensor.{load|st..
* 9890722 Update Java Bindings To Build In Experimental (#5226)
* 734ec24 Add smoketest_linalg_on_tensors to LLVM and Vulkan-SPIRV targets. (#5324)
* d8bcb78 Drop absl logging and flat_hash_map. (#5334)
* 5c63668 [vulkan] Disable ResNet50 test failing on NVIDIA GPUs (#5332)
* 55d3715 Fix vulkan_device struct manipulation issue with std::vector. (#5333)
* 47d00c6 Fix benchmarking MobileNetV2 on S20 GPU in Linalg on tensor path. (#5331)
* ccae793 Fix bugs in ExtractReduceWindowOpPaddingAttributes. (#5329)
* 652e328 Don't inline block arguments that can be written (#5247)
* 86e7d29 [CodeGen] Enable fusion with consumer elementwise ops (#5282)
* 44ad774 Integrate MLIR-EmitC at iml130/mlir-emitc@3c265bf (#5326)
* 0141857 Added pad test, update LegalizeInputTypes to allow linalg.yield (#5305)
* 5a3653f Add mobile-bert f16 version to Mako benchmark. (#5204)
* f596cdb Add a target_env_conversion test for Linalg on tensors. (#5309)
* f1aa6f4 Print out the status when iree-check-module fails (#5323)
* 40d7589 Check for VMLA and Vulkan components for simple_embedding_test. (#5318)

PiperOrigin-RevId: 368121520
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.

2 participants