Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / compiler / dalgona / src / Utils.h
1 /*
2  * Copyright (c) 2022 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 #ifndef __DALGONA_UTILS_H__
18 #define __DALGONA_UTILS_H__
19
20 #include <luci_interpreter/Interpreter.h>
21
22 #include <pybind11/embed.h>
23
24 namespace py = pybind11;
25
26 namespace dalgona
27 {
28
29 template <typename... Args> void pySafeCall(py::object func, Args... args)
30 {
31   try
32   {
33     func(args...);
34   }
35   catch (py::error_already_set &e)
36   {
37     throw std::runtime_error(e.what());
38   }
39 }
40
41 py::dict outputPyArray(const luci::CircleNode *node, luci_interpreter::Interpreter *interpreter);
42
43 // Return a vector of Tensors(py::dict) which correspond to node's inputs
44 std::vector<py::dict> inputsPyArray(const luci::CircleNode *node,
45                                     luci_interpreter::Interpreter *interpreter);
46
47 // Return a vector of Tensors(py::dict) which correspond to the outputs of multi-out node (ex:
48 // SPLIT)
49 std::vector<py::dict> outputsPyArray(const luci::CircleNode *node,
50                                      luci_interpreter::Interpreter *interpreter);
51
52 py::object none();
53
54 bool multi_out_node(const luci::CircleNode *node);
55
56 } // namespace dalgona
57
58 #endif // __DALGONA_UTILS_H__