Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / BroadcastToLayer.cc
1 /*
2  * Copyright (c) 2020 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 "BroadcastToLayer.h"
18
19 #include <cker/operation/BroadcastTo.h>
20
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace ops
28 {
29
30 BroadcastToLayer::BroadcastToLayer() : _input(nullptr), _shape(nullptr), _output(nullptr)
31 {
32   // DO NOTHING
33 }
34
35 void BroadcastToLayer::configure(const IPortableTensor *input, const IPortableTensor *shape,
36                                  IPortableTensor *output)
37 {
38   _input = input;
39   _shape = shape;
40   _output = output;
41 }
42
43 void BroadcastToLayer::run()
44 {
45   // NOTE : It was implemented follows tf.broadcast_to operation works and
46   //        Api Document(https://www.tensorflow.org/api_docs/python/tf/broadcast_to)
47
48   switch (_output->data_type())
49   {
50     // ToDo : It need to support INT8 and UINT8 also when will be applied quantization.
51     case OperandType::FLOAT32:
52       nnfw::cker::BroadcastTo<float>(
53           getTensorShape(_input), reinterpret_cast<float *>(_input->buffer()),
54           getTensorShape(_output), reinterpret_cast<float *>(_output->buffer()));
55       break;
56     case OperandType::INT32:
57       nnfw::cker::BroadcastTo<int32_t>(
58           getTensorShape(_input), reinterpret_cast<int32_t *>(_input->buffer()),
59           getTensorShape(_output), reinterpret_cast<int32_t *>(_output->buffer()));
60       break;
61     case OperandType::UINT32:
62       nnfw::cker::BroadcastTo<uint32_t>(
63           getTensorShape(_input), reinterpret_cast<uint32_t *>(_input->buffer()),
64           getTensorShape(_output), reinterpret_cast<uint32_t *>(_output->buffer()));
65       break;
66     default:
67       throw std::runtime_error{"BroadcastToLayer: unsupported data type"};
68   }
69 }
70
71 } // namespace ops
72 } // namespace cpu
73 } // namespace backend
74 } // namespace onert