-
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.
Added support for stablehlo.convert op
* stablehlo.convert op is used to convert data type of a variable * Introduced a new TTIR::cast Op to map stablehlo.convert which is used instead of TTIR::to_layout op to avoid adding layout information in TTIR mlir graph. * TTIR::cast op is then lowered to TTNN::to_layout
- Loading branch information
1 parent
9abcba1
commit 9034e8a
Showing
5 changed files
with
84 additions
and
3 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,26 @@ | ||
// REQUIRES: stablehlo | ||
// RUN: ttmlir-opt --stablehlo-to-ttir-pipeline %s | FileCheck %s | ||
#any_device = #tt.operand_constraint<dram|l1|scalar|tile|any_device|any_device_tile> | ||
module @jit_eltwise_convert attributes {} { | ||
func.func public @test_convert(%arg0: tensor<2x4xf32>) -> tensor<2x4xbf16> { | ||
%0 = stablehlo.convert %arg0 : (tensor<2x4xf32>) -> tensor<2x4xbf16> | ||
// CHECK: %[[C:.*]] = tensor.empty[[C:.*]] | ||
// CHECK: %[[C:.*]] = "ttir.typecast" | ||
// CHECK-SAME: (tensor<2x4xf32>, tensor<2x4xbf16>) -> tensor<2x4xbf16> | ||
return %0 : tensor<2x4xbf16> | ||
} | ||
} | ||
|
||
module @jit_eltwise_add attributes {} { | ||
func.func public @test_add(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { | ||
%0 = stablehlo.convert %arg0 : tensor<13x21x3xf32> | ||
// CHECK: %[[C:.*]] = tensor.empty[[C:.*]] | ||
// CHECK: %[[ARG1:.*]] = "ttir.typecast"[[C:.*]] | ||
%1 = stablehlo.convert %arg1 : tensor<13x21x3xf32> | ||
// CHECK: %[[C:.*]] = tensor.empty[[C:.*]] | ||
// CHECK: %[[ARG2:.*]] = "ttir.typecast"[[C:.*]] | ||
%2 = stablehlo.add %0, %1 : tensor<13x21x3xf32> | ||
// CHECK: %[[C:.*]] = "ttir.add"(%[[ARG1]], %[[ARG2]], | ||
return %2 : tensor<13x21x3xf32> | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/ttmlir/Dialect/TTNN/eltwise/unary/cast/simple_cast.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,13 @@ | ||
// 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 @forward(%arg0: tensor<64x128xf32>) -> tensor<64x128xbf16> { | ||
%0 = tensor.empty() : tensor<64x128xbf16> | ||
// CHECK: {{.*}} = "ttnn.empty"{{.*}} | ||
%1 = "ttir.typecast"(%arg0, %0) <{operandSegmentSizes = array<i32: 1, 1>, operand_constraints = [#any_device, #any_device]}> : (tensor<64x128xf32>, tensor<64x128xbf16>) -> tensor<64x128xbf16> | ||
// CHECK: %[[C:.*]] = "ttnn.to_layout" | ||
// CHECK-SAME: tensor<64x128xf32, | ||
// CHECK-SAME: tensor<64x128xbf16, | ||
return %1 : tensor<64x128xbf16> | ||
} | ||
} |