Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / compiler / locomotiv / src / Node / Forward.cpp
1 /*
2  * Copyright (c) 2019 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 "NodeExecution.h"
18
19 #include "NodeDataImpl.h"
20 #include "NodeDomain.h"
21 #include "Validation.h"
22
23 #include <stdexcept>
24 #include <cassert>
25
26 namespace
27 {
28
29 using namespace locomotiv;
30
31 void execute_node(loco::Forward *forward)
32 {
33   auto input_data = annot_data(forward->input());
34
35   validate(input_data, "Input not ready");
36   validate(annot_domain(forward->input()) != loco::Domain::Unknown,
37            "Input domain must not Unknown");
38
39   std::unique_ptr<NodeData> forward_data = nullptr;
40
41   switch (input_data->dtype())
42   {
43     case loco::DataType::S32:
44     {
45       auto input_bufptr = input_data->as_s32_bufptr();
46       forward_data = make_data(*input_bufptr);
47       break;
48     }
49     case loco::DataType::FLOAT32:
50     {
51       auto input_bufptr = input_data->as_f32_bufptr();
52       forward_data = make_data(*input_bufptr);
53       break;
54     }
55     default:
56       throw std::runtime_error("NYI for this DataType");
57   }
58
59   assert(forward_data != nullptr);
60   annot_data(forward, std::move(forward_data));
61   annot_domain(forward, annot_domain(forward->input()));
62 }
63
64 } // namespace
65
66 namespace locomotiv
67 {
68
69 void NodeExecution::execute(loco::Forward *forward) { execute_node(forward); }
70
71 } // namespace locomotiv