Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / libs / nnapi / include / NeuralNetworksTypes.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 // NOTE This header is derived from part of the following file
19 // https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/lite/nnapi/NeuralNetworksTypes.h
20
21 #ifndef __NEURAL_NETWORKS_TYPES_H__
22 #define __NEURAL_NETWORKS_TYPES_H__
23
24 #include "NeuralNetworks.h"
25
26 // NN api types based on NNAPI header file
27 // https://developer.android.com/ndk/reference/group/neural-networks
28
29 // nn api function types
30
31 typedef int (*ANeuralNetworksMemory_createFromFd_fn)(size_t size, int protect, int fd,
32                                                      size_t offset, ANeuralNetworksMemory **memory);
33
34 typedef void (*ANeuralNetworksMemory_free_fn)(ANeuralNetworksMemory *memory);
35
36 typedef int (*ANeuralNetworksModel_create_fn)(ANeuralNetworksModel **model);
37
38 typedef int (*ANeuralNetworksModel_finish_fn)(ANeuralNetworksModel *model);
39
40 typedef void (*ANeuralNetworksModel_free_fn)(ANeuralNetworksModel *model);
41
42 typedef int (*ANeuralNetworksCompilation_create_fn)(ANeuralNetworksModel *model,
43                                                     ANeuralNetworksCompilation **compilation);
44
45 typedef void (*ANeuralNetworksCompilation_free_fn)(ANeuralNetworksCompilation *compilation);
46
47 typedef int (*ANeuralNetworksCompilation_setPreference_fn)(ANeuralNetworksCompilation *compilation,
48                                                            int32_t preference);
49
50 typedef int (*ANeuralNetworksCompilation_finish_fn)(ANeuralNetworksCompilation *compilation);
51
52 typedef int (*ANeuralNetworksModel_addOperand_fn)(ANeuralNetworksModel *model,
53                                                   const ANeuralNetworksOperandType *type);
54
55 typedef int (*ANeuralNetworksModel_setOperandValue_fn)(ANeuralNetworksModel *model, int32_t index,
56                                                        const void *buffer, size_t length);
57
58 typedef int (*ANeuralNetworksModel_setOperandSymmPerChannelQuantParams_fn)(
59   ANeuralNetworksModel *model, int32_t index,
60   const ANeuralNetworksSymmPerChannelQuantParams *channelQuant);
61
62 typedef int (*ANeuralNetworksModel_setOperandValueFromMemory_fn)(
63   ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksMemory *memory, size_t offset,
64   size_t length);
65
66 typedef int (*ANeuralNetworksModel_addOperation_fn)(ANeuralNetworksModel *model,
67                                                     ANeuralNetworksOperationType type,
68                                                     uint32_t inputCount, const uint32_t *inputs,
69                                                     uint32_t outputCount, const uint32_t *outputs);
70
71 typedef int (*ANeuralNetworksModel_identifyInputsAndOutputs_fn)(ANeuralNetworksModel *model,
72                                                                 uint32_t inputCount,
73                                                                 const uint32_t *inputs,
74                                                                 uint32_t outputCount,
75                                                                 const uint32_t *outputs);
76
77 typedef int (*ANeuralNetworksModel_relaxComputationFloat32toFloat16_fn)(ANeuralNetworksModel *model,
78                                                                         bool allow);
79
80 typedef int (*ANeuralNetworksExecution_create_fn)(ANeuralNetworksCompilation *compilation,
81                                                   ANeuralNetworksExecution **execution);
82
83 typedef void (*ANeuralNetworksExecution_free_fn)(ANeuralNetworksExecution *execution);
84
85 typedef int (*ANeuralNetworksExecution_setInput_fn)(ANeuralNetworksExecution *execution,
86                                                     int32_t index,
87                                                     const ANeuralNetworksOperandType *type,
88                                                     const void *buffer, size_t length);
89
90 typedef int (*ANeuralNetworksExecution_setInputFromMemory_fn)(
91   ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type,
92   const ANeuralNetworksMemory *memory, size_t offset, size_t length);
93
94 typedef int (*ANeuralNetworksExecution_setOutput_fn)(ANeuralNetworksExecution *execution,
95                                                      int32_t index,
96                                                      const ANeuralNetworksOperandType *type,
97                                                      void *buffer, size_t length);
98
99 typedef int (*ANeuralNetworksExecution_setOutputFromMemory_fn)(
100   ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type,
101   const ANeuralNetworksMemory *memory, size_t offset, size_t length);
102
103 typedef int (*ANeuralNetworksExecution_startCompute_fn)(ANeuralNetworksExecution *execution,
104                                                         ANeuralNetworksEvent **event);
105
106 typedef int (*ANeuralNetworksEvent_wait_fn)(ANeuralNetworksEvent *event);
107
108 typedef void (*ANeuralNetworksEvent_free_fn)(ANeuralNetworksEvent *event);
109
110 typedef int (*ASharedMemory_create_fn)(const char *name, size_t size);
111
112 typedef int (*ANeuralNetworks_getDeviceCount_fn)(uint32_t *numDevices);
113
114 typedef int (*ANeuralNetworks_getDevice_fn)(uint32_t devIndex, ANeuralNetworksDevice **device);
115
116 typedef int (*ANeuralNetworksDevice_getName_fn)(const ANeuralNetworksDevice *device,
117                                                 const char **name);
118
119 typedef int (*ANeuralNetworksDevice_getType_fn)(const ANeuralNetworksDevice *device, int32_t *type);
120
121 typedef int (*ANeuralNetworksDevice_getVersion_fn)(const ANeuralNetworksDevice *device,
122                                                    const char **version);
123
124 typedef int (*ANeuralNetworksDevice_getFeatureLevel_fn)(const ANeuralNetworksDevice *device,
125                                                         int64_t *featureLevel);
126
127 typedef int (*ANeuralNetworksModel_getSupportedOperationsForDevices_fn)(
128   const ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices,
129   uint32_t numDevices, bool *supportedOps);
130
131 typedef int (*ANeuralNetworksCompilation_createForDevices_fn)(
132   ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices, uint32_t numDevices,
133   ANeuralNetworksCompilation **compilation);
134
135 typedef int (*ANeuralNetworksCompilation_setCaching_fn)(ANeuralNetworksCompilation *compilation,
136                                                         const char *cacheDir, const uint8_t *token);
137
138 #if __ANDROID_API__ >= 30
139 typedef int (*ANeuralNetworksCompilation_setTimeout_fn)(ANeuralNetworksCompilation *compilation,
140                                                         uint64_t duration);
141
142 typedef int (*ANeuralNetworksCompilation_setPriority_fn)(ANeuralNetworksCompilation *compilation,
143                                                          int priority);
144 #endif // __ANDROID_API__ >= 30
145
146 typedef int (*ANeuralNetworksExecution_compute_fn)(ANeuralNetworksExecution *execution);
147
148 #if __ANDROID_API__ >= 30
149 typedef int (*ANeuralNetworksExecution_setTimeout_fn)(ANeuralNetworksExecution *execution,
150                                                       uint64_t duration);
151
152 typedef int (*ANeuralNetworksExecution_setLoopTimeout_fn)(ANeuralNetworksExecution *execution,
153                                                           uint64_t duration);
154 #endif // __ANDROID_API__ >= 30
155
156 typedef int (*ANeuralNetworksExecution_getOutputOperandRank_fn)(ANeuralNetworksExecution *execution,
157                                                                 int32_t index, uint32_t *rank);
158
159 typedef int (*ANeuralNetworksExecution_getOutputOperandDimensions_fn)(
160   ANeuralNetworksExecution *execution, int32_t index, uint32_t *dimensions);
161
162 typedef int (*ANeuralNetworksBurst_create_fn)(ANeuralNetworksCompilation *compilation,
163                                               ANeuralNetworksBurst **burst);
164
165 typedef void (*ANeuralNetworksBurst_free_fn)(ANeuralNetworksBurst *burst);
166
167 typedef int (*ANeuralNetworksExecution_burstCompute_fn)(ANeuralNetworksExecution *execution,
168                                                         ANeuralNetworksBurst *burst);
169
170 typedef int (*ANeuralNetworksMemory_createFromAHardwareBuffer_fn)(const AHardwareBuffer *ahwb,
171                                                                   ANeuralNetworksMemory **memory);
172
173 typedef int (*ANeuralNetworksExecution_setMeasureTiming_fn)(ANeuralNetworksExecution *execution,
174                                                             bool measure);
175
176 typedef int (*ANeuralNetworksExecution_getDuration_fn)(const ANeuralNetworksExecution *execution,
177                                                        int32_t durationCode, uint64_t *duration);
178
179 typedef int (*ANeuralNetworksDevice_getExtensionSupport_fn)(const ANeuralNetworksDevice *device,
180                                                             const char *extensionName,
181                                                             bool *isExtensionSupported);
182
183 typedef int (*ANeuralNetworksModel_getExtensionOperandType_fn)(ANeuralNetworksModel *model,
184                                                                const char *extensionName,
185                                                                uint16_t operandCodeWithinExtension,
186                                                                int32_t *type);
187
188 typedef int (*ANeuralNetworksModel_getExtensionOperationType_fn)(
189   ANeuralNetworksModel *model, const char *extensionName, uint16_t operationCodeWithinExtension,
190   ANeuralNetworksOperationType *type);
191
192 typedef int (*ANeuralNetworksModel_setOperandExtensionData_fn)(ANeuralNetworksModel *model,
193                                                                int32_t index, const void *data,
194                                                                size_t length);
195
196 #if __ANDROID_API__ >= 30
197 typedef int (*ANeuralNetworksMemoryDesc_create_fn)(ANeuralNetworksMemoryDesc **desc);
198
199 typedef void (*ANeuralNetworksMemoryDesc_free_fn)(ANeuralNetworksMemoryDesc *desc);
200
201 typedef int (*ANeuralNetworksMemoryDesc_addInputRole_fn)(
202   ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, int32_t index,
203   float frequency);
204
205 typedef int (*ANeuralNetworksMemoryDesc_addOutputRole_fn)(
206   ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, uint32_t index,
207   float frequency);
208
209 typedef int (*ANeuralNetworksMemoryDesc_setDimensions_fn)(ANeuralNetworksMemoryDesc *desc,
210                                                           uint32_t rank,
211                                                           const uint32_t *dimensions);
212
213 typedef int (*ANeuralNetworksMemoryDesc_finish_fn)(ANeuralNetworksMemoryDesc *desc);
214
215 typedef int (*ANeuralNetworksMemory_createFromDesc_fn)(const ANeuralNetworksMemoryDesc *desc,
216                                                        ANeuralNetworksMemory **memory);
217
218 typedef int (*ANeuralNetworksMemory_copy_fn)(const ANeuralNetworksMemory *src,
219                                              const ANeuralNetworksMemory *dst);
220 #endif // __ANDROID_API__ >= 30
221 #endif // __NEURAL_NETWORKS_TYPES_H__