Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / compiler / locomotiv / src / Node / Push.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::Push *push)
32 {
33   auto from_data = annot_data(push->from());
34
35   validate(from_data, "Ingredient not ready");
36   validate(annot_domain(push->from()) == loco::Domain::Tensor, "Ingredient of Push is not tensor");
37
38   std::unique_ptr<NodeData> push_data = nullptr;
39
40   switch (from_data->dtype())
41   {
42     case loco::DataType::S32:
43     {
44       auto from_bufptr = from_data->as_s32_bufptr();
45       push_data = make_data(*from_bufptr);
46       break;
47     }
48     case loco::DataType::FLOAT32:
49     {
50       auto from_bufptr = from_data->as_f32_bufptr();
51       push_data = make_data(*from_bufptr);
52       break;
53     }
54     default:
55       throw std::runtime_error("NYI for this DataType");
56   }
57
58   assert(push_data != nullptr);
59   annot_data(push, std::move(push_data));
60   annot_domain(push, loco::Domain::Tensor);
61 }
62
63 } // namespace
64
65 namespace locomotiv
66 {
67
68 void NodeExecution::execute(loco::Push *push) { execute_node(push); }
69
70 } // namespace locomotiv