Skip to content

LinkExecutables pass overrides duplicate named tensors #5946

Closed

Description

@rsuderman

Describe the bug
During the LinkExecutables pass for vmvx, duplicately named tensors are overridden to a single value.

To Reproduce
Download the attached file and execute below:

iree-opt /tmp/test.mlir.txt --split-input-file --iree-hal-link-executables --iree-hal-target-backends vmvx

vm.rodata for both functions will result in being the same

Additional context
test.mlir.txt

Activity

  1. added
    bug 🐞
    help wanted
    on May 18, 2021
  2. deleted a comment from Hawkmike on May 19, 2021
  3. ScottTodd commented on May 20, 2021

    @ScottTodd
    Member

    Here's some debug output from that linking code:

    symbol conflict: '__constant_4xi8'
    target op:
    vm.rodata @__constant_4xi8 dense<[0, 0, 0, 1]> : tensor<4xi8>
      (visibility public)
    source op:
    vm.rodata @__constant_4xi8 dense<[0, 0, 1, 0]> : tensor<4xi8>
      (visibility public)
    ops are *not* equivalent, need to disambiguate
    

    Relating this back to the comment thread there, could these vm.rodata ops be marked private (Symbol Visibility docs)? I'm trying to decide how to resolve that conflict and it would be safer to only rename private symbols while merging modules.

  4. benvanik commented on May 20, 2021

    @benvanik
    Collaborator

    RE visibility: rodata should all be private so it's worth setPrivate()ing everywhere.

  5. ScottTodd commented on May 20, 2021

    @ScottTodd
    Member

    public rodata ops are coming from https://github.com/google/iree/blob/b154cd99df25272e17bb4cbb29438b70f445028b/iree/compiler/Dialect/VM/Conversion/MemRefToVM/ConvertMemRefToVM.cpp#L107-L109

    I can reproduce this bug compiling https://github.com/google/iree/blob/main/iree/test/e2e/models/edge_detection.mlir:

    symbol conflict: '__constant_3x3x1x1xf32'
    target op:
    vm.rodata @__constant_3x3x1x1xf32 dense<[-1.000000e+00, 0.000000e+00, 1.000000e+00, -2.000000e+00, 0.000000e+00, 2.000000e+00, -1.000000e+00, 0.000000e+00, 1.000000e+00]> : tensor<9xf32>
      (visibility public)
    source op:
    vm.rodata @__constant_3x3x1x1xf32 dense<[1.000000e+00, 2.000000e+00, 1.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, -1.000000e+00, -2.000000e+00, -1.000000e+00]> : tensor<9xf32>
      (visibility public)
    ops are *not* equivalent, need to disambiguate
    

    I'll work on a fix to the linking pass. This is what I have sketched so far (to handle the general case):

    // Destructively merges |sourceModuleOp| into |targetModuleOp|.
    // |targetSymbolMap| is updated with the new symbols.
    //
    // If a private symbol in |sourceModuleOp| conflicts with another symbol
    // (public or private) tracked in |targetSymbolMap|, it will be renamed and
    // |privateSymbolOccurrences| will be updated to reflect this.
    //
    // Fails if a public symbol in |sourceModuleOp| conflicts with another public
    // symbol tracked in |targetSymbolMap|.
    static LogicalResult mergeModuleInto(
        Operation *sourceModuleOp, Operation *targetModuleOp,
        DenseMap<StringRef, Operation *> &targetSymbolMap,
        llvm::StringMap<unsigned> &privateSymbolOccurrences) {

    that's modeled after @MaheshRavishankar 's earlier attempt here: MaheshRavishankar@7d3baeb

  6. added
    compiler/dialects
    and removed
    help wanted
    on May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐞compiler/dialects

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions