From 6fb1f04baf64e03e721f11100be3f44ab49e673f Mon Sep 17 00:00:00 2001 From: Renjie Liu Date: Thu, 26 Mar 2020 08:02:19 -0700 Subject: [PATCH] Add add/mul/relu to gpu target PiperOrigin-RevId: 303112045 Change-Id: Ieb3880f299453d87c3c3ebc3ab27390ca9d532b3 --- .../experimental/estimators/gpu_estimators.h | 39 +++++++++++++++++++ tensorflow/compiler/mlir/lite/ir/tfl_ops.td | 13 +++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tensorflow/compiler/mlir/lite/experimental/estimators/gpu_estimators.h b/tensorflow/compiler/mlir/lite/experimental/estimators/gpu_estimators.h index c7eed171455..52ede7c8c5b 100644 --- a/tensorflow/compiler/mlir/lite/experimental/estimators/gpu_estimators.h +++ b/tensorflow/compiler/mlir/lite/experimental/estimators/gpu_estimators.h @@ -16,6 +16,19 @@ limitations under the License. #ifndef TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_ESTIMATORS_GPU_ESTIMATORS_H_ #define TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_ESTIMATORS_GPU_ESTIMATORS_H_ +// tfl.add +template <> +class TFLiteCostEstimator { + public: + static double GetCost(mlir::Operation* op) { + llvm::errs() << "No defined cost function for op: " + << op->getName().getStringRef().str(); + return 0.0; + } + + static bool IsSupported(mlir::Operation* op) { return true; } +}; + // tfl.average_pool_2d template <> class TFLiteCostEstimator { @@ -69,5 +82,31 @@ class TFLiteCostEstimator { static bool IsSupported(mlir::Operation* op) { return true; } }; +// tfl.mul +template <> +class TFLiteCostEstimator { + public: + static double GetCost(mlir::Operation* op) { + llvm::errs() << "No defined cost function for op: " + << op->getName().getStringRef().str(); + return 0.0; + } + + static bool IsSupported(mlir::Operation* op) { return true; } +}; + +// tfl.relu +template <> +class TFLiteCostEstimator { + public: + static double GetCost(mlir::Operation* op) { + llvm::errs() << "No defined cost function for op: " + << op->getName().getStringRef().str(); + return 0.0; + } + + static bool IsSupported(mlir::Operation* op) { return true; } +}; + #endif // TENSORFLOW_COMPILER_MLIR_LITE_EXPERIMENTAL_ESTIMATORS_GPU_ESTIMATORS_H_ diff --git a/tensorflow/compiler/mlir/lite/ir/tfl_ops.td b/tensorflow/compiler/mlir/lite/ir/tfl_ops.td index 332b6d84f23..6394509880b 100644 --- a/tensorflow/compiler/mlir/lite/ir/tfl_ops.td +++ b/tensorflow/compiler/mlir/lite/ir/tfl_ops.td @@ -360,7 +360,10 @@ an output element, this operation computes \\(y = |x|\\). let hasFolder = 1; } -def TFL_AddOp : TFL_Op<"add", [ResultsBroadcastableShape, NoSideEffect, Commutative]> { +def TFL_AddOp : TFL_Op<"add", [ResultsBroadcastableShape, + NoSideEffect, + Commutative, + TFL_GpuTargetOp]> { let summary = "Addition operator"; let description = [{ @@ -1869,7 +1872,10 @@ def TFL_MinimumOp : TFL_Op<"minimum", [ let hasOptions = 0; } -def TFL_MulOp : TFL_Op<"mul", [ResultsBroadcastableShape, NoSideEffect, Commutative]> { +def TFL_MulOp : TFL_Op<"mul", [ResultsBroadcastableShape, + NoSideEffect, + Commutative, + TFL_GpuTargetOp]> { let summary = "Multiplication operator"; let description = [{ @@ -2102,7 +2108,8 @@ def TFL_RankOp: TFL_Op<"rank", [NoSideEffect]> { def TFL_ReluOp: TFL_Op<"relu", [NoSideEffect, SameOperandsAndResultShape, - SameOperandsAndResultsScale]> { + SameOperandsAndResultsScale, + TFL_GpuTargetOp]> { let summary = "Relu operator"; let description = [{