Imported Upstream version 1.25.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>(getBuffer<float>(_value), getShape(_output),
49                               getBuffer<float>(_output));
50       break;
51     case OperandType::INT32:
52       nnfw::cker::Fill<int32_t>(getBuffer<int32_t>(_value), getShape(_output),
53                                 getBuffer<int32_t>(_output));
54       break;
55     case OperandType::INT64:
56       nnfw::cker::Fill<int64_t>(getBuffer<int64_t>(_value), getShape(_output),
57                                 getBuffer<int64_t>(_output));
58       break;
59     case OperandType::UINT32:
60       nnfw::cker::Fill<uint32_t>(getBuffer<uint32_t>(_value), getShape(_output),
61                                  getBuffer<uint32_t>(_output));
62       break;
63     default:
64       throw std::runtime_error{"Fill: unsupported data type"};
65   }
66 }
67
68 } // namespace ops
69 } // namespace cpu
70 } // namespace backend
71 } // namespace onert