-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E implementation of reduce minimum op along with StableHLO conv…
…ersion.
- Loading branch information
1 parent
757ef0b
commit 20bbd5c
Showing
14 changed files
with
359 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ enum ReductionOpType: uint32 { | |
Sum, | ||
Mean, | ||
Max, | ||
Min, | ||
} | ||
|
||
table ReductionOp { | ||
|
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
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
113 changes: 113 additions & 0 deletions
113
test/ttmlir/Conversion/StableHLOToTTIR/reduction/reduce_min_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,113 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
module @jit_reduce_minimum attributes {} { | ||
func.func public @test_reduce_minimum_4to3dim(%arg0: tensor<128x10x32x4xf32>, %cst_0: tensor<f32>) -> tensor<128x32x4xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xf32> | ||
// CHECK-SAME: -> tensor<128x32x4xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1] : (tensor<128x10x32x4xf32>, tensor<f32>) -> tensor<128x32x4xf32> | ||
return %0 : tensor<128x32x4xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_4to2dim(%arg0: tensor<128x10x32x4xf32>, %cst_0: tensor<f32>) -> tensor<128x32xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32, 3 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xf32> | ||
// CHECK-SAME: -> tensor<128x32xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1, 3] : (tensor<128x10x32x4xf32>, tensor<f32>) -> tensor<128x32xf32> | ||
return %0 : tensor<128x32xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_4to1dim(%arg0: tensor<128x10x32x4xf32>, %cst_0: tensor<f32>) -> tensor<128xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32, 2 : i32, 3 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xf32> | ||
// CHECK-SAME: -> tensor<128xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1, 2, 3] : (tensor<128x10x32x4xf32>, tensor<f32>) -> tensor<128xf32> | ||
return %0 : tensor<128xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_4to0dim(%arg0: tensor<128x10x32x4xf32>, %cst_0: tensor<f32>) -> tensor<f32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [0 : i32, 1 : i32, 2 : i32, 3 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x32x4xf32> | ||
// CHECK-SAME: -> tensor<1xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [0, 1, 2, 3] : (tensor<128x10x32x4xf32>, tensor<f32>) -> tensor<f32> | ||
return %0 : tensor<f32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_3to2dim(%arg0: tensor<128x10x4xf32>, %cst_0: tensor<f32>) -> tensor<128x4xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x4xf32> | ||
// CHECK-SAME: -> tensor<128x4xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1] : (tensor<128x10x4xf32>, tensor<f32>) -> tensor<128x4xf32> | ||
return %0 : tensor<128x4xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_3to1dim(%arg0: tensor<128x10x4xf32>, %cst_0: tensor<f32>) -> tensor<128xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32, 2 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x4xf32> | ||
// CHECK-SAME: -> tensor<128xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1, 2] : (tensor<128x10x4xf32>, tensor<f32>) -> tensor<128xf32> | ||
return %0 : tensor<128xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_3to0dim(%arg0: tensor<128x10x4xf32>, %cst_0: tensor<f32>) -> tensor<f32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [0 : i32, 1 : i32, 2 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10x4xf32> | ||
// CHECK-SAME: -> tensor<1xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [0, 1, 2] : (tensor<128x10x4xf32>, tensor<f32>) -> tensor<f32> | ||
return %0 : tensor<f32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_2to1dim(%arg0: tensor<128x10xf32>, %cst_0: tensor<f32>) -> tensor<128xf32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10xf32> | ||
// CHECK-SAME: -> tensor<128xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [1] : (tensor<128x10xf32>, tensor<f32>) -> tensor<128xf32> | ||
return %0 : tensor<128xf32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_2to0dim(%arg0: tensor<128x10xf32>, %cst_0: tensor<f32>) -> tensor<f32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [0 : i32, 1 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128x10xf32> | ||
// CHECK-SAME: -> tensor<1xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [0, 1] : (tensor<128x10xf32>, tensor<f32>) -> tensor<f32> | ||
return %0 : tensor<f32> | ||
} | ||
|
||
func.func public @test_reduce_minimum_1to0dim(%arg0: tensor<128xf32>, %cst_0: tensor<f32>) -> tensor<f32> { | ||
// CHECK: tensor.empty | ||
// CHECK: "ttir.min" | ||
// CHECK-SAME: dim_arg = [0 : i32] | ||
// CHECK-SAME: keep_dim = false | ||
// CHECK-SAME: tensor<128xf32> | ||
// CHECK-SAME: -> tensor<1xf32> | ||
%0 = stablehlo.reduce(%arg0 init: %cst_0) applies stablehlo.minimum across dimensions = [0] : (tensor<128xf32>, tensor<f32>) -> tensor<f32> | ||
return %0 : tensor<f32> | ||
} | ||
} |
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,80 @@ | ||
// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s | FileCheck %s | ||
|
||
module attributes {} { | ||
func.func public @test_reduce_min_4to3dim(%arg0: tensor<128x10x32x4xf32>) -> tensor<128x32x4xf32> { | ||
// CHECK-LABEL: func.func public @test_reduce_min_4to3dim | ||
%0 = tensor.empty() : tensor<128x32x4xf32> | ||
// CHECK: %[[MIN:[0-9]+]] = "ttnn.min" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: (tensor<128x10x32x4xf32, | ||
// CHECK-SAME: -> tensor<128x1x32x4xf32, | ||
// CHECK: "ttnn.reshape"(%[[MIN]]) | ||
// CHECK-SAME: shape = [128 : i32, 32 : i32, 4 : i32] | ||
// CHECK-SAME: tensor<128x1x32x4xf32, | ||
// CHECK-SAME: -> tensor<128x32x4xf32 | ||
%1 = "ttir.min"(%arg0, %0) <{dim_arg = [1: i32], keep_dim = false}> : (tensor<128x10x32x4xf32>, tensor<128x32x4xf32>) -> tensor<128x32x4xf32> | ||
return %1 : tensor<128x32x4xf32> | ||
} | ||
|
||
func.func public @test_reduce_min_4to0dim(%arg0: tensor<128x10x32x4xbf16>) -> tensor<1xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_min_4to0dim | ||
%0 = tensor.empty() : tensor<1xbf16> | ||
// CHECK-NOT: dim_arg = [1 : i32] | ||
// CHECK: %[[MIN:[0-9]+]] = "ttnn.min" | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: (tensor<128x10x32x4xbf16, | ||
// CHECK-SAME: -> tensor<1x1x1x1xbf16, | ||
// CHECK: "ttnn.reshape"(%[[MIN]]) | ||
// CHECK-SAME: shape = [1 : i32] | ||
// CHECK-SAME: tensor<1x1x1x1xbf16, | ||
// CHECK-SAME: -> tensor<1xbf16 | ||
%1 = "ttir.min"(%arg0, %0) <{dim_arg = [0 : i32, 1 : i32, 2 : i32, 3 : i32], keep_dim = false}> : (tensor<128x10x32x4xbf16>, tensor<1xbf16>) -> tensor<1xbf16> | ||
return %1 : tensor<1xbf16> | ||
} | ||
|
||
func.func public @test_reduce_min_3to2dim(%arg0: tensor<128x10x4xf32>) -> tensor<128x4xf32> { | ||
// CHECK-LABEL: func.func public @test_reduce_min_3to2dim | ||
%0 = tensor.empty() : tensor<128x4xf32> | ||
// CHECK: %[[MIN:[0-9]+]] = "ttnn.min" | ||
// CHECK-SAME: dim_arg = [1 : i32] | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: (tensor<128x10x4xf32, | ||
// CHECK-SAME: -> tensor<128x1x4xf32, | ||
// CHECK: "ttnn.reshape"(%[[MIN]]) | ||
// CHECK-SAME: shape = [128 : i32, 4 : i32] | ||
// CHECK-SAME: tensor<128x1x4xf32, | ||
// CHECK-SAME: -> tensor<128x4xf32 | ||
%1 = "ttir.min"(%arg0, %0) <{dim_arg = [1: i32], keep_dim = false}> : (tensor<128x10x4xf32>, tensor<128x4xf32>) -> tensor<128x4xf32> | ||
return %1 : tensor<128x4xf32> | ||
} | ||
|
||
func.func public @test_reduce_min_3to0dim(%arg0: tensor<128x10x4xbf16>) -> tensor<1xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_min_3to0dim | ||
%0 = tensor.empty() : tensor<1xbf16> | ||
// CHECK-NOT: dim_arg = [1 : i32] | ||
// CHECK: %[[MIN:[0-9]+]] = "ttnn.min" | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: (tensor<128x10x4xbf16, | ||
// CHECK-SAME: -> tensor<1x1x1xbf16, | ||
// CHECK: "ttnn.reshape"(%[[MIN]]) | ||
// CHECK-SAME: shape = [1 : i32] | ||
// CHECK-SAME: tensor<1x1x1xbf16, | ||
// CHECK-SAME: -> tensor<1xbf16 | ||
%1 = "ttir.min"(%arg0, %0) <{dim_arg = [0 : i32, 1 : i32, 2 : i32], keep_dim = false}> : (tensor<128x10x4xbf16>, tensor<1xbf16>) -> tensor<1xbf16> | ||
return %1 : tensor<1xbf16> | ||
} | ||
|
||
func.func public @test_reduce_min_1to0dim(%arg0: tensor<128xbf16>) -> tensor<1xbf16> { | ||
// CHECK-LABEL: func.func public @test_reduce_min_1to0dim | ||
%0 = tensor.empty() : tensor<1xbf16> | ||
// CHECK-NOT: dim_arg = [0 : i32] | ||
// CHECK-NOT: ttnn.reshape | ||
// CHECK: %[[MIN:[0-9]+]] = "ttnn.min" | ||
// CHECK-SAME: keep_dim = true | ||
// CHECK-SAME: (tensor<128xbf16, | ||
// CHECK-SAME: -> tensor<1xbf16, | ||
%1 = "ttir.min"(%arg0, %0) <{dim_arg = [0 : i32], keep_dim = false}> : (tensor<128xbf16>, tensor<1xbf16>) -> tensor<1xbf16> | ||
return %1 : tensor<1xbf16> | ||
} | ||
} |
Oops, something went wrong.