-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][tosa] Add error_if checks for Transpose #135219
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//-------------------------------------------------------------------------------------------------- | ||
// Test expected errors generated by verifier checks. | ||
//-------------------------------------------------------------------------------------------------- | ||
|
||
// RUN: mlir-opt %s -split-input-file -verify-diagnostics | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_io_rank_mismatch(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21x1xf32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected input tensor rank to equal result tensor rank}} | ||
%0 = tosa.transpose %arg0 {perms = array<i32: 2, 1, 0>}: (tensor<13x21x3xf32>) -> tensor<3x13x21x1xf32> | ||
return %0 : tensor<3x13x21x1xf32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_rank0_perms() { | ||
%14 = tensor.empty() : tensor<5x27xi64> | ||
// expected-error@+1 {{'tosa.transpose' op expected perms attribute to have size 2 (input rank) but got size 0}} | ||
%72 = tosa.transpose %14 {perms = array<i32> }: (tensor<5x27xi64>) -> tensor<?x?xi64> | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_perms_size(%arg0: tensor<13x21x3xf32>) -> tensor<3x13x21xf32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected perms attribute to have size 3 (input rank) but got size 7}} | ||
%0 = tosa.transpose %arg0 {perms = array<i32: 6, 5, 4, 3, 2, 1, 0> }: (tensor<13x21x3xf32>) -> tensor<3x13x21xf32> | ||
return %0 : tensor<3x13x21xf32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_permutation_tensor(%arg0: tensor<13x21x3xf32>) -> tensor<?x?x?xf32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%0 = tosa.transpose %arg0 {perms = array<i32: 2, 0, 0> }: (tensor<13x21x3xf32>) -> tensor<?x?x?xf32> | ||
return %0 : tensor<?x?x?xf32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_permutation_negative(%arg0: tensor<3x2xi32>) -> tensor<*xi32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: -1, 0> }: (tensor<3x2xi32>) -> tensor<*xi32> | ||
return %1 : tensor<*xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_permutation_tensor_above_range(%arg0: tensor<3x2xi32>) -> tensor<*xi32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 2, 0> }: (tensor<3x2xi32>) -> tensor<*xi32> | ||
return %1 : tensor<*xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_num_elements(%arg0: tensor<3x2xi32>) -> tensor<3x4xi32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected input1 and output to have same numbers of elements, got 6 and 12}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<3x2xi32>) -> tensor<3x4xi32> | ||
return %1 : tensor<3x4xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_permutation_types(%arg0: tensor<3x2xi32>) -> tensor<3x2xi32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected output tensor dim 0 to match input dim 1 with value of 2}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<3x2xi32>) -> tensor<3x2xi32> | ||
return %1 : tensor<3x2xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_invalid_permutation_types_dynamic_dim_ok(%arg0: tensor<2x?xi32>) -> tensor<3x4xi32> { | ||
// expected-error@+1 {{'tosa.transpose' op expected output tensor dim 1 to match input dim 0 with value of 2}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<2x?xi32>) -> tensor<3x4xi32> | ||
return %1 : tensor<3x4xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_transpose_element_type_mismatch(%arg0: tensor<2x3xi32>) -> tensor<3x2xf32> { | ||
// expected-error@+1 {{'tosa.transpose' op failed to verify that all of {input1, output} have same element type}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 1, 0>} : (tensor<2x3xi32>) -> tensor<3x2xf32> | ||
return %1 : tensor<3x2xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @test_invalid_constant_permutation | ||
func.func @test_invalid_constant_permutation() { | ||
%0 = tensor.empty() : tensor<3x4x5xi32> | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%2 = tosa.transpose %0 {perms = array<i32: 3, 0, 1>}: (tensor<3x4x5xi32>) -> tensor<3x4x5xi32> | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: test_rank_size_constant_permutation | ||
func.func @test_rank_size_constant_permutation() { | ||
%0 = arith.constant 6 : index | ||
%2 = tensor.empty(%0) : tensor<?x27xi64> | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%3 = tosa.transpose %2 {perms = array<i32: 0, 2>}: (tensor<?x27xi64>) -> tensor<?x27xi64> | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: test_large_constant_permutation | ||
func.func @test_large_constant_permutation() { | ||
%0 = arith.constant 6 : index | ||
%2 = tensor.empty(%0) : tensor<?x27xi64> | ||
// expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}} | ||
%3 = tosa.transpose %2 {perms = array<i32: 1185677355, 332462212>}: (tensor<?x27xi64>) -> tensor<?x27xi64> | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
func.func @test_scalar_output_transpose(%arg0: tensor<*xf32>) -> tensor<f32> { | ||
// expected-error@+1 {{'tosa.transpose' op result #0 must be tosa-conformant tensor of at least rank 1, but got 'tensor<f32>'}} | ||
%1 = tosa.transpose %arg0 {perms = array<i32: 2, 0, 1>} : (tensor<*xf32>) -> tensor<f32> | ||
return %1 : tensor<f32> | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we missing the check for those? https://www.mlplatform.org/tosa/tosa_spec.html#_transpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these checks are covered by the function: isPermutationVector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see. thanks for the clarification. i would suggest adding a comment to note this down to make it more clear?