-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TTIR Reverse op and stablehlo -> ttir conversion (#1346)
Fixes #1330. A part of the solution for for #1142 (need to add tt-torch and tt-xla tests in separate PRs) . Not implemented end to end since this OP should not exists e2e but rather fitted inside transposed conv op.
- Loading branch information
1 parent
305ea47
commit 8f326f4
Showing
6 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,12 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
|
||
module @jit_eltwise_reverse attributes {} { | ||
func.func @reverse_op(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
%0 = "stablehlo.reverse"(%arg0) {dimensions = array<i64: 1, 0>} : (tensor<32x64xf32>) -> tensor<32x64xf32> | ||
// CHECK: %[[EMPTY:[0-9]+]] = tensor.empty() : tensor<32x64xf32> | ||
// CHECK: %[[REV:[0-9]+]] = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 1, 0>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %0 : tensor<32x64xf32> | ||
// CHECK: return %[[REV]] : tensor<32x64xf32> | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
test/ttmlir/Dialect/TTIR/reverse/reverse_tests_negative.mlir
This file contains 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,34 @@ | ||
// RUN: not ttmlir-opt --split-input-file %s 2>&1 | FileCheck %s | ||
// Negative tests for reverse operation | ||
|
||
// Verify that parsing fails if dimensions are not unique. | ||
module attributes {} { | ||
func.func @reverse_non_unique_dims(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
// CHECK: error: 'ttir.reverse' op dimensions should be unique. Got: 0, 0 | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 0, 0>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
} | ||
|
||
// Verify that parsing fails if any dimension is negative. | ||
// ----- | ||
module attributes {} { | ||
func.func @reverse_negative_dim(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
// CHECK: error: 'ttir.reverse' op all dimensions should be non-negative. Got dimension: -1 | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 0, -1>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
} | ||
|
||
// Verify that parsing fails if any dimension is out of range [0, operandRank). | ||
// ----- | ||
module attributes {} { | ||
func.func @reverse_out_of_bounds_dim(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
// CHECK: error: 'ttir.reverse' op all dimensions should be in interval [0, 2). Got dimension: 2 | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 2>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
test/ttmlir/Dialect/TTIR/reverse/reverse_tests_positive.mlir
This file contains 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,24 @@ | ||
// RUN: ttmlir-opt %s | FileCheck %s | ||
|
||
module attributes {} { | ||
func.func @reverse_first_dim(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
// CHECK: %[[C:.*]] = "ttir.reverse"[[C:.*]] | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 0>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
|
||
func.func @reverse_second_dim(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
// CHECK: %[[C:.*]] = "ttir.reverse"[[C:.*]] | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 1>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
|
||
func.func @reverse_both_dims(%arg0: tensor<32x64xf32>) -> tensor<32x64xf32> { | ||
%0 = tensor.empty() : tensor<32x64xf32> | ||
// CHECK: %[[C:.*]] = "ttir.reverse"[[C:.*]] | ||
%1 = "ttir.reverse"(%arg0, %0) <{dimensions = array<i64: 0, 1>}> : (tensor<32x64xf32>, tensor<32x64xf32>) -> tensor<32x64xf32> | ||
return %1 : tensor<32x64xf32> | ||
} | ||
} |