ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Cast.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#include "core/OMDataType.h"
22
24#include "execute/OMUtils.h"
26
27#include "PALCast.h"
28
29using namespace onert_micro;
30using namespace onert_micro::execute;
31
32namespace
33{
34
35constexpr uint32_t inputTensorIdx = 0;
36constexpr uint32_t outputTensorIdx = 0;
37
38} // namespace
39
40// NOTE: doesnt currently support dynamic shapes
41namespace onert_micro
42{
43namespace execute
44{
45
47{
48 const circle::Tensor *input = nullptr;
49 const circle::Tensor *output = nullptr;
50
51 uint8_t *input_data = nullptr;
52 uint8_t *output_data = nullptr;
53
54 SISOHeader(execute_args, &input, &output, &input_data, &output_data);
55
56 OMStatus status;
57
58 switch (input->type())
59 {
60#ifndef DIS_FLOAT
61 case circle::TensorType_FLOAT32:
62 {
63 switch (output->type())
64 {
65 case circle::TensorType_INT32:
66 {
67 status = pal::Cast(
68 core::OMRuntimeShape(input), core::utils::castInputData<float>(input_data),
69 core::OMRuntimeShape(output), core::utils::castOutputData<int32_t>(output_data));
70 break;
71 }
72 case circle::TensorType_INT8:
73 {
74 status = pal::Cast(
75 core::OMRuntimeShape(input), core::utils::castInputData<float>(input_data),
76 core::OMRuntimeShape(output), core::utils::castOutputData<int8_t>(output_data));
77 break;
78 }
79 case circle::TensorType_INT16:
80 {
81 status = pal::Cast(
82 core::OMRuntimeShape(input), core::utils::castInputData<float>(input_data),
83 core::OMRuntimeShape(output), core::utils::castOutputData<int16_t>(output_data));
84 break;
85 }
86 default:
87 {
88 status = UnsupportedType;
89 assert(false && "Unsupported type.");
90 break;
91 }
92 }
93 }
94 break;
95#endif // DIS_FLOAT
96 default:
97 {
98 status = UnsupportedType;
99 assert(false && "Unsupported type.");
100 break;
101 }
102 }
103
104 return status;
105}
106
107} // namespace execute
108} // namespace onert_micro
constexpr uint32_t outputTensorIdx
OMStatus Cast(const core::OMRuntimeShape &input_shape, const FromT *input_data, const core::OMRuntimeShape &output_shape, ToT *output_data)
Definition PALCast.h:34
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_CircleCast(const OMExecuteArgs &execute_args)
Definition Cast.cpp:46
@ UnsupportedType
Definition OMStatus.h:26