Skip to content

Deduplicate flow.executable ops during Flow dialect transformation. - #3702

Merged
ScottTodd merged 18 commits into
iree-org:mainfrom
ScottTodd:dedup
Nov 9, 2020
Merged

ScottTodd merged 18 commits into
iree-org:mainfrom
ScottTodd:dedup

Conversation

@ScottTodd

@ScottTodd ScottTodd commented Nov 3, 2020 •

Copy link
Copy Markdown
Member

This works towards #1144, but is not generalized beyond flow.executable.

Deep equivalence checks are performed between pairs of flow.executable ops in a new pass run after outlining dispatch regions. These executables will, by construction, have different symbol names so some special comparison logic is needed. When an executable is identified as a duplicate, it is deleted and references to it are updated to point to the canonical executable. This cleans up cases where duplicate executables are generated from the same library calls throughout a program, prior to running further compiler passes or dropping down to codegen.

I iterated on the comparison algorithm quite a bit, first printing ops to strings and checking string equality, then caching hashes of those strings using getChildAnalysis<> (see this documentation). That had the correctness and performance traits I wanted and was easy to read, but was thread-hostile. The comparison code I settled on is still fast even without multithreading (milliseconds on mobilebert in RelWithDebInfo), thanks to efficient structural checks and plenty of places to short circuit and return early. If we find it needs speeding up, we can

  1. Write a llvm::hash_code analysis for executables, traversing regions/blocks and using OperationEquivalence::computeHash()
  2. Query and compare hashes use getChildAnalysis<> as a first check (like a bounding box test prior to collision tests)
  3. Run the existing deep equivalence check to verify that a hash collision didn't happen

The new pass emits statistics, like these for mobilebert (debug build + -pass-statistics flag):

mlir::iree_compiler::IREE::Flow::DeduplicateExecutablesPass
  (S) 930 total executable(s)     - Number of flow.executable ops before deduplication
  (S) 891 duplicate executable(s) - Number of flow.executable ops removed as duplicates
  (S)  39 unique executable(s)    - Number of flow.executable ops remaining after deduplication

@ScottTodd ScottTodd added compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) performance ⚡ Performance/optimization related work across the compiler and runtime labels Nov 3, 2020
@google-cla google-cla Bot added the cla: yes label Nov 3, 2020
@ScottTodd
ScottTodd marked this pull request as ready for review November 5, 2020 00:09
@ScottTodd
ScottTodd requested a review from benvanik November 5, 2020 00:10
@ScottTodd
ScottTodd requested a review from benvanik November 6, 2020 20:35

@benvanik benvanik 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.

see comments

@ScottTodd
ScottTodd requested a review from benvanik November 6, 2020 22:13
@ScottTodd
ScottTodd merged commit 1ba69d9 into iree-org:main Nov 9, 2020
@ScottTodd
ScottTodd deleted the dedup branch November 9, 2020 18:37
@ScottTodd ScottTodd mentioned this pull request Nov 9, 2020
copybara-service Bot pushed a commit that referenced this pull request Nov 9, 2020
* 1ba69d9 Deduplicate flow.executable ops during Flow dialect transformation. (#3702)
* 848b893 Seperate tensorflow coverage into multiple pages (#3758)
* be8dd02 Merge pull request #3760 from google/benvanik-aot-windows-prework
* 6d83db8 Adding support for embedding debug symbols (pdb/dwarf/etc) in dylibs.
* 8a1347f Bumping tracy to disable vsync capture and expose the dbghelp lock.
* 4dc7064 Improving error messages in iree-run-module with invalid function names.
* 4d7805b Optimizations to reduce dispatch overhead. All of these will be fixed with the..
* d57efa3 Making IREE_CHECK_OK not double-evaluate. Prior to this it would run the expre..
* 10b400e Canonicalizing win32 paths prior to trying to open files. Useful in cases wher..
* f9c11f2 [spirv] Use addNestedPass<FuncOp>() for passes working on functions (#3745)
* ab4cb7c Add static, dynamic and training tests for all tf.keras.layers (#3753)
* aaf3377 Adopt pipeline-in-a-pass infra (#3741)
* 43b1d76 Create template for Bug Reports (#3755)
* d264a16 Remove unused deps from kws test (#3751)
* 0601682 Add 'deep_copy' to bazel to allow variable reuse (#3750)
* a70b1d1 Merge google -> main (#3749)

COPYBARA_INTEGRATE_REVIEW=#3762 from ScottTodd:main-to-google 1ba69d9
PiperOrigin-RevId: 341484363
ScottTodd added a commit that referenced this pull request Nov 9, 2020
* 1ba69d9 Deduplicate flow.executable ops during Flow dialect transformation. (#3702)
* 848b893 Seperate tensorflow coverage into multiple pages (#3758)
* be8dd02 Merge pull request #3760 from google/benvanik-aot-windows-prework
* 6d83db8 Adding support for embedding debug symbols (pdb/dwarf/etc) in dylibs.
* 8a1347f Bumping tracy to disable vsync capture and expose the dbghelp lock.
* 4dc7064 Improving error messages in iree-run-module with invalid function names.
* 4d7805b Optimizations to reduce dispatch overhead. All of these will be fixed with the..
* d57efa3 Making IREE_CHECK_OK not double-evaluate. Prior to this it would run the expre..
* 10b400e Canonicalizing win32 paths prior to trying to open files. Useful in cases wher..
* f9c11f2 [spirv] Use addNestedPass<FuncOp>() for passes working on functions (#3745)
* ab4cb7c Add static, dynamic and training tests for all tf.keras.layers (#3753)
* aaf3377 Adopt pipeline-in-a-pass infra (#3741)
* 43b1d76 Create template for Bug Reports (#3755)
* d264a16 Remove unused deps from kws test (#3751)
* 0601682 Add 'deep_copy' to bazel to allow variable reuse (#3750)
* a70b1d1 Merge google -> main (#3749)

COPYBARA_INTEGRATE_REVIEW=#3762 from ScottTodd:main-to-google 1ba69d9
PiperOrigin-RevId: 341484363
ScottTodd added a commit that referenced this pull request Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler/dialects Relating to the IREE compiler dialects (flow, hal, vm) performance ⚡ Performance/optimization related work across the compiler and runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants