c482d8b04ebc94a462f364e8e0bf043da91fc3c1
[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 locomotiv
28 {
29
30 void NodeExecution::execute(loco::Pull *pull)
31 {
32 // TODO Remove deprecated code
33 #if 0
34   validate(annot_data(pull), "Data for Pull is not ready");
35
36   validate(annot_domain(pull) == loco::Domain::Tensor, "Domain for Pull is not Tensor");
37
38   // DO NOTHING
39 #endif
40
41   auto input_data = user_data(pull);
42
43   validate(input_data, "Input not ready");
44   // User always passes a "Tensor"
45
46   std::unique_ptr<NodeData> pull_data = nullptr;
47
48   // Q. Is it possible to use generic one?
49   switch (input_data->dtype())
50   {
51     case loco::DataType::S32:
52     {
53       auto input_bufptr = input_data->as_s32_bufptr();
54       pull_data = make_data(*input_bufptr);
55       break;
56     }
57     case loco::DataType::FLOAT32:
58     {
59       auto input_bufptr = input_data->as_f32_bufptr();
60       pull_data = make_data(*input_bufptr);
61       break;
62     }
63     default:
64       throw std::runtime_error("NYI for this DataType");
65   }
66
67   assert(pull_data != nullptr);
68   annot_data(pull, std::move(pull_data));
69   annot_domain(pull, loco::Domain::Tensor);
70 }
71
72 } // namespace locomotiv