ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALAddCommon.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ONERT_MICRO_EXECUTE_PAL_ADD_COMMON_H
19#define ONERT_MICRO_EXECUTE_PAL_ADD_COMMON_H
20
22
23namespace onert_micro
24{
25namespace execute
26{
27namespace pal
28{
29
30int8_t AddFunc(int8_t x, int8_t y, const core::ArithmeticQuantParams &params)
31{
32 const int32_t input1_val = params.input1_offset + x;
33 const int32_t input2_val = params.input2_offset + y;
34 const int32_t shifted_input1_val = input1_val * (1 << params.left_shift);
35 const int32_t shifted_input2_val = input2_val * (1 << params.left_shift);
36 const int32_t scaled_input1_val = multiplyByQuantizedMultiplierSmallerThanOneExp(
37 shifted_input1_val, params.input1_multiplier, params.input1_shift);
38 const int32_t scaled_input2_val = multiplyByQuantizedMultiplierSmallerThanOneExp(
39 shifted_input2_val, params.input2_multiplier, params.input2_shift);
40 const int32_t raw_sum = scaled_input1_val + scaled_input2_val;
41 const int32_t raw_output = multiplyByQuantizedMultiplierSmallerThanOneExp(
42 raw_sum, params.output_multiplier, params.output_shift) +
43 params.output_offset;
44 const int32_t clamped_output = std::min(params.quantized_activation_max,
45 std::max(params.quantized_activation_min, raw_output));
46 return static_cast<int8_t>(clamped_output);
47}
48
49template <typename T>
50OMStatus Add(const core::BinaryArithmeticBroadcastParams &params, const int flat_size,
51 const T *input1_data, const T *input2_data, T *output_data)
52{
53 ArithmeticOp<T, AddFn<T>>(params, flat_size, input1_data, input2_data, output_data);
54 return Ok;
55}
56
57template <typename T>
59 const core::OMRuntimeShape &input1_shape, const T *input1_data,
60 const core::OMRuntimeShape &input2_shape, const T *input2_data,
61 const core::OMRuntimeShape &output_shape, T *output_data)
62{
63 BroadcastArithmeticOp4DSlow<T, AddFn<T>>(params, input1_shape, input1_data, input2_shape,
64 input2_data, output_shape, output_data);
65 return Ok;
66}
67
69 const core::OMRuntimeShape &input1_shape, const int8_t *input1_data,
70 const core::OMRuntimeShape &input2_shape, const int8_t *input2_data,
71 const core::OMRuntimeShape &output_shape, int8_t *output_data)
72{
73 BroadcastBinaryFunction6DSlow(params, input1_shape, input1_data, input2_shape, input2_data,
74 output_shape, output_data, AddFunc);
75 return Ok;
76}
77
78} // namespace pal
79} // namespace execute
80} // namespace onert_micro
81
82#endif // ONERT_MICRO_EXECUTE_PAL_ADD_COMMON_H
const luci_interpreter::RuntimeShape output_shape
OMStatus BroadcastAdd4DSlow(const core::BinaryArithmeticBroadcastParams &params, const core::OMRuntimeShape &input1_shape, const T *input1_data, const core::OMRuntimeShape &input2_shape, const T *input2_data, const core::OMRuntimeShape &output_shape, T *output_data)
int32_t multiplyByQuantizedMultiplierSmallerThanOneExp(int32_t x, int32_t quantized_multiplier, int left_shift)
Definition PALUtils.h:112
OMStatus Add(const core::ArithmeticQuantParams &params, const uint32_t flat_size, const int8_t *input1_data, const int8_t *input2_data, int8_t *output_data)
Definition PALAdd.h:33
int8_t AddFunc(int8_t x, int8_t y, const core::ArithmeticQuantParams &params)
void BroadcastBinaryFunction6DSlow(const core::ArithmeticQuantParams &params, const core::OMRuntimeShape &input1_shape, const T *input1_data, const core::OMRuntimeShape &input2_shape, const T *input2_data, const core::OMRuntimeShape &output_shape, T *output_data, T(*binary_func)(T, T, const core::ArithmeticQuantParams &))