-
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 support for logical xor op. (#1141)
* Add end-to-end implementation of the logical xor op. * Add stablehlo to ttir conversion
- Loading branch information
1 parent
9d08234
commit 9cc313f
Showing
13 changed files
with
116 additions
and
29 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
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
49 changes: 20 additions & 29 deletions
49
test/ttmlir/Conversion/StableHLOToTTIR/binary/logical_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 |
---|---|---|
@@ -1,39 +1,30 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
module @jit_eltwise_compare attributes {} { | ||
func.func public @logical_and(%arg0: tensor<13x31xi1>, %arg1: tensor<13x31xi1>) -> tensor<13x31xi1> { | ||
%0 = stablehlo.and %arg0, %arg1 : tensor<13x31xi1> | ||
// CHECK: %[[E:.*]] = tensor.empty() : tensor<13x31xbf16> | ||
module @jit_eltwise_logical attributes {} { | ||
func.func public @logical_and(%arg0: tensor<32x32xi1>, %arg1: tensor<32x32xi1>) -> tensor<32x32xi1> { | ||
// CHECK: %[[E:.*]] = tensor.empty() : [[TENSOR:tensor<32x32xbf16>]] | ||
// CHECK: = "ttir.logical_and"(%arg0, %arg1, %[[E]]) | ||
// CHECK-SAME: (tensor<13x31xbf16>, tensor<13x31xbf16>, tensor<13x31xbf16>) -> tensor<13x31xbf16> | ||
return %0 : tensor<13x31xi1> | ||
// CHECK: return %1 : tensor<13x31xbf16> | ||
// CHECK-SAME: ([[TENSOR]], [[TENSOR]], [[TENSOR]]) -> [[TENSOR]] | ||
%0 = stablehlo.and %arg0, %arg1 : tensor<32x32xi1> | ||
// CHECK: return %1 : [[TENSOR]] | ||
return %0 : tensor<32x32xi1> | ||
} | ||
|
||
func.func public @logical_or(%arg0: tensor<13x31xi1>, %arg1: tensor<13x31xi1>) -> tensor<13x31xi1> { | ||
%0 = stablehlo.or %arg0, %arg1 : tensor<13x31xi1> | ||
// CHECK: %[[E:.*]] = tensor.empty() : tensor<13x31xbf16> | ||
func.func public @logical_or(%arg0: tensor<32x32xi1>, %arg1: tensor<32x32xi1>) -> tensor<32x32xi1> { | ||
// CHECK: %[[E:.*]] = tensor.empty() : [[TENSOR:tensor<32x32xbf16>]] | ||
// CHECK: = "ttir.logical_or"(%arg0, %arg1, %[[E]]) | ||
// CHECK-SAME: (tensor<13x31xbf16>, tensor<13x31xbf16>, tensor<13x31xbf16>) -> tensor<13x31xbf16> | ||
return %0 : tensor<13x31xi1> | ||
// CHECK: return %1 : tensor<13x31xbf16> | ||
// CHECK-SAME: ([[TENSOR]], [[TENSOR]], [[TENSOR]]) -> [[TENSOR]] | ||
%0 = stablehlo.or %arg0, %arg1 : tensor<32x32xi1> | ||
// CHECK: return %1 : [[TENSOR]] | ||
return %0 : tensor<32x32xi1> | ||
} | ||
|
||
func.func public @logical_not(%arg0: tensor<13x31xi1>) -> tensor<13x31xi1> { | ||
%0 = stablehlo.not %arg0 : tensor<13x31xi1> | ||
// CHECK: %[[E:.*]] = tensor.empty() : tensor<13x31xbf16> | ||
// CHECK: = "ttir.logical_not"(%arg0, %[[E]]) | ||
// CHECK-SAME: (tensor<13x31xbf16>, tensor<13x31xbf16>) -> tensor<13x31xbf16> | ||
return %0 : tensor<13x31xi1> | ||
// CHECK: return %1 : tensor<13x31xbf16> | ||
} | ||
|
||
func.func public @logical_not_scalar(%arg0: tensor<i1>) -> tensor<i1> { | ||
%0 = stablehlo.not %arg0 : tensor<i1> | ||
// CHECK: %[[E:.*]] = tensor.empty() : tensor<1xbf16> | ||
// CHECK: = "ttir.logical_not"(%arg0, %[[E]]) | ||
// CHECK-SAME: (tensor<1xbf16>, tensor<1xbf16>) -> tensor<1xbf16> | ||
return %0 : tensor<i1> | ||
// CHECK: return %1 : tensor<1xbf16> | ||
func.func public @logical_xor(%arg0: tensor<32x32xi1>, %arg1: tensor<32x32xi1>) -> tensor<32x32xi1> { | ||
// CHECK: %[[E:.*]] = tensor.empty() : [[TENSOR:tensor<32x32xbf16>]] | ||
// CHECK: = "ttir.logical_xor"(%arg0, %arg1, %[[E]]) | ||
// CHECK-SAME: ([[TENSOR]], [[TENSOR]], [[TENSOR]]) -> [[TENSOR]] | ||
%0 = stablehlo.xor %arg0, %arg1 : tensor<32x32xi1> | ||
// CHECK: return %1 : [[TENSOR]] | ||
return %0 : tensor<32x32xi1> | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/ttmlir/Conversion/StableHLOToTTIR/unary/logical_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,21 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
module @jit_eltwise_logical attributes {} { | ||
func.func public @logical_not(%arg0: tensor<32x32xi1>) -> tensor<32x32xi1> { | ||
// CHECK: %[[E:.*]] = tensor.empty() : [[TENSOR:tensor<32x32xbf16>]] | ||
// CHECK: = "ttir.logical_not"(%arg0, %[[E]]) | ||
// CHECK-SAME: ([[TENSOR]], [[TENSOR]]) -> [[TENSOR]] | ||
%0 = stablehlo.not %arg0 : tensor<32x32xi1> | ||
// CHECK: return %1 : [[TENSOR]] | ||
return %0 : tensor<32x32xi1> | ||
} | ||
|
||
func.func public @logical_not_scalar(%arg0: tensor<i1>) -> tensor<i1> { | ||
// CHECK: %[[E:.*]] = tensor.empty() : [[TENSOR:tensor<1xbf16>]] | ||
// CHECK: = "ttir.logical_not"(%arg0, %[[E]]) | ||
// CHECK-SAME: ([[TENSOR]], [[TENSOR]]) -> [[TENSOR]] | ||
%0 = stablehlo.not %arg0 : tensor<i1> | ||
// CHECK: return %1 : [[TENSOR]] | ||
return %0 : tensor<i1> | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/ttmlir/Dialect/TTNN/eltwise/binary/logical_xor/simple_xor.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,16 @@ | ||
// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline %s | FileCheck %s | ||
|
||
#any_device = #tt.operand_constraint<dram|l1|scalar|tile|any_device|any_device_tile> | ||
module attributes {} { | ||
func.func @logical_xor(%arg0: tensor<64x128xbf16>, %arg1: tensor<64x128xbf16>) -> tensor<64x128xbf16> { | ||
// CHECK: %{{[0-9]+}} = "ttnn.empty"{{.*}} [[TENSOR:tensor<64x128xbf16]] | ||
%0 = tensor.empty() : tensor<64x128xbf16> | ||
// CHECK: %{{[0-9]+}} = "ttnn.logical_xor" | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
%1 = "ttir.logical_xor"(%arg0, %arg1, %0) <{operandSegmentSizes = array<i32: 2, 1>, operand_constraints = [#any_device, #any_device, #any_device]}> : (tensor<64x128xbf16>, tensor<64x128xbf16>, tensor<64x128xbf16>) -> tensor<64x128xbf16> | ||
return %1 : tensor<64x128xbf16> | ||
} | ||
} |
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,18 @@ | ||
// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline="system-desc-path=%system_desc_path%" %s > %t.mlir | ||
// RUN: FileCheck %s --input-file=%t.mlir | ||
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn | ||
|
||
#any_device = #tt.operand_constraint<dram|l1|scalar|tile|any_device|any_device_tile> | ||
#any_device_tile = #tt.operand_constraint<dram|l1|tile|any_device_tile> | ||
|
||
func.func @logical_xor(%arg0: tensor<64x128xbf16>, %arg1: tensor<64x128xbf16>) -> tensor<64x128xbf16> { | ||
// CHECK: %{{[0-9]+}} = "ttnn.empty"{{.*}} [[TENSOR:tensor<64x128xbf16]] | ||
%0 = tensor.empty() : tensor<64x128xbf16> | ||
// CHECK: %{{[0-9]+}} = "ttnn.logical_xor" | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: [[TENSOR]] | ||
// CHECK-SAME: -> [[TENSOR]] | ||
%1 = "ttir.logical_xor"(%arg0, %arg1, %0) <{operandSegmentSizes = array<i32: 2, 1>, operand_constraints = [#any_device, #any_device, #any_device]}> : (tensor<64x128xbf16>, tensor<64x128xbf16>, tensor<64x128xbf16>) -> tensor<64x128xbf16> | ||
return %1 : tensor<64x128xbf16> | ||
} |
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