Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / compiler / locomotiv / src / Node / Pull.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 "UserData.h"
20 #include "NodeDataImpl.h"
21 #include "NodeDomain.h"
22 #include "Validation.h"
23
24 #include <cassert>
25 #include <stdexcept>
26
27 namespace
28 {
29
30 using namespace locomotiv;
31
32 void execute_node(loco::Pull *pull)
33 {
34 // TODO Remove deprecated code
35 #if 0
36   validate(annot_data(pull), "Data for Pull is not ready");
37
38   validate(annot_domain(pull) == loco::Domain::Tensor, "Domain for Pull is not Tensor");
39
40   // DO NOTHING
41 #endif
42
43   auto input_data = user_data(pull);
44
45   validate(input_data, "Input not ready");
46   // User always passes a "Tensor"
47
48   std::unique_ptr<NodeData> pull_data = nullptr;
49
50   // Q. Is it possible to use generic one?
51   switch (input_data->dtype())
52   {
53     case loco::DataType::S32:
54     {
55       auto input_bufptr = input_data->as_s32_bufptr();
56       pull_data = make_data(*input_bufptr);
57       break;
58     }
59     case loco::DataType::FLOAT32:
60     {
61       auto input_bufptr = input_data->as_f32_bufptr();
62       pull_data = make_data(*input_bufptr);
63       break;
64     }
65     default:
66       throw std::runtime_error("NYI for this DataType");
67   }
68
69   assert(pull_data != nullptr);
70   annot_data(pull, std::move(pull_data));
71   annot_domain(pull, loco::Domain::Tensor);
72 }
73
74 } // namespace
75
76 namespace locomotiv
77 {
78
79 void NodeExecution::execute(loco::Pull *pull) { execute_node(pull); }
80
81 } // namespace locomotiv