Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / AddNLayer.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 "AddNLayer.h"
18
19 #include "OperationUtils.h"
20
21 #include <cker/operation/AddN.h>
22 #include <assert.h>
23
24 namespace onert
25 {
26 namespace backend
27 {
28 namespace cpu
29 {
30 namespace ops
31 {
32
33 void AddNLayer::configure(std::vector<const IPortableTensor *> &&inputs, IPortableTensor *output)
34 {
35   _inputs = std::move(inputs);
36   _output = output;
37 }
38
39 void AddNLayer::run()
40 {
41   size_t input_size = _inputs.size();
42   if (_output->data_type() == ir::DataType::INT32)
43   {
44     std::vector<const int32_t *> input_buffers(input_size);
45     for (size_t i = 0; i < input_size; i++)
46     {
47       input_buffers[i] = getBuffer<int32_t>(_inputs[i]);
48     }
49     AddN(getShape(_inputs[0]), input_size, input_buffers.data(), getBuffer<int32_t>(_output));
50   }
51   else if (_output->data_type() == ir::DataType::FLOAT32)
52   {
53     std::vector<const float *> input_buffers(input_size);
54     for (size_t i = 0; i < input_size; i++)
55     {
56       input_buffers[i] = getBuffer<float>(_inputs[i]);
57     }
58     AddN(getShape(_inputs[0]), input_size, input_buffers.data(), getBuffer<float>(_output));
59   }
60   else
61   {
62     throw std::runtime_error("AddN: unsupported data type");
63   }
64 }
65
66 } // namespace ops
67 } // namespace cpu
68 } // namespace backend
69 } // namespace onert