Skip to content

[mlir] Add missing patterns to linalg.decompose_pack_unpack TD Op #121400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,8 +1656,8 @@ void linalg::populateDecomposeConvolutionPatterns(RewritePatternSet &patterns,
}

void linalg::populateDecomposePackUnpackPatterns(RewritePatternSet &patterns) {
// TODO: Add and test patterns for tensor.unpack
patterns.add<DecomposeOuterUnitDimsPackOpPattern>(patterns.getContext());
patterns.add<DecomposeOuterUnitDimsUnPackOpPattern>(patterns.getContext());
}

void linalg::populateDecomposePadPatterns(RewritePatternSet &patterns) {
Expand Down
5 changes: 4 additions & 1 deletion mlir/test/Dialect/Linalg/decompose-tensor-unpack-tile.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// RUN: mlir-opt -split-input-file --transform-interpreter --canonicalize --test-linalg-transform-patterns="test-decompose-tensor-unpack" %s | FileCheck %s
// RUN: mlir-opt -split-input-file -transform-interpreter --canonicalize \
// RUN: -transform-preload-library='transform-library-paths=%p/td/decompose-unpack.mlir' \
// RUN: -transform-interpreter=entry-point=decompose_unpack \
// RUN: -transform-interpreter %s | FileCheck %s

func.func @KCRSsr_to_KCRS(%arg0: tensor<1x1x4x8x8x32xf32>, %arg1: tensor<1x1x128x64xf32>) -> tensor<1x1x128x64xf32> {
%0 = tensor.unpack %arg0 inner_dims_pos = [3, 2] inner_tiles = [8, 32] into %arg1 : tensor<1x1x4x8x8x32xf32> -> tensor<1x1x128x64xf32>
Expand Down
4 changes: 3 additions & 1 deletion mlir/test/Dialect/Linalg/decompose-tensor-unpack.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: mlir-opt -split-input-file --test-linalg-transform-patterns="test-decompose-tensor-unpack" %s | FileCheck %s
// RUN: mlir-opt -split-input-file \
// RUN: -transform-preload-library='transform-library-paths=%p/td/decompose-unpack.mlir' \
// RUN: -transform-interpreter=entry-point=decompose_unpack %s | FileCheck %s

func.func @simple_KCRSsr_to_KCRS(%arg0: tensor<1x1x1x1x8x32xf32>, %arg1: tensor<1x1x32x8xf32>) -> tensor<1x1x32x8xf32> {
%0 = tensor.unpack %arg0 inner_dims_pos = [3, 2] inner_tiles = [8, 32] into %arg1 : tensor<1x1x1x1x8x32xf32> -> tensor<1x1x32x8xf32>
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Dialect/Linalg/td/decompose-unpack.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module @transforms attributes { transform.with_named_sequence } {
transform.named_sequence @decompose_unpack(%module: !transform.any_op {transform.readonly}) {
%pack = transform.structured.match ops{["tensor.unpack"]} in %module : (!transform.any_op) -> !transform.any_op

%1 = transform.get_parent_op %pack {isolated_from_above} : (!transform.any_op) -> !transform.any_op
transform.apply_patterns to %1 {
transform.apply_patterns.linalg.decompose_pack_unpack
} : !transform.any_op

transform.yield
}
}
Loading