ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Transpose.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#include "core/OMKernelData.h"
21
23#include "execute/OMUtils.h"
25
26#include "PALTranspose.h"
27
28using namespace onert_micro;
29using namespace onert_micro::core;
30using namespace onert_micro::execute;
31
32namespace
33{
34constexpr int kInputTensorIdx = 0;
35constexpr int kPermTensorIdx = 1;
36constexpr int kOutputTensorIdx = 0;
37
38} // namespace
39
40namespace onert_micro
41{
42namespace execute
43{
44
46{
47 core::OMRuntimeContext &runtime_context = execute_args.runtime_context;
48 core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage;
49 uint16_t op_index = execute_args.kernel_index;
50
51 const circle::Tensor *input;
52 const circle::Tensor *perm;
53 const circle::Tensor *output;
54
55 uint8_t *input_data;
56 uint8_t *perm_data;
57 uint8_t *output_data;
58
59 OMStatus status = Ok;
60
61 // Read kernel
62 {
63 execute::OMRuntimeKernel runtime_kernel;
64 status = runtime_kernel.readKernel(op_index, runtime_context);
65 if (status != Ok)
66 return status;
67
68 input = runtime_kernel.inputs[kInputTensorIdx];
69 perm = runtime_kernel.inputs[kPermTensorIdx];
70 output = runtime_kernel.outputs[kOutputTensorIdx];
71 assert(input != nullptr);
72 assert(perm != nullptr);
73 assert(output != nullptr);
74
75 status = runtime_kernel.getDataFromStorage(op_index, runtime_storage, runtime_context);
76 if (status != Ok)
77 return status;
78
79 input_data = runtime_kernel.inputs_data[kInputTensorIdx];
80 perm_data = runtime_kernel.inputs_data[kPermTensorIdx];
81 output_data = runtime_kernel.outputs_data[kOutputTensorIdx];
82 assert(input_data != nullptr);
83 assert(perm_data != nullptr);
84 assert(output_data != nullptr);
85 }
86
87 OMRuntimeShape perm_shape(perm);
88 OMRuntimeShape input_shape(input);
90
91 for (int idx = 0; idx < input_shape.dimensionsCount(); ++idx)
92 assert(reinterpret_cast<int32_t *>(perm_data)[idx] >= 0 and
93 perm_data[idx] < input_shape.dimensionsCount());
94
96 params.perm_count = perm_shape.dims(0);
97 for (int i = 0; i < params.perm_count; ++i)
98 params.perm[i] = reinterpret_cast<int32_t *>(perm_data)[i];
99
100 switch (input->type())
101 {
102#ifndef DIS_FLOAT
103 case circle::TensorType_FLOAT32:
104 status = pal::Transpose<float>(params, input_shape, reinterpret_cast<float *>(input_data),
105 output_shape, reinterpret_cast<float *>(output_data));
106 break;
107#endif // DIS_FLOAT
108#ifndef DIS_QUANT
109 case circle::TensorType_INT8:
110 {
111 status = pal::Transpose<int8_t>(params, input_shape, reinterpret_cast<int8_t *>(input_data),
112 output_shape, reinterpret_cast<int8_t *>(output_data));
113 }
114 break;
115#endif // DIS_QUANT
116 default:
117 {
118 status = UnsupportedActivation;
119 assert(false && "Unsupported type.");
120 }
121 }
122
123 return status;
124}
125
126} // namespace execute
127} // namespace onert_micro
size_t dimensionsCount() const noexcept
uint8_t * outputs_data[maxOutputSize]
OMStatus getDataFromStorage(uint16_t op_index, core::OMRuntimeStorage &storage, core::OMRuntimeContext &context)
OMStatus readKernel(uint16_t op_index, core::OMRuntimeContext &runtime_context)
const circle::Tensor * outputs[maxOutputSize]
const circle::Tensor * inputs[maxInputSize]
const luci_interpreter::RuntimeShape output_shape
OMStatus execute_kernel_CircleTranspose(const OMExecuteArgs &execute_args)
Definition Transpose.cpp:45
@ UnsupportedActivation
Definition OMStatus.h:28
core::OMRuntimeContext & runtime_context
core::OMRuntimeStorage & runtime_storage