ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Shape.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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 "kernels/Shape.h"
18#include "kernels/Utils.h"
19
20namespace luci_interpreter
21{
22namespace kernels
23{
24
25ShapeKernel::ShapeKernel(const Tensor *input, Tensor *output, const ShapeParams &params)
26 : KernelWithParams<ShapeParams>({input}, {output}, params)
27{
28}
29
31{
32 LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::S32 or
33 output()->element_type() == DataType::S64);
34 const auto input_shape = input()->shape();
35
37 output_shape.dim(0) = input_shape.num_dims();
38
40}
41
43{
44 switch (params().out_type)
45 {
46 case DataType::S32:
47 evalInt<int32_t>();
48 break;
49 case DataType::S64:
50 evalInt<int64_t>();
51 break;
52 default:
53 throw std::runtime_error("luci-intp Shape Unsupported type.");
54 }
55}
56
57template <typename T> void ShapeKernel::evalInt() const
58{
59 const auto input_shape = input()->shape();
60
61 auto output_data = getTensorData<T>(output());
62
63 for (int i = 0; i < input_shape.num_dims(); ++i)
64 {
65 output_data[i] = input_shape.dim(i);
66 }
67}
68
69} // namespace kernels
70} // namespace luci_interpreter
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
ShapeKernel(const Tensor *input, Tensor *output, const ShapeParams &params)
Definition Shape.cpp:25
void execute() const override
Definition Shape.cpp:42
const Tensor * input() const
Definition Shape.h:33
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
const luci_interpreter::RuntimeShape output_shape