ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LogSoftmax.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 "PALLogSoftmax.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 dim_count = inputs_shape.dimensionsCount();
66
67 const auto trailing_dim = dim_count - 1;
68
69 int flat_size = 1;
70 for (int i = 0; i < inputs_shape.dimensionsCount(); ++i)
71 {
72 flat_size *= (i == trailing_dim) ? 1 : inputs_shape.dims(i);
73 }
74
76 params.num_rows = flat_size;
77
78 assert(inputs_shape.dims(trailing_dim) == outputs_shape.dims(trailing_dim));
79 params.row_size = inputs_shape.dims(trailing_dim);
80
81 status = pal::LogSoftmax(params, core::utils::castInputData<float>(input_data),
82 core::utils::castOutputData<float>(output_data));
83 }
84 break;
85#endif // DIS_FLOAT
86 default:
87 {
88 status = UnsupportedType;
89 assert(false && "Unsupported type.");
90 }
91 }
92
93 return status;
94}
95
96} // namespace execute
97} // namespace onert_micro
constexpr uint32_t outputTensorIdx
OMStatus LogSoftmax(const core::LogSoftmaxParams &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_CircleLogSoftmax(const OMExecuteArgs &execute_args)
@ UnsupportedType
Definition OMStatus.h:26