From d91a039e0eda6fd70dcd22672b8ce1817c1ca50e Mon Sep 17 00:00:00 2001 From: Chunseok Lee Date: Thu, 5 Mar 2020 15:10:09 +0900 Subject: catch up to tizen_5.5 and remove unness dir - update to tizen_5.5 - remove dirs --- runtimes/libs/cker/include/cker/operation/Add.h | 95 +++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 runtimes/libs/cker/include/cker/operation/Add.h (limited to 'runtimes/libs/cker/include/cker/operation/Add.h') diff --git a/runtimes/libs/cker/include/cker/operation/Add.h b/runtimes/libs/cker/include/cker/operation/Add.h new file mode 100644 index 000000000..703d617f8 --- /dev/null +++ b/runtimes/libs/cker/include/cker/operation/Add.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2017 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 __NNFW_CKER_ADD_H__ +#define __NNFW_CKER_ADD_H__ + +#include "cker/Shape.h" +#include "cker/Types.h" +#include "cker/Utils.h" + +namespace nnfw +{ +namespace cker +{ + +struct AddParam +{ + // Shape dependent / common to data / op types. + // BroadcastableOpCategory broadcast_category; + // uint8 inference params. + int32_t input1_offset; + int32_t input2_offset; + int32_t output_offset; + int32_t output_multiplier; + int32_t output_shift; + // Add / Sub, not Mul, uint8 inference params. + int32_t left_shift; + int32_t input1_multiplier; + int32_t input1_shift; + int32_t input2_multiplier; + int32_t input2_shift; + // uint8, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; + + // Processed output dimensions. + // Let input "a" be the one that broadcasts in the faster-changing dimension. + // Then, after coalescing, for shapes {a0, a1, a2, a3, a4} and + // {b0, b1, b2, b3, b4}, + // broadcast_shape[4] = b0 = a0. + // broadcast_shape[3] = b1; a1 = 1. + // broadcast_shape[2] = b2 = a2. + // broadcast_shape[1] = a3; b3 = 1. + // broadcast_shape[0] = b4 = a4. + // int broadcast_shape[5]; +}; + +template +inline void Add(const AddParam ¶ms, const Shape &input1_shape, const T *input1_data, + const Shape &input2_shape, const T *input2_data, const Shape &output_shape, + T *output_data) +{ + const int32_t flat_size = MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) + { + output_data[i] = ActivationFunctionWithMinMax(input1_data[i] + input2_data[i], + params.quantized_activation_min, + params.quantized_activation_max); + } +} + +inline void Add(const AddParam ¶ms, const Shape &input1_shape, const float *input1_data, + const Shape &input2_shape, const float *input2_data, const Shape &output_shape, + float *output_data) +{ + const int size = MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < size; i++) + { + auto x = input1_data[i] + input2_data[i]; + output_data[i] = + ActivationFunctionWithMinMax(x, params.float_activation_min, params.float_activation_max); + } +} + +} // namespace cker +} // namespace nnfw + +#endif // __NNFW_CKER_ADD_H__ -- cgit v1.2.3