Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / FillLayer.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 "FillLayer.h"
18
19 #include "OperationUtils.h"
20
21 #include <cker/operation/Fill.h>
22
23 namespace onert
24 {
25 namespace backend
26 {
27 namespace cpu
28 {
29 namespace ops
30 {
31
32 FillLayer::FillLayer() : _value(nullptr), _output(nullptr)
33 {
34   // DO NOTHING
35 }
36
37 void FillLayer::configure(const IPortableTensor *value, IPortableTensor *output)
38 {
39   _value = value;
40   _output = output;
41 }
42
43 void FillLayer::run()
44 {
45   switch (_output->data_type())
46   {
47     case OperandType::FLOAT32:
48       nnfw::cker::Fill<float *>(reinterpret_cast<float *>(_value->buffer()),
49                                 getTensorShape(_output),
50                                 reinterpret_cast<float *>(_output->buffer()));
51       break;
52     case OperandType::INT32:
53       nnfw::cker::Fill<int32_t *>(reinterpret_cast<int32_t *>(_value->buffer()),
54                                   getTensorShape(_output),
55                                   reinterpret_cast<int32_t *>(_output->buffer()));
56       break;
57     case OperandType::INT64:
58       nnfw::cker::Fill<int64_t *>(reinterpret_cast<int64_t *>(_value->buffer()),
59                                   getTensorShape(_output),
60                                   reinterpret_cast<int64_t *>(_output->buffer()));
61       break;
62     case OperandType::UINT32:
63       nnfw::cker::Fill<uint32_t *>(reinterpret_cast<uint32_t *>(_value->buffer()),
64                                    getTensorShape(_output),
65                                    reinterpret_cast<uint32_t *>(_output->buffer()));
66       break;
67     default:
68       throw std::runtime_error{"Fill: unsupported data type"};
69   }
70 }
71
72 } // namespace ops
73 } // namespace cpu
74 } // namespace backend
75 } // namespace onert