-
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.
Add TOSA to TTIR conversions for some simple ops (#1445)
* Add Tosa conversion for sin * Add Tosa conversion for sigmoid * Add Tosa conversion for reciprocal * Add Tosa conversion for rsqrt * Add Tosa conversion for where * Add Tosa conversion for maximum * Add Tosa conversion for minimum * Add neg and sub tests * Refactor tests * Improve tests; fix whitespace * Add return checks to tests
- Loading branch information
1 parent
0640c7c
commit 37e10f3
Showing
10 changed files
with
111 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
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_binary/maximum_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_maximum(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.maximum %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.maximum"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_binary/minimum_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_minimum(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.minimum %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.minimum"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_binary/subtract_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_sub(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.sub %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.subtract"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
test/ttmlir/Conversion/TosaToTTIR/elementwise_ternary/select_op.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,11 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_select(%arg0: tensor<32x128xi1>, %arg1: tensor<32x128xf32>, %arg2: tensor<32x128xf32>) -> tensor<32x128xf32> { | ||
// CHECK: func.func {{.+}} [[SELECTOR:tensor<[0-9]+x[0-9]+xi1>]] | ||
%0 = tosa.select %arg0, %arg1, %arg2 : (tensor<32x128xi1>, tensor<32x128xf32>, tensor<32x128xf32>) -> tensor<32x128xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.where"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[SELECTOR]], [[TENSOR_SIZE]], [[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<32x128xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/negate_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_negate(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.negate %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.neg"(%arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/reciprocal_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_reciprocal(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.reciprocal %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.reciprocal"(%arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/rsqrt_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_rsqrt(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.rsqrt %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.rsqrt"(%arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/sigmoid_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_sigmoid(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.sigmoid %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.sigmoid"(%arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/sin_op.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,10 @@ | ||
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s | ||
module attributes {} { | ||
func.func @test_sin(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = tosa.sin %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32> | ||
// CHECK: %[[OP_OUT:[0-9]+]] = tensor.empty() : [[TENSOR_SIZE:tensor<[0-9]+x[0-9]+x[0-9]+xf[0-9]+>]] | ||
// CHECK: %[[VAL:[0-9]+]] = "ttir.sin"(%arg{{[0-9]+}}, %[[OP_OUT]]){{.+}} : ([[TENSOR_SIZE]], [[TENSOR_SIZE]]) -> [[TENSOR_SIZE]] | ||
// CHECK: return %[[VAL]] : [[TENSOR_SIZE]] | ||
return %0 : tensor<13x21x3xf32> | ||
} | ||
} |