df3f8b7cd1eec0a5fb8e84cb2047563447f1a8d8
[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() : _input(nullptr), _value(nullptr), _output(nullptr)
33 {
34   // DO NOTHING
35 }
36
37 void FillLayer::configure(const IPortableTensor *input, const IPortableTensor *value,
38                           IPortableTensor *output)
39 {
40   _input = input;
41   _value = value;
42   _output = output;
43 }
44
45 void FillLayer::run()
46 {
47   switch (_output->data_type())
48   {
49     case OperandType::FLOAT32:
50       nnfw::cker::Fill<float *>(getTensorShape(_input), reinterpret_cast<int *>(_input->buffer()),
51                                 reinterpret_cast<float *>(_value->buffer()),
52                                 getTensorShape(_output),
53                                 reinterpret_cast<float *>(_output->buffer()));
54       break;
55     case OperandType::INT32:
56       nnfw::cker::Fill<int32_t *>(getTensorShape(_input), reinterpret_cast<int *>(_input->buffer()),
57                                   reinterpret_cast<int32_t *>(_value->buffer()),
58                                   getTensorShape(_output),
59                                   reinterpret_cast<int32_t *>(_output->buffer()));
60       break;
61     case OperandType::INT64:
62       nnfw::cker::Fill<int64_t *>(getTensorShape(_input), reinterpret_cast<int *>(_input->buffer()),
63                                   reinterpret_cast<int64_t *>(_value->buffer()),
64                                   getTensorShape(_output),
65                                   reinterpret_cast<int64_t *>(_output->buffer()));
66       break;
67     case OperandType::UINT32:
68       nnfw::cker::Fill<uint32_t *>(
69           getTensorShape(_input), reinterpret_cast<int *>(_input->buffer()),
70           reinterpret_cast<uint32_t *>(_value->buffer()), getTensorShape(_output),
71           reinterpret_cast<uint32_t *>(_output->buffer()));
72       break;
73     default:
74       throw std::runtime_error{"Fill: unsupported data type"};
75   }
76 }
77
78 } // namespace ops
79 } // namespace cpu
80 } // namespace backend
81 } // namespace onert