2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
21 #ifndef __NEURAL_NETWORKS_TYPES_H__
22 #define __NEURAL_NETWORKS_TYPES_H__
24 #include "NeuralNetworks.h"
26 // NN api types based on NNAPI header file
27 // https://developer.android.com/ndk/reference/group/neural-networks
29 // nn api function types
31 typedef int (*ANeuralNetworksMemory_createFromFd_fn)(size_t size, int protect, int fd,
32 size_t offset, ANeuralNetworksMemory **memory);
34 typedef void (*ANeuralNetworksMemory_free_fn)(ANeuralNetworksMemory *memory);
36 typedef int (*ANeuralNetworksModel_create_fn)(ANeuralNetworksModel **model);
38 typedef int (*ANeuralNetworksModel_finish_fn)(ANeuralNetworksModel *model);
40 typedef void (*ANeuralNetworksModel_free_fn)(ANeuralNetworksModel *model);
42 typedef int (*ANeuralNetworksCompilation_create_fn)(ANeuralNetworksModel *model,
43 ANeuralNetworksCompilation **compilation);
45 typedef void (*ANeuralNetworksCompilation_free_fn)(ANeuralNetworksCompilation *compilation);
47 typedef int (*ANeuralNetworksCompilation_setPreference_fn)(ANeuralNetworksCompilation *compilation,
50 typedef int (*ANeuralNetworksCompilation_finish_fn)(ANeuralNetworksCompilation *compilation);
52 typedef int (*ANeuralNetworksModel_addOperand_fn)(ANeuralNetworksModel *model,
53 const ANeuralNetworksOperandType *type);
55 typedef int (*ANeuralNetworksModel_setOperandValue_fn)(ANeuralNetworksModel *model, int32_t index,
56 const void *buffer, size_t length);
58 typedef int (*ANeuralNetworksModel_setOperandSymmPerChannelQuantParams_fn)(
59 ANeuralNetworksModel *model, int32_t index,
60 const ANeuralNetworksSymmPerChannelQuantParams *channelQuant);
62 typedef int (*ANeuralNetworksModel_setOperandValueFromMemory_fn)(
63 ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksMemory *memory, size_t offset,
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);
71 typedef int (*ANeuralNetworksModel_identifyInputsAndOutputs_fn)(ANeuralNetworksModel *model,
73 const uint32_t *inputs,
75 const uint32_t *outputs);
77 typedef int (*ANeuralNetworksModel_relaxComputationFloat32toFloat16_fn)(ANeuralNetworksModel *model,
80 typedef int (*ANeuralNetworksExecution_create_fn)(ANeuralNetworksCompilation *compilation,
81 ANeuralNetworksExecution **execution);
83 typedef void (*ANeuralNetworksExecution_free_fn)(ANeuralNetworksExecution *execution);
85 typedef int (*ANeuralNetworksExecution_setInput_fn)(ANeuralNetworksExecution *execution,
87 const ANeuralNetworksOperandType *type,
88 const void *buffer, size_t length);
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);
94 typedef int (*ANeuralNetworksExecution_setOutput_fn)(ANeuralNetworksExecution *execution,
96 const ANeuralNetworksOperandType *type,
97 void *buffer, size_t length);
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);
103 typedef int (*ANeuralNetworksExecution_startCompute_fn)(ANeuralNetworksExecution *execution,
104 ANeuralNetworksEvent **event);
106 typedef int (*ANeuralNetworksEvent_wait_fn)(ANeuralNetworksEvent *event);
108 typedef void (*ANeuralNetworksEvent_free_fn)(ANeuralNetworksEvent *event);
110 typedef int (*ASharedMemory_create_fn)(const char *name, size_t size);
112 typedef int (*ANeuralNetworks_getDeviceCount_fn)(uint32_t *numDevices);
114 typedef int (*ANeuralNetworks_getDevice_fn)(uint32_t devIndex, ANeuralNetworksDevice **device);
116 typedef int (*ANeuralNetworksDevice_getName_fn)(const ANeuralNetworksDevice *device,
119 typedef int (*ANeuralNetworksDevice_getType_fn)(const ANeuralNetworksDevice *device, int32_t *type);
121 typedef int (*ANeuralNetworksDevice_getVersion_fn)(const ANeuralNetworksDevice *device,
122 const char **version);
124 typedef int (*ANeuralNetworksDevice_getFeatureLevel_fn)(const ANeuralNetworksDevice *device,
125 int64_t *featureLevel);
127 typedef int (*ANeuralNetworksModel_getSupportedOperationsForDevices_fn)(
128 const ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices,
129 uint32_t numDevices, bool *supportedOps);
131 typedef int (*ANeuralNetworksCompilation_createForDevices_fn)(
132 ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices, uint32_t numDevices,
133 ANeuralNetworksCompilation **compilation);
135 typedef int (*ANeuralNetworksCompilation_setCaching_fn)(ANeuralNetworksCompilation *compilation,
136 const char *cacheDir, const uint8_t *token);
138 #if __ANDROID_API__ >= 30
139 typedef int (*ANeuralNetworksCompilation_setTimeout_fn)(ANeuralNetworksCompilation *compilation,
142 typedef int (*ANeuralNetworksCompilation_setPriority_fn)(ANeuralNetworksCompilation *compilation,
144 #endif // __ANDROID_API__ >= 30
146 typedef int (*ANeuralNetworksExecution_compute_fn)(ANeuralNetworksExecution *execution);
148 #if __ANDROID_API__ >= 30
149 typedef int (*ANeuralNetworksExecution_setTimeout_fn)(ANeuralNetworksExecution *execution,
152 typedef int (*ANeuralNetworksExecution_setLoopTimeout_fn)(ANeuralNetworksExecution *execution,
154 #endif // __ANDROID_API__ >= 30
156 typedef int (*ANeuralNetworksExecution_getOutputOperandRank_fn)(ANeuralNetworksExecution *execution,
157 int32_t index, uint32_t *rank);
159 typedef int (*ANeuralNetworksExecution_getOutputOperandDimensions_fn)(
160 ANeuralNetworksExecution *execution, int32_t index, uint32_t *dimensions);
162 typedef int (*ANeuralNetworksBurst_create_fn)(ANeuralNetworksCompilation *compilation,
163 ANeuralNetworksBurst **burst);
165 typedef void (*ANeuralNetworksBurst_free_fn)(ANeuralNetworksBurst *burst);
167 typedef int (*ANeuralNetworksExecution_burstCompute_fn)(ANeuralNetworksExecution *execution,
168 ANeuralNetworksBurst *burst);
170 typedef int (*ANeuralNetworksMemory_createFromAHardwareBuffer_fn)(const AHardwareBuffer *ahwb,
171 ANeuralNetworksMemory **memory);
173 typedef int (*ANeuralNetworksExecution_setMeasureTiming_fn)(ANeuralNetworksExecution *execution,
176 typedef int (*ANeuralNetworksExecution_getDuration_fn)(const ANeuralNetworksExecution *execution,
177 int32_t durationCode, uint64_t *duration);
179 typedef int (*ANeuralNetworksDevice_getExtensionSupport_fn)(const ANeuralNetworksDevice *device,
180 const char *extensionName,
181 bool *isExtensionSupported);
183 typedef int (*ANeuralNetworksModel_getExtensionOperandType_fn)(ANeuralNetworksModel *model,
184 const char *extensionName,
185 uint16_t operandCodeWithinExtension,
188 typedef int (*ANeuralNetworksModel_getExtensionOperationType_fn)(
189 ANeuralNetworksModel *model, const char *extensionName, uint16_t operationCodeWithinExtension,
190 ANeuralNetworksOperationType *type);
192 typedef int (*ANeuralNetworksModel_setOperandExtensionData_fn)(ANeuralNetworksModel *model,
193 int32_t index, const void *data,
196 #if __ANDROID_API__ >= 30
197 typedef int (*ANeuralNetworksMemoryDesc_create_fn)(ANeuralNetworksMemoryDesc **desc);
199 typedef void (*ANeuralNetworksMemoryDesc_free_fn)(ANeuralNetworksMemoryDesc *desc);
201 typedef int (*ANeuralNetworksMemoryDesc_addInputRole_fn)(
202 ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, int32_t index,
205 typedef int (*ANeuralNetworksMemoryDesc_addOutputRole_fn)(
206 ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, uint32_t index,
209 typedef int (*ANeuralNetworksMemoryDesc_setDimensions_fn)(ANeuralNetworksMemoryDesc *desc,
211 const uint32_t *dimensions);
213 typedef int (*ANeuralNetworksMemoryDesc_finish_fn)(ANeuralNetworksMemoryDesc *desc);
215 typedef int (*ANeuralNetworksMemory_createFromDesc_fn)(const ANeuralNetworksMemoryDesc *desc,
216 ANeuralNetworksMemory **memory);
218 typedef int (*ANeuralNetworksMemory_copy_fn)(const ANeuralNetworksMemory *src,
219 const ANeuralNetworksMemory *dst);
220 #endif // __ANDROID_API__ >= 30
221 #endif // __NEURAL_NETWORKS_TYPES_H__