ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
39OMStatus onert_micro::execute::execute_kernel_CircleL2Normalize(const OMExecuteArgs &execute_args)
40{
41 const circle::Tensor *input = nullptr;
42 const circle::Tensor *output = nullptr;
43
44 uint8_t *input_data = nullptr;
45 uint8_t *output_data = nullptr;
46
47 SISOHeader(execute_args, &input, &output, &input_data, &output_data);
48
49 OMStatus status;
50
51 switch (input->type())
52 {
53#ifndef DIS_FLOAT
54 case circle::TensorType_FLOAT32:
55 {
56
57 core::OMRuntimeShape inputs_shape(input);
58 core::OMRuntimeShape outputs_shape(output);
59
60 const auto trailing_dim = inputs_shape.dimensionsCount() - 1;
61
63 params.num_rows =
64 pal::flatSizeSkipDim(inputs_shape.dimsData(), trailing_dim, inputs_shape.dimensionsCount());
65
66 assert(inputs_shape.dims(trailing_dim) == outputs_shape.dims(trailing_dim));
67 params.row_size = inputs_shape.dims(trailing_dim);
68
69 status = pal::L2Normalization(params, core::utils::castInputData<float>(input_data),
70 core::utils::castOutputData<float>(output_data));
71 }
72 break;
73#endif // DIS_FLOAT
74 default:
75 {
76 status = UnsupportedType;
77 assert(false && "Unsupported type.");
78 }
79 }
80
81 return status;
82}
constexpr uint32_t outputTensorIdx
list input_data
Definition infer.py:29
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
@ UnsupportedType
Definition OMStatus.h:26