-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for stablehlo.reduce op for logical and operator
TTNN does not support reduction for logical and operator. So stablehlo.reduce for stablehlo.and operator is decomposed into reduction sum op along give dimension and then compared with the size of given dimension.
- Loading branch information
1 parent
2fcd37a
commit e800cae
Showing
10 changed files
with
249 additions
and
1 deletion.
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
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,39 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
module @jit_reduce_and attributes {} { | ||
func.func public @test_reduce_and_4to3dim(%arg0: tensor<128x10x32x4xi1>, %cst_0: tensor<i1>) -> tensor<128x10x32xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_4to3dim | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.reduce_and" | ||
// CHECK-SAME: dim_arg = [3 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xbf16> | ||
// CHECK-SAME: -> tensor<128x10x32xbf16> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [3] : (tensor<128x10x32x4xi1>, tensor<i1>) -> tensor<128x10x32xi1> | ||
return %0 : tensor<128x10x32xi1> | ||
} | ||
|
||
func.func public @test_reduce_and_3to2dim(%arg0: tensor<128x10x4xi1>, %cst_0: tensor<i1>) -> tensor<128x4xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_3to2dim | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.reduce_and" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x4xbf16> | ||
// CHECK-SAME: -> tensor<128x4xbf16> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [1] : (tensor<128x10x4xi1>, tensor<i1>) -> tensor<128x4xi1> | ||
return %0 : tensor<128x4xi1> | ||
} | ||
|
||
func.func public @test_reduce_and_2to1dim(%arg0: tensor<128x10xi1>, %cst_0: tensor<i1>) -> tensor<10xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_2to1dim | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.reduce_and" | ||
// CHECK-SAME: dim_arg = [0 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10xbf16> | ||
// CHECK-SAME: -> tensor<10xbf16> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [0] : (tensor<128x10xi1>, tensor<i1>) -> tensor<10xi1> | ||
return %0 : tensor<10xi1> | ||
} | ||
} |
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,59 @@ | ||
// RUN: ttmlir-opt --ttir-to-ttir-decomposition %s | FileCheck %s | ||
module attributes {} { | ||
func.func public @test_reduce_and_4to3dim(%arg0: tensor<128x10x32x4xbf16>, %arg1: tensor<1xbf16>) -> tensor<128x10x32xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_4to3dim | ||
// CHECK: %[[SUM:[0-9]+]] = "ttir.sum" | ||
// CHECK-SAME: dim_arg = [3 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xbf16> | ||
// CHECK-SAME: -> [[TENSOR:tensor<128x10x32xbf16>]] | ||
// CHECK: %[[CONST:[0-9+]]] = "ttir.constant" | ||
// CHECK-SAME: value = dense<4.0 | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: %[[RET:[0-9]+]] = "ttir.eq" | ||
// CHECK-SAME: %[[SUM]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: return %[[RET]] | ||
%0 = tensor.empty() : tensor<128x10x32xbf16> | ||
%1 = "ttir.reduce_and"(%arg0, %0) <{dim_arg = [3 : i32], keep_dim = false}> : (tensor<128x10x32x4xbf16>, tensor<128x10x32xbf16>) -> tensor<128x10x32xbf16> | ||
return %1 : tensor<128x10x32xbf16> | ||
} | ||
|
||
func.func public @test_reduce_and_3to2dim(%arg0: tensor<128x10x4xbf16>, %arg1: tensor<1xbf16>) -> tensor<128x4xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_3to2dim | ||
// CHECK: %[[SUM:[0-9]+]] = "ttir.sum" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x4xbf16> | ||
// CHECK-SAME: -> [[TENSOR:tensor<128x4xbf16>]] | ||
// CHECK: %[[CONST:[0-9+]]] = "ttir.constant" | ||
// CHECK-SAME: value = dense<1.000000e+01> | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: %[[RET:[0-9]+]] = "ttir.eq" | ||
// CHECK-SAME: %[[SUM]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: return %[[RET]] | ||
%0 = tensor.empty() : tensor<128x4xbf16> | ||
%1 = "ttir.reduce_and"(%arg0, %0) <{dim_arg = [1 : i32], keep_dim = false}> : (tensor<128x10x4xbf16>, tensor<128x4xbf16>) -> tensor<128x4xbf16> | ||
return %1 : tensor<128x4xbf16> | ||
} | ||
|
||
func.func public @test_reduce_and_2to1dim(%arg0: tensor<128x10xbf16>, %arg1: tensor<1xbf16>) -> tensor<10xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_2to1dim | ||
// CHECK: %[[SUM:[0-9]+]] = "ttir.sum" | ||
// CHECK-SAME: dim_arg = [0 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10xbf16> | ||
// CHECK-SAME: -> [[TENSOR:tensor<10xbf16>]] | ||
// CHECK: %[[CONST:[0-9+]]] = "ttir.constant" | ||
// CHECK-SAME: value = dense<1.280000e+02> | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: %[[RET:[0-9]+]] = "ttir.eq" | ||
// CHECK-SAME: %[[SUM]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: return %[[RET]] | ||
%0 = tensor.empty() : tensor<10xbf16> | ||
%1 = "ttir.reduce_and"(%arg0, %0) <{dim_arg = [0 : i32], keep_dim = false}> : (tensor<128x10xbf16>, tensor<10xbf16>) -> tensor<10xbf16> | ||
return %1 : tensor<10xbf16> | ||
} | ||
} |
File renamed without changes.
70 changes: 70 additions & 0 deletions
70
test/ttmlir/Silicon/StableHLO/reduction/reduce_and_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,70 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: rm -rf %t.ttnn | ||
// RUN: rm -rf %t.mlir | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline --ttir-to-ttnn-backend-pipeline="system-desc-path=%system_desc_path%" > %t.mlir | ||
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn | ||
|
||
module @jit_reduce_add attributes {} { | ||
func.func public @test_reduce_and_4to3dim(%arg0: tensor<128x10x32x4xi1>, %cst_0: tensor<i1>) -> tensor<128x10x32xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_4to3dim | ||
// CHECK: %[[CONST:[0-9+]]] = "ttnn.full" | ||
// CHECK-SAME: <{fillValue = 4.000000e+00 : f32}> | ||
// CHECK-SAME: -> [[TENSOR:tensor<128x10x32xbf16,]] | ||
// CHECK: %[[SUM:[0-9]+]] = "ttnn.sum" | ||
// CHECK-SAME: dim_arg = [3 : i32] | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: -> tensor<128x10x32x1xbf16, | ||
// CHECK: %[[RES:[0-9]+]] = "ttnn.reshape" | ||
// CHECK-SAME: %[[SUM]] | ||
// CHECK-SAME: <{shape = [128 : i32, 10 : i32, 32 : i32]}> | ||
// CHECK-SAME: tensor<128x10x32x1xbf16, | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: "ttnn.eq" | ||
// CHECK-SAME: %[[RES]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [3] : (tensor<128x10x32x4xi1>, tensor<i1>) -> tensor<128x10x32xi1> | ||
return %0 : tensor<128x10x32xi1> | ||
} | ||
|
||
func.func public @test_reduce_and_3to2dim(%arg0: tensor<128x10x4xi1>, %cst_0: tensor<i1>) -> tensor<128x4xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_3to2dim | ||
// CHECK: %[[CONST:[0-9+]]] = "ttnn.full" | ||
// CHECK-SAME: <{fillValue = 1.000000e+01 : f32}> | ||
// CHECK-SAME: -> [[TENSOR:tensor<128x4xbf16,]] | ||
// CHECK: %[[SUM:[0-9]+]] = "ttnn.sum" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: -> tensor<128x1x4xbf16, | ||
// CHECK: %[[RES:[0-9]+]] = "ttnn.reshape" | ||
// CHECK-SAME: %[[SUM]] | ||
// CHECK-SAME: <{shape = [128 : i32, 4 : i32]}> | ||
// CHECK-SAME: tensor<128x1x4xbf16, | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: "ttnn.eq" | ||
// CHECK-SAME: %[[RES]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [1] : (tensor<128x10x4xi1>, tensor<i1>) -> tensor<128x4xi1> | ||
return %0 : tensor<128x4xi1> | ||
} | ||
|
||
func.func public @test_reduce_and_2to1dim(%arg0: tensor<128x10xi1>, %cst_0: tensor<i1>) -> tensor<10xi1> { | ||
// CHECK-LABEL: func.func public @test_reduce_and_2to1dim | ||
// CHECK: %[[CONST:[0-9+]]] = "ttnn.full" | ||
// CHECK-SAME: <{fillValue = 1.280000e+02 : f32}> | ||
// CHECK-SAME: -> [[TENSOR:tensor<10xbf16,]] | ||
// CHECK: %[[SUM:[0-9]+]] = "ttnn.sum" | ||
// CHECK-SAME: dim_arg = [0 : i32] | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: -> tensor<1x10xbf16, | ||
// CHECK: %[[RES:[0-9]+]] = "ttnn.reshape" | ||
// CHECK-SAME: %[[SUM]] | ||
// CHECK-SAME: <{shape = [10 : i32]}> | ||
// CHECK-SAME: tensor<1x10xbf16, | ||
// CHECK-SAME: -> [[TENSOR]] | ||
// CHECK: "ttnn.eq" | ||
// CHECK-SAME: %[[RES]], %[[CONST]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.and across dimensions = [0] : (tensor<128x10xi1>, tensor<i1>) -> tensor<10xi1> | ||
return %0 : tensor<10xi1> | ||
} | ||
} |
File renamed without changes.