From 61434af6c7bfb21a955494a17df983c41c8a9754 Mon Sep 17 00:00:00 2001 From: rsun Date: Tue, 8 Dec 2020 21:16:02 -0800 Subject: [PATCH 1/2] Refactor exp.h from reference_ops.h; 2nd step to port op EXP for TFLite micro --- tensorflow/lite/kernels/internal/BUILD | 2 + .../lite/kernels/internal/reference/exp.h | 37 +++++++++++++++++++ .../internal/reference/reference_ops.h | 10 +---- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 tensorflow/lite/kernels/internal/reference/exp.h diff --git a/tensorflow/lite/kernels/internal/BUILD b/tensorflow/lite/kernels/internal/BUILD index b59dc0a9fff..e9cf62521fa 100644 --- a/tensorflow/lite/kernels/internal/BUILD +++ b/tensorflow/lite/kernels/internal/BUILD @@ -457,6 +457,7 @@ cc_library( "reference/depthwiseconv_float.h", "reference/depthwiseconv_uint8.h", "reference/dequantize.h", + "reference/exp.h", "reference/fill.h", "reference/floor.h", "reference/fully_connected.h", @@ -551,6 +552,7 @@ cc_library( "reference/depthwiseconv_float.h", "reference/depthwiseconv_uint8.h", "reference/dequantize.h", + "reference/exp.h", "reference/fill.h", "reference/floor.h", "reference/fully_connected.h", diff --git a/tensorflow/lite/kernels/internal/reference/exp.h b/tensorflow/lite/kernels/internal/reference/exp.h new file mode 100644 index 00000000000..a4d6e06869a --- /dev/null +++ b/tensorflow/lite/kernels/internal/reference/exp.h @@ -0,0 +1,37 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { + +template +inline void Exp(const T* input_data, const size_t num_elements, + T* output_data) { + ruy::profiler::ScopeLabel label("Exp"); + for (size_t idx = 0; idx < num_elements; ++idx) { + output_data[idx] = std::exp(input_data[idx]); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ diff --git a/tensorflow/lite/kernels/internal/reference/reference_ops.h b/tensorflow/lite/kernels/internal/reference/reference_ops.h index afbb717bc9f..71b676c1e62 100644 --- a/tensorflow/lite/kernels/internal/reference/reference_ops.h +++ b/tensorflow/lite/kernels/internal/reference/reference_ops.h @@ -40,6 +40,7 @@ limitations under the License. #include "tensorflow/lite/kernels/internal/reference/concatenation.h" #include "tensorflow/lite/kernels/internal/reference/conv.h" #include "tensorflow/lite/kernels/internal/reference/dequantize.h" +#include "tensorflow/lite/kernels/internal/reference/exp.h" #include "tensorflow/lite/kernels/internal/reference/fill.h" #include "tensorflow/lite/kernels/internal/reference/floor.h" #include "tensorflow/lite/kernels/internal/reference/fully_connected.h" @@ -1945,15 +1946,6 @@ inline void Slice(const tflite::SliceParams& op_params, return Slice(op_params, input_shape, output_shape, &writer); } -template -inline void Exp(const T* input_data, const size_t num_elements, - T* output_data) { - ruy::profiler::ScopeLabel label("Exp"); - for (size_t idx = 0; idx < num_elements; ++idx) { - output_data[idx] = std::exp(input_data[idx]); - } -} - template void Minimum(const RuntimeShape& input1_shape, const T* input1_data, const T* input2_data, const RuntimeShape& output_shape, From 45e36f795a688400766b8b14c32566854471a4ce Mon Sep 17 00:00:00 2001 From: rsun Date: Mon, 14 Dec 2020 15:32:03 -0800 Subject: [PATCH 2/2] Add the ruy profiler header in exp.h --- tensorflow/lite/kernels/internal/reference/exp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow/lite/kernels/internal/reference/exp.h b/tensorflow/lite/kernels/internal/reference/exp.h index a4d6e06869a..134ee13fb59 100644 --- a/tensorflow/lite/kernels/internal/reference/exp.h +++ b/tensorflow/lite/kernels/internal/reference/exp.h @@ -17,6 +17,7 @@ limitations under the License. #include +#include "ruy/profiler/instrumentation.h" // from @ruy #include "tensorflow/lite/kernels/internal/types.h" namespace tflite {