Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOSA to TTIR: adding simple op conversion patterns #1443

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/Conversion/TosaToTTIR/TosaToTTIRPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ void addElementwiseUnaryOpsConversionPatterns(MLIRContext *ctx,
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<tosa::AbsOp,
mlir::tt::ttir::AbsOp>>(
typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::CastOp, mlir::tt::ttir::TypecastOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<tosa::CeilOp,
mlir::tt::ttir::CeilOp>>(
typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<tosa::CosOp,
mlir::tt::ttir::CosOp>>(
typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<tosa::ExpOp,
mlir::tt::ttir::ExpOp>>(
typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::FloorOp, mlir::tt::ttir::FloorOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<tosa::NegateOp,
mlir::tt::ttir::NegOp>>(
typeConverter, ctx);
Expand All @@ -104,12 +117,29 @@ void addElementwiseBinaryOpsConversionPatterns(MLIRContext *ctx,
tosa::SubOp, mlir::tt::ttir::SubtractOp>>(typeConverter, ctx);
}

void addLogicalOpConversionPattern(MLIRContext *ctx,
RewritePatternSet &patterns,
TypeConverter &typeConverter) {
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::LogicalAndOp, mlir::tt::ttir::LogicalAndOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::LogicalOrOp, mlir::tt::ttir::LogicalOrOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::LogicalNotOp, mlir::tt::ttir::LogicalNotOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::LogicalXorOp, mlir::tt::ttir::LogicalXorOp>>(typeConverter, ctx);
}

void addCompareOpsConversionPatterns(MLIRContext *ctx,
RewritePatternSet &patterns,
TypeConverter &typeConverter) {
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::EqualOp, mlir::tt::ttir::EqualOp>>(typeConverter, ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::GreaterEqualOp, mlir::tt::ttir::GreaterEqualOp>>(typeConverter,
ctx);
patterns.add<TosaToTTIRDefaultDPSOpConversionPattern<
tosa::GreaterOp, mlir::tt::ttir::GreaterThanOp>>(typeConverter, ctx);
}

} // namespace
Expand All @@ -120,6 +150,8 @@ void populateTosaToTTIRPatterns(MLIRContext *ctx, RewritePatternSet &patterns,
TypeConverter &typeConverter) {
addElementwiseUnaryOpsConversionPatterns(ctx, patterns, typeConverter);
addElementwiseBinaryOpsConversionPatterns(ctx, patterns, typeConverter);
addLogicalOpConversionPattern(ctx, patterns, typeConverter);
addLogicalOpConversionPattern(ctx, patterns, typeConverter);
sdjukicTT marked this conversation as resolved.
Show resolved Hide resolved
addCompareOpsConversionPatterns(ctx, patterns, typeConverter);
}

Expand Down
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/compare/equal.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_equal(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xi1> {
%0 = tosa.equal %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
// CHECK: %[[EQ_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1
sdjukicTT marked this conversation as resolved.
Show resolved Hide resolved
// CHECK: %{{[0-9]+}} = "ttir.eq"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[EQ_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
sdjukicTT marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/compare/greater.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_greater(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xi1> {
%0 = tosa.greater %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
// CHECK: %[[GT_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1
// CHECK: %{{[0-9]+}} = "ttir.gt"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[GT_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/compare/greater_equal.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_greater_equal(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xi1> {
%0 = tosa.greater_equal %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
// CHECK: %[[GE_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1
// CHECK: %{{[0-9]+}} = "ttir.ge"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[GE_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_binary/add.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_add(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.add %arg0, %arg1 {shift = 0 : i8} : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[ADD_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.add"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[ADD_OUT]]){{.+}} -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
#any_device = #tt.operand_constraint<dram|l1|scalar|tile|any_device|any_device_tile>
module attributes {} {
func.func @test_mul(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.mul %arg0, %arg1 {shift = 0 : i8} : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[C:.*]] = tensor.empty[[C:.*]]
// CHECK: %[[C:.*]] = "ttir.multiply"[[C:.*]]
// CHECK: %[[MUL_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.multiply"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[MUL_OUT]]){{.+}} -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/abs.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_abs(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.abs %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[ABS_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.abs"(%arg{{[0-9]+}}, %[[ABS_OUT]]){{.+}}-> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/cast.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_cast(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xbf16> {
%0 = tosa.cast %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xbf16>
// CHECK: %[[CAST_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xbf16>
// CHECK: %{{[0-9]+}} = "ttir.typecast"(%arg{{[0-9]+}}, %[[CAST_OUT]]){{.+}} : (tensor<13x21x3xf32>, tensor<13x21x3xbf16>) -> tensor<13x21x3xbf16>
return %0 : tensor<13x21x3xbf16>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/ceil.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_ceil(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.ceil %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[CEIL_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.ceil"(%arg{{[0-9]+}}, %[[CEIL_OUT]]){{.+}}-> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/cos.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_cos(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.cos %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[COS_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.cos"(%arg{{[0-9]+}}, %[[COS_OUT]]){{.+}}-> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/elementwise_unary/exp.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_exp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.exp %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[EXP_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.exp"(%arg{{[0-9]+}}, %[[EXP_OUT]]){{.+}}-> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_floor(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
%0 = tosa.floor %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
// CHECK: %[[FLOOR_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xf32>
// CHECK: %{{[0-9]+}} = "ttir.floor"(%arg{{[0-9]+}}, %[[FLOOR_OUT]]){{.+}}-> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/logical/logical_and.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_logical_and(%arg0: tensor<13x21x3xi1>, %arg1: tensor<13x21x3xi1>) -> tensor<13x21x3xi1> {
%0 = tosa.logical_and %arg0, %arg1 : (tensor<13x21x3xi1>, tensor<13x21x3xi1>) -> tensor<13x21x3xi1>
// CHECK: %[[LOGICAL_AND_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1>
// CHECK: %{{[0-9]+}} = "ttir.logical_and"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[LOGICAL_AND_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/logical/logical_not.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_logical_not(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi1> {
%0 = tosa.logical_not %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi1>
// CHECK: %[[LOGICAL_NOT_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1>
// CHECK: %{{[0-9]+}} = "ttir.logical_not"(%arg{{[0-9]+}}, %[[LOGICAL_NOT_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/logical/logical_or.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_logical_or(%arg0: tensor<13x21x3xi1>, %arg1: tensor<13x21x3xi1>) -> tensor<13x21x3xi1> {
%0 = tosa.logical_or %arg0, %arg1 : (tensor<13x21x3xi1>, tensor<13x21x3xi1>) -> tensor<13x21x3xi1>
// CHECK: %[[LOGICAL_OR_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1>
// CHECK: %{{[0-9]+}} = "ttir.logical_or"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[LOGICAL_OR_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
9 changes: 9 additions & 0 deletions test/ttmlir/Conversion/TosaToTTIR/logical/logical_xor.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: ttmlir-opt --convert-tosa-to-ttir %s | FileCheck %s
module attributes {} {
func.func @test_logical_xor(%arg0: tensor<13x21x3xi1>, %arg1: tensor<13x21x3xi1>) -> tensor<13x21x3xi1> {
%0 = tosa.logical_xor %arg0, %arg1 : (tensor<13x21x3xi1>, tensor<13x21x3xi1>) -> tensor<13x21x3xi1>
// CHECK: %[[LOGICAL_XOR_OUT:[0-9]+]] = tensor.empty() : tensor<13x21x3xi1>
// CHECK: %{{[0-9]+}} = "ttir.logical_xor"(%arg{{[0-9]+}}, %arg{{[0-9]+}}, %[[LOGICAL_XOR_OUT]]){{.+}} -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
}
Loading