2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This file contains ANeuralNetworksExecution class for handling Execution NNAPI such as
20 * ANeuralNetworksExecution_create, ANeuralNetworksExecution_setInput
21 * @ingroup COM_AI_RUNTIME
24 #ifndef __EXECUTION_H__
25 #define __EXECUTION_H__
27 #include "internal/arm_compute.h"
28 #include "internal/Sink.h"
29 #include "internal/Source.h"
32 * @brief struct to express Execution of NNAPI
34 struct ANeuralNetworksExecution
38 * @brief Construct with params
39 * @param [in] plan Pointer to get internal::arm_compute::Plan
41 ANeuralNetworksExecution(const std::shared_ptr<const internal::arm_compute::Plan> &plan)
44 _sources.resize(_plan->model().inputs.size());
45 _sinks.resize(_plan->model().outputs.size());
50 * @brief Get reference of internal::arm_compute::Plan
51 * @return Const reference of internal::arm_compute::Plan
53 const internal::arm_compute::Plan &plan(void) const { return *_plan; }
56 std::shared_ptr<const internal::arm_compute::Plan> _plan;
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
65 // TODO Use InputIndex instead of int
66 void source(int n, std::unique_ptr<Source> &&source) { _sources.at(n) = std::move(source); }
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
73 template <typename T, typename... Args> void source(int n, Args &&... args)
75 source(n, std::unique_ptr<T>{new T{std::forward<Args>(args)...}});
80 * @brief Get the nth source
81 * @param [in] n Index of the nth source
82 * @return Const reference of Source
84 const Source &source(int n) const { return *(_sources.at(n)); }
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
93 // TODO Use OutputIndex instead of int
94 void sink(int n, std::unique_ptr<Sink> &&sink) { _sinks.at(n) = std::move(sink); }
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
101 template <typename T, typename... Args> void sink(int n, Args &&... args)
103 sink(n, std::unique_ptr<T>{new T{std::forward<Args>(args)...}});
108 * @brief Get the nth sink
109 * @param [in] n Index of the nth sink
110 * @return Const reference of Sink
112 const Sink &sink(int n) const { return *(_sinks.at(n)); }
115 std::vector<std::unique_ptr<Source>> _sources;
116 std::vector<std::unique_ptr<Sink>> _sinks;