ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
L2Normalize.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "OMStatus.h"
18
19#include "core/OMUtils.h"
20
23
24#include "execute/OMUtils.h"
25#include "PALL2Normalize.h"
26
27using namespace onert_micro;
28using namespace onert_micro::execute;
29
30namespace
31{
32
33constexpr uint32_t inputTensorIdx = 0;
34constexpr uint32_t outputTensorIdx = 0;
35
36} // namespace
37
38// NOTE: doesnt currently support dynamic shapes
39namespace onert_micro
40{
41namespace execute
42{
43
45{
46 const circle::Tensor *input = nullptr;
47 const circle::Tensor *output = nullptr;
48
49 uint8_t *input_data = nullptr;
50 uint8_t *output_data = nullptr;
51
52 SISOHeader(execute_args, &input, &output, &input_data, &output_data);
53
54 OMStatus status;
55
56 switch (input->type())
57 {
58#ifndef DIS_FLOAT
59 case circle::TensorType_FLOAT32:
60 {
61
62 core::OMRuntimeShape inputs_shape(input);
63 core::OMRuntimeShape outputs_shape(output);
64
65 const auto trailing_dim = inputs_shape.dimensionsCount() - 1;
66
68 params.num_rows =
69 pal::flatSizeSkipDim(inputs_shape.dimsData(), trailing_dim, inputs_shape.dimensionsCount());
70
71 assert(inputs_shape.dims(trailing_dim) == outputs_shape.dims(trailing_dim));
72 params.row_size = inputs_shape.dims(trailing_dim);
73
74 status = pal::L2Normalization(params, core::utils::castInputData<float>(input_data),
75 core::utils::castOutputData<float>(output_data));
76 }
77 break;
78#endif // DIS_FLOAT
79 default:
80 {
81 status = UnsupportedType;
82 assert(false && "Unsupported type.");
83 }
84 }
85
86 return status;
87}
88
89} // namespace execute
90} // namespace onert_micro
constexpr uint32_t outputTensorIdx
int flatSizeSkipDim(const int32_t *dims_data, int skip_dim, int num_dims)
Definition PALUtils.h:210
OMStatus L2Normalization(const core::L2NormalizationParams &params, const float *input_data, float *output_data)
OMStatus SISOHeader(const OMExecuteArgs &execute_args, const circle::Tensor **input, const circle::Tensor **output, uint8_t **input_data, uint8_t **output_data)
Definition OMUtils.cpp:159
OMStatus execute_kernel_CircleL2Normalize(const OMExecuteArgs &execute_args)
@ UnsupportedType
Definition OMStatus.h:26