ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
39OMStatus onert_micro::execute::execute_kernel_CircleLogSoftmax(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 dim_count = inputs_shape.dimensionsCount();
61
62 const auto trailing_dim = dim_count - 1;
63
64 int flat_size = 1;
65 for (int i = 0; i < inputs_shape.dimensionsCount(); ++i)
66 {
67 flat_size *= (i == trailing_dim) ? 1 : inputs_shape.dims(i);
68 }
69
71 params.num_rows = flat_size;
72
73 assert(inputs_shape.dims(trailing_dim) == outputs_shape.dims(trailing_dim));
74 params.row_size = inputs_shape.dims(trailing_dim);
75
76 status = pal::LogSoftmax(params, core::utils::castInputData<float>(input_data),
77 core::utils::castOutputData<float>(output_data));
78 }
79 break;
80#endif // DIS_FLOAT
81 default:
82 {
83 status = UnsupportedType;
84 assert(false && "Unsupported type.");
85 }
86 }
87
88 return status;
89}
constexpr uint32_t outputTensorIdx
list input_data
Definition infer.py:29
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
@ UnsupportedType
Definition OMStatus.h:26