ba47df4abad108b7719a4814f021a166bd58db15
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / Reshape.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "Builders.h"
19
20 #include <cassert>
21 #include <cstring>
22
23 namespace luci_interpreter
24 {
25
26 void configure_kernel_CircleReshape(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
27 {
28   // Do nothing
29 }
30
31 void execute_kernel_CircleReshape(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph,
32                                   bool is_inplace)
33 {
34   const auto input_index = cur_op->inputs()->operator[](0);
35   const auto output_index = cur_op->outputs()->operator[](0);
36
37   assert(input_index != -1);
38   assert(output_index != -1);
39
40   const auto input = runtime_graph->getCircleTensorByIndex(input_index);
41   const auto output = runtime_graph->getCircleTensorByIndex(output_index);
42
43   if (is_inplace)
44   {
45     runtime_graph->makeInplaceOperation(input, output);
46     return;
47   }
48
49   const auto input_data = (runtime_graph->getDataByTensor(input));
50   auto output_data = (runtime_graph->getDataByTensor(output));
51
52   assert(input_data != nullptr);
53   assert(output_data != nullptr);
54
55   const size_t element_size = getDataTypeSize(Tensor::element_type(input));
56   const int32_t num_elements = Tensor::num_elements(input);
57   std::memcpy(output_data, input_data, num_elements * element_size);
58 }
59
60 } // namespace luci_interpreter