Skip to content
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

1D Convolution where input spatial dimension isn't 2 #2358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ struct Legalize1DConvolutionPattern : public ConvolutionDecompositionPattern {
return failure();
}

// Not currently supporting spatial dims other than 2 for the 1D case.
if (op.getConvolutionLayout().getInputSpatialDimensions()[0] != 2) {
return failure();
}

// The shapes that the convolution currently operates with have are 3D, and
// we need to add another dimension for it to match the conv2d signature, so
// adding a dimension of size 1 to the end of input and output shapes.
Expand Down
22 changes: 21 additions & 1 deletion test/ttmlir/Dialect/TTNN/convolution/simple_conv1d.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s | FileCheck %s
module {
func.func @main(%arg0: tensor<1x256x512xf32>, %arg1: tensor<1024x256x1xf32>, %arg2: tensor<1024xf32>) -> tensor<1x1024x512xf32> {
func.func @conv1d_test1(%arg0: tensor<1x256x512xf32>, %arg1: tensor<1024x256x1xf32>, %arg2: tensor<1024xf32>) -> tensor<1x1024x512xf32> {
%0 = tensor.empty() : tensor<1x1024x512xf32>
// CHECK: "ttnn.reshape"
// CHECK-SAME: shape = [1 : i32, 256 : i32, 512 : i32, 1 : i32]
Expand All @@ -17,4 +17,24 @@ module {
// CHECK: return %{{.*}} : tensor<1x1024x512xf32, #ttnn_layout3>
return %1 : tensor<1x1024x512xf32>
}

func.func public @conv1d_test2(%arg0: tensor<1x7x768xbf16>, %arg1: tensor<1x192x768xbf16>) -> (tensor<1x7x768xbf16>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just put some more descriptive test names than test1 and test2, or write some comment above each test explaining the case it is testing :)

%0 = tensor.empty() : tensor<1x7x768xbf16>
// CHECK: "ttnn.reshape"
// CHECK-SAME: shape = [1 : i32, 7 : i32, 768 : i32, 1 : i32]
// CHECK: "ttnn.reshape"
// CHECK-SAME: shape = [1 : i32, 192 : i32, 768 : i32, 1 : i32]
// CHECK: "ttnn.permute"
// CHECK-SAME: permutation = array<i64: 0, 1, 3, 2>
// CHECK: "ttnn.permute"
// CHECK-SAME: permutation = array<i64: 2, 1, 0, 3>
// CHECK: "ttnn.conv2d"
// CHECK: "ttnn.permute"
// CHECK-SAME: permutation = array<i64: 0, 1, 3, 2>
// CHECK: "ttnn.reshape"
// CHECK-SAME: shape = [1 : i32, 7 : i32, 768 : i32]
%1 = "ttir.convolution"(%arg0, %arg1, %0) <{batch_group_count = 1 : i64, convolution_layout = #ttir<convolution_layout input_batch = 0, input_feature = 2, input_spatial_dimensions = 1, kernel_output_feature = 2, kernel_input_feature = 1, kernel_spatial_dimensions = 0, output_batch = 0, output_feature = 2, output_spatial_dimensions = 1>, feature_group_count = 4 : i64, input_dilation = array<i64: 1>, padding = array<i64: 0, 0>, weight_dilation = array<i64: 1>, window_reversal = array<i1: false>, window_strides = array<i64: 1>}> : (tensor<1x7x768xbf16>, tensor<1x192x768xbf16>, tensor<1x7x768xbf16>) -> tensor<1x7x768xbf16>
// CHECK: return %{{.*}} : tensor<1x7x768xbf16, #ttnn_layout{{.*}}>
return %1 : tensor<1x7x768xbf16>
}
}
Loading