1f4b868f6091c90896403df6862ef7214273a310
[platform/core/ml/nnfw.git] / runtime / onert / frontend / nnapi / wrapper / ANeuralNetworksExecution.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 #ifndef __EXECUTION_H__
18 #define __EXECUTION_H__
19
20 #include <NeuralNetworks.h>
21
22 #include <memory>
23
24 #include "exec/Execution.h"
25
26 struct ANeuralNetworksExecution
27 {
28 public:
29   ANeuralNetworksExecution(const std::shared_ptr<onert::exec::ExecutorMap> &executors)
30       : _execution{std::make_shared<onert::exec::Execution>(executors)}
31   {
32     // DO NOTHING
33   }
34
35 public:
36   bool setInput(uint32_t index, const ANeuralNetworksOperandType *type, const void *buffer,
37                 size_t length) noexcept;
38   bool setOptionalInput(uint32_t index, const ANeuralNetworksOperandType *type, const void *buffer,
39                         size_t length) noexcept;
40   bool setOutput(uint32_t index, const ANeuralNetworksOperandType *type, void *buffer,
41                  size_t length) noexcept;
42   bool startExecute(void) noexcept;
43   bool execute(void) noexcept;
44
45   const onert::ir::OperandIndex getInputOperandIndex(int32_t index) noexcept;
46   const onert::ir::OperandIndex getOutputOperandIndex(int32_t index) noexcept;
47   bool compareDataType(const ANeuralNetworksOperandType *type,
48                        const onert::ir::OperandIndex index) noexcept;
49   bool compareShape(const ANeuralNetworksOperandType *type,
50                     const onert::ir::OperandIndex index) noexcept;
51   bool IsOptionalInput(const onert::ir::OperandIndex index) noexcept;
52   bool hasUnspecifiedDims(const onert::ir::OperandIndex index) noexcept;
53   size_t getOperandSize(const onert::ir::OperandIndex index) noexcept;
54   const std::shared_ptr<onert::exec::Execution> instance(void) noexcept;
55
56   /**
57    * @brief       Get output operand's rank
58    * @param[in]   index Output index
59    * @param[out]  rank  Output operand's rank
60    * @return      @c true if success to get rank, otherwise @c false
61    */
62   bool getOutputOperandRank(uint32_t index, uint32_t *rank) noexcept;
63   /**
64    * @brief       Get dimensions of the output operand
65    * @param[in]   index Output index
66    * @param[out]  dimensions  Output operand's dimensions
67    * @return      @c true if success to get rank, otherwise @c false
68    * @note        This must be called after execution is finished to get resolved output shape
69    *              unspecified in model
70    */
71   bool getOutputOperandDimensions(uint32_t index, uint32_t *dimensions);
72
73 private:
74   std::shared_ptr<onert::exec::Execution> _execution;
75 };
76
77 #endif