Imported Upstream version 1.4.0
[platform/core/ml/nnfw.git] / runtime / contrib / pure_arm_compute / src / execution.h
1 /*
2  * Copyright (c) 2018 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 /**
18  * @file execution.h
19  * @brief This file contains ANeuralNetworksExecution class for handling Execution NNAPI such as
20  * ANeuralNetworksExecution_create, ANeuralNetworksExecution_setInput
21  * @ingroup COM_AI_RUNTIME
22  */
23
24 #ifndef __EXECUTION_H__
25 #define __EXECUTION_H__
26
27 #include "internal/arm_compute.h"
28 #include "internal/Sink.h"
29 #include "internal/Source.h"
30
31 /**
32  * @brief struct to express Execution of NNAPI
33  */
34 struct ANeuralNetworksExecution
35 {
36 public:
37   /**
38    * @brief Construct with params
39    * @param [in] plan Pointer to get internal::arm_compute::Plan
40    */
41   ANeuralNetworksExecution(const std::shared_ptr<const internal::arm_compute::Plan> &plan)
42       : _plan{plan}
43   {
44     _sources.resize(_plan->model().inputs.size());
45     _sinks.resize(_plan->model().outputs.size());
46   }
47
48 public:
49   /**
50    * @brief Get reference of internal::arm_compute::Plan
51    * @return Const reference of internal::arm_compute::Plan
52    */
53   const internal::arm_compute::Plan &plan(void) const { return *_plan; }
54
55 private:
56   std::shared_ptr<const internal::arm_compute::Plan> _plan;
57
58 public:
59   /**
60    * @brief Set the nth source with param
61    * @param [in] n Index of the nth source
62    * @param [in] source Pointer to set the nth source from
63    * @return N/A
64    */
65   // TODO Use InputIndex instead of int
66   void source(int n, std::unique_ptr<Source> &&source) { _sources.at(n) = std::move(source); }
67   /**
68    * @brief Set the nth source with param
69    * @param [in] n Index of the nth source
70    * @param [in] args Arguments to set the nth source from
71    * @return N/A
72    */
73   template <typename T, typename... Args> void source(int n, Args &&... args)
74   {
75     source(n, std::unique_ptr<T>{new T{std::forward<Args>(args)...}});
76   }
77
78 public:
79   /**
80    * @brief Get the nth source
81    * @param [in] n Index of the nth source
82    * @return Const reference of Source
83    */
84   const Source &source(int n) const { return *(_sources.at(n)); }
85
86 public:
87   /**
88    * @brief Set the nth sink with param
89    * @param [in] n Index of the nth sink
90    * @param [in] sink Pointer to set the nth sink from
91    * @return N/A
92    */
93   // TODO Use OutputIndex instead of int
94   void sink(int n, std::unique_ptr<Sink> &&sink) { _sinks.at(n) = std::move(sink); }
95   /**
96    * @brief Set the nth sink with param
97    * @param [in] n Index of the nth sink
98    * @param [in] args Arguments to set the nth sink from
99    * @return N/A
100    */
101   template <typename T, typename... Args> void sink(int n, Args &&... args)
102   {
103     sink(n, std::unique_ptr<T>{new T{std::forward<Args>(args)...}});
104   }
105
106 public:
107   /**
108    * @brief Get the nth sink
109    * @param [in] n Index of the nth sink
110    * @return Const reference of Sink
111    */
112   const Sink &sink(int n) const { return *(_sinks.at(n)); }
113
114 private:
115   std::vector<std::unique_ptr<Source>> _sources;
116   std::vector<std::unique_ptr<Sink>> _sinks;
117 };
118
119 #endif