Skip to content

Conversation

chrsmcgrr
Copy link
Collaborator

@chrsmcgrr chrsmcgrr commented May 22, 2025

Given the following example:

module {
  func.func @main(%arg0: tensor<1x1x1x4x1xf32>, %arg1: tensor<1x1x4xf32>) -> tensor<1x1x1x4x1xf32> {
    %pack = linalg.pack %arg1 outer_dims_perm = [1, 2, 0] inner_dims_pos = [2, 0] inner_tiles = [4, 1] into %arg0 : tensor<1x1x4xf32> -> tensor<1x1x1x4x1xf32>
    return %pack : tensor<1x1x1x4x1xf32>
  }
}

We would generate an invalid transpose operation because the calculated permutation would be [0, 2, 0] which is semantically incorrect. As the permutation must contain unique integers corresponding to the source tensor.

The assumption that because all outer dimensions are 1 the transposition does not matter does not hold because the indices in permutation must be unique and match the source tensor indices.

The following change attempts to amend that.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@chrsmcgrr chrsmcgrr force-pushed the chris/roo-395-fix-pack-decomposition branch 2 times, most recently from 85d6f7a to 2fce8ff Compare May 23, 2025 11:58
@chrsmcgrr chrsmcgrr marked this pull request as ready for review May 23, 2025 12:00
@chrsmcgrr chrsmcgrr requested a review from a team May 23, 2025 12:00
Copy link
Collaborator Author

ninja check-mlir passes locally. Feel free to checkout and test yourself. We need automation.

Copy link

@maxbartel maxbartel left a comment

Choose a reason for hiding this comment

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

LGTM. You can also directly upstream. Pack is really a heavy op...

@chrsmcgrr chrsmcgrr force-pushed the chris/roo-395-fix-pack-decomposition branch 2 times, most recently from 7355aa1 to 4033b94 Compare May 26, 2025 14:16
given the following example:
```
module {
  func.func @main(%arg0: tensor<1x1x1x4x1xf32>, %arg1: tensor<1x1x4xf32>) -> tensor<1x1x1x4x1xf32> {
    %pack = linalg.pack %arg1 outer_dims_perm = [1, 2, 0] inner_dims_pos = [2, 0] inner_tiles = [4, 1] into %arg0 : tensor<1x1x4xf32> -> tensor<1x1x1x4x1xf32>
    return %pack : tensor<1x1x1x4x1xf32>
  }
}
```

we would generate an invalid transpose operation because the calculated
permutation would be `[0, 2, 0]` which is semantically incorrect. As the
permutation must contain unique integers corresponding to the source
tensor.

The following change attempts to amend that.
@chrsmcgrr chrsmcgrr force-pushed the chris/roo-395-fix-pack-decomposition branch from 4033b94 to 2c1f0aa Compare May 26, 2025 14:18
@chrsmcgrr chrsmcgrr merged commit 697e7ea into integrate-llvm-project-20250508 May 26, 2025
6 checks passed
@chrsmcgrr chrsmcgrr deleted the chris/roo-395-fix-pack-decomposition branch July 9, 2025 06:13
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.

3 participants