1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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  * @addtogroup NeuralNetworks
19  * @{
20  */
21 
22 /**
23  * @file NeuralNetworks.h
24  */
25 
26 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_H
27 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_H
28 
29 /******************************************************************
30  *
31  * IMPORTANT NOTICE:
32  *
33  *   This file is part of Android's set of stable system headers
34  *   exposed by the Android NDK (Native Development Kit).
35  *
36  *   Third-party source AND binary code relies on the definitions
37  *   here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
38  *
39  *   - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
40  *   - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
41  *   - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
42  *   - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
43  */
44 
45 #include <stdbool.h>
46 #include <stddef.h>
47 #include <stdint.h>
48 #include <sys/cdefs.h>
49 
50 #include "NeuralNetworksTypes.h"
51 
52 #ifdef __ANDROID__
53 #include <android/hardware_buffer.h>
54 #else
55 #endif  // __ANDROID__
56 
57 #if !defined(__DEPRECATED_IN)
58 #define __DEPRECATED_IN(api_level) __attribute__((annotate("deprecated_in=" #api_level)))
59 #endif
60 
61 // This is required for building libneuralnetworks_cl,
62 // the symbols have same names as in NDK, but
63 // they are not bounded by API availability.
64 #ifdef NN_COMPATIBILITY_LIBRARY_BUILD
65 #define __NNAPI_INTRODUCED_IN(x)
66 #define __NNAPI_DEPRECATED_IN(x)
67 #else
68 #define __NNAPI_INTRODUCED_IN(x) __INTRODUCED_IN(x)
69 #define __NNAPI_DEPRECATED_IN(x) __DEPRECATED_IN(x)
70 #endif
71 
72 #ifndef __NNAPI_FL5_MIN_ANDROID_API__
73 #define __NNAPI_FL5_MIN_ANDROID_API__ __ANDROID_API_S__
74 #endif
75 
76 __BEGIN_DECLS
77 
78 /**
79  * Create a {@link ANeuralNetworksMemoryDesc} with no properties.
80  *
81  * This only creates the memory descriptor. Its properties should be set with calls to
82  * {@link ANeuralNetworksMemoryDesc_addInputRole},
83  * {@link ANeuralNetworksMemoryDesc_addOutputRole}, and
84  * {@link ANeuralNetworksMemoryDesc_setDimensions}.
85  *
86  * {@link ANeuralNetworksMemoryDesc_finish} must be called once all properties have been set.
87  *
88  * {@link ANeuralNetworksMemoryDesc_free} must be called once the memory descriptor
89  * is no longer needed.
90  *
91  * Available since NNAPI feature level 4.
92  *
93  * @param desc The {@link ANeuralNetworksMemoryDesc} to be created.
94  *             Set to NULL if unsuccessful.
95  *
96  * @return ANEURALNETWORKS_NO_ERROR if successful.
97  * @deprecated NNAPI is deprecated. See
98  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
99  *   for more details.
100  */
101 int ANeuralNetworksMemoryDesc_create(ANeuralNetworksMemoryDesc** desc) __NNAPI_INTRODUCED_IN(30)
102         __NNAPI_DEPRECATED_IN(35);
103 
104 /**
105  * Destroy a memory descriptor.
106  *
107  * The memory descriptor need not have been finished by a call to
108  * {@link ANeuralNetworksMemoryDesc_finish}.
109  *
110  * See {@link ANeuralNetworksMemoryDesc} for information on multithreaded usage.
111  *
112  * Available since NNAPI feature level 4.
113  *
114  * @param desc The memory descriptor to be destroyed. Passing NULL is acceptable and
115  *             results in no operation.
116  * @deprecated NNAPI is deprecated. See
117  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
118  *   for more details.
119  */
120 void ANeuralNetworksMemoryDesc_free(ANeuralNetworksMemoryDesc* desc) __NNAPI_INTRODUCED_IN(30)
121         __NNAPI_DEPRECATED_IN(35);
122 
123 /**
124  * Specify that a memory object will be playing the role of an input to an execution created from a
125  * particular compilation.
126  *
127  * The compilation and the input index fully specify an input operand. This function
128  * may be invoked multiple times on the same memory descriptor with different input operands,
129  * and the same input operand may be specified on multiple memory descriptors. However,
130  * specifying the same input operand on the same memory descriptor more than once will
131  * return an error.
132  *
133  * The dimensions of the corresponding model operands of all the roles specified by
134  * {@link ANeuralNetworksMemoryDesc_addInputRole} and
135  * {@link ANeuralNetworksMemoryDesc_addOutputRole} must be compatible with each other. Two
136  * dimensions are incompatible if both ranks are fully specified but have different values, or if
137  * there is at least one axis that is fully specified in both but has different values.
138  *
139  * At least one of {@link ANeuralNetworksMemoryDesc_addInputRole} and
140  * {@link ANeuralNetworksMemoryDesc_addOutputRole} must be called on a memory descriptor
141  * before invoking {@link ANeuralNetworksMemoryDesc_finish}.
142  *
143  * Attempting to modify a memory descriptor once {@link ANeuralNetworksMemoryDesc_finish} has been
144  * called will return an error.
145  *
146  * See {@link ANeuralNetworksMemoryDesc} for information on multithreaded usage.
147  *
148  * Available since NNAPI feature level 4.
149  *
150  * @param desc The memory descriptor to be modified.
151  * @param compilation The compilation object. It must already have been finished by calling
152  *                    {@link ANeuralNetworksCompilation_finish}, and must outlive the memory
153  *                    descriptor.
154  * @param index The index of the input argument we are referencing from the compilation. It is
155  *              an index into the inputs list passed to
156  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
157  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
158  * @param frequency A floating-point value within the range (0.0, 1.0]. Describes how likely the
159  *                  memory is to be used in the specified role. This is provided as a hint to
160  *                  optimize the case when different roles prefer different memory locations or data
161  *                  layouts.
162  *
163  * @return ANEURALNETWORKS_NO_ERROR if successful.
164  * @deprecated NNAPI is deprecated. See
165  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
166  *   for more details.
167  */
168 int ANeuralNetworksMemoryDesc_addInputRole(ANeuralNetworksMemoryDesc* desc,
169                                            const ANeuralNetworksCompilation* compilation,
170                                            uint32_t index, float frequency)
171         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
172 
173 /**
174  * Specify that a memory object will be playing the role of an output to an execution created from a
175  * particular compilation.
176  *
177  * The compilation and the output index fully specify an output operand. This function
178  * may be invoked multiple times on the same memory descriptor with different output operands,
179  * and the same output operand may be specified on multiple memory descriptors. However,
180  * specifying the same output operand on the same memory descriptor object more than once will
181  * return an error.
182  *
183  * The dimensions of the corresponding model operands of all the roles specified by
184  * {@link ANeuralNetworksMemoryDesc_addInputRole} and
185  * {@link ANeuralNetworksMemoryDesc_addOutputRole} must be compatible with each other. Two
186  * dimensions are incompatible if both ranks are fully specified but have different values, or if
187  * there is at least one axis that is fully specified in both but has different values.
188  *
189  * At least one of {@link ANeuralNetworksMemoryDesc_addInputRole} and
190  * {@link ANeuralNetworksMemoryDesc_addOutputRole} must be called on the memory descriptor
191  * before invoking {@link ANeuralNetworksMemoryDesc_finish}.
192  *
193  * Attempting to modify a memory descriptor once {@link ANeuralNetworksMemoryDesc_finish} has been
194  * called will return an error.
195  *
196  * See {@link ANeuralNetworksMemoryDesc} for information on multithreaded usage.
197  *
198  * Available since NNAPI feature level 4.
199  *
200  * @param desc The memory descriptor to be modified.
201  * @param compilation The compilation object. It must already have been finished by calling
202  *                    {@link ANeuralNetworksCompilation_finish}, and must outlive the memory
203  *                    descriptor.
204  * @param index The index of the output argument we are referencing from the compilation. It is
205  *              an index into the outputs list passed to
206  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
207  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
208  * @param frequency A floating-point value within the range (0.0, 1.0]. Describes how likely the
209  *                  memory is to be used in the specified role. This is provided as a hint to
210  *                  optimize the case when multiple roles prefer different memory locations or data
211  *                  layouts.
212  *
213  * @return ANEURALNETWORKS_NO_ERROR if successful.
214  * @deprecated NNAPI is deprecated. See
215  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
216  *   for more details.
217  */
218 int ANeuralNetworksMemoryDesc_addOutputRole(ANeuralNetworksMemoryDesc* desc,
219                                             const ANeuralNetworksCompilation* compilation,
220                                             uint32_t index, float frequency)
221         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
222 
223 /**
224  * Set the dimensional information of the memory descriptor.
225  *
226  * The specified dimensions must be compatible with the dimensions of the corresponding model
227  * operands of all the roles specified by {@link ANeuralNetworksMemoryDesc_addInputRole} and
228  * {@link ANeuralNetworksMemoryDesc_addOutputRole}. Two dimensions are incompatible if both ranks
229  * are fully specified but have different values, or if there is at least one axis that is fully
230  * specified in both but has different values.
231  *
232  * Attempting to modify a memory descriptor once {@link ANeuralNetworksMemoryDesc_finish} has been
233  * called will return an error.
234  *
235  * See {@link ANeuralNetworksMemoryDesc} for information on multithreaded usage.
236  *
237  * Available since NNAPI feature level 4.
238  *
239  * @param desc The memory descriptor to be modified.
240  * @param rank The number of dimensions. Must be 0 for scalars.
241  * @param dimensions An array of dimensions. An entry with the value 0 indicates that the
242  *                   corresponding axis has an unknown size.
243  *
244  * @return ANEURALNETWORKS_NO_ERROR if successful.
245  * @deprecated NNAPI is deprecated. See
246  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
247  *   for more details.
248  */
249 int ANeuralNetworksMemoryDesc_setDimensions(ANeuralNetworksMemoryDesc* desc, uint32_t rank,
250                                             const uint32_t* dimensions) __NNAPI_INTRODUCED_IN(30)
251         __NNAPI_DEPRECATED_IN(35);
252 
253 /**
254  * Indicate that we have finished modifying a memory descriptor. Required before calling
255  * {@link ANeuralNetworksMemory_createFromDesc}.
256  *
257  * This function must only be called once for a given memory descriptor.
258  *
259  * See {@link ANeuralNetworksMemoryDesc} for information on multithreaded usage.
260  *
261  * Available since NNAPI feature level 4.
262  *
263  * @param desc The memory descriptor to be finished.
264  *
265  * @return ANEURALNETWORKS_NO_ERROR if successful.
266  * @deprecated NNAPI is deprecated. See
267  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
268  *   for more details.
269  */
270 int ANeuralNetworksMemoryDesc_finish(ANeuralNetworksMemoryDesc* desc) __NNAPI_INTRODUCED_IN(30)
271         __NNAPI_DEPRECATED_IN(35);
272 
273 /**
274  * Creates a memory object from a memory descriptor.
275  *
276  * The memory object is created with an uninitialized buffer. A memory object with an uninitialized
277  * buffer may only be used according to the roles specified by {@link
278  * ANeuralNetworksMemoryDesc_addOutputRole}, or as the destination memory in {@link
279  * ANeuralNetworksMemory_copy}. The buffer of a memory object is initialized after the memory object
280  * is used as an output in a successful execution, or used as the destination memory in a successful
281  * {@link ANeuralNetworksMemory_copy}. A memory object with an initialized buffer may be used
282  * according to all roles specified in {@link ANeuralNetworksMemoryDesc}, or as the source or
283  * destination memory in {@link ANeuralNetworksMemory_copy}. The buffer of a memory object will
284  * return to the uninitialized state if the memory object is used as an output in a failed
285  * execution, or used as the destination memory in a failed {@link ANeuralNetworksMemory_copy}.
286  *
287  * The dimensions of the memory descriptor are deduced from the dimensions of the corresponding
288  * model operands of all the roles specified by {@link ANeuralNetworksMemoryDesc_addInputRole} and
289  * {@link ANeuralNetworksMemoryDesc_addOutputRole}, as well as the dimensions set by the call to
290  * {@link ANeuralNetworksMemoryDesc_setDimensions}, if any. The memory descriptor may have
291  * unspecified dimensions or rank. In such a case, the same memory object may be used with different
292  * shapes of outputs in different executions. When the memory is used as an input, the input shape
293  * must be the same as the output shape from the last execution using this memory object as an
294  * output, or the last {@link ANeuralNetworksMemory_copy} using this memory object as the
295  * destination memory. Creating a memory object with unspecified dimensions or rank may fail for
296  * certain sets of roles.
297  *
298  * Using the memory in roles or shapes that are not compatible with the rules specified above will
299  * return an error.
300  *
301  * When calling {@link ANeuralNetworksExecution_setInputFromMemory} or
302  * {@link ANeuralNetworksExecution_setOutputFromMemory} with the memory object,
303  * both offset and length must be set to zero and the entire memory region will be
304  * associated with the specified input or output operand.
305  *
306  * Calling {@link ANeuralNetworksModel_setOperandValueFromMemory} with the memory created from this
307  * function will return an error.
308  *
309  * {@link ANeuralNetworksMemory_free} must be called once the memory is no longer needed.
310  *
311  * Attempting to create memory from an unfinished memory descriptor will return an error.
312  *
313  * The provided {@link ANeuralNetworksMemoryDesc} need not outlive the {@link ANeuralNetworksMemory}
314  * object.
315  *
316  * Available since NNAPI feature level 4.
317  *
318  * @param desc The memory descriptor.
319  * @param memory The memory object to be created.
320  *               Set to NULL if unsuccessful.
321  *
322  * @return ANEURALNETWORKS_NO_ERROR if successful; ANEURALNETWORKS_OP_FAILED if the memory is
323  *         created with unspecified dimensions or rank and it is not supported for this set of
324  *         roles.
325  * @deprecated NNAPI is deprecated. See
326  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
327  *   for more details.
328  */
329 int ANeuralNetworksMemory_createFromDesc(const ANeuralNetworksMemoryDesc* desc,
330                                          ANeuralNetworksMemory** memory) __NNAPI_INTRODUCED_IN(30)
331         __NNAPI_DEPRECATED_IN(35);
332 
333 /**
334  * Copies data from one memory object to another.
335  *
336  * If at most one of the src and dst is created from {@link ANeuralNetworksMemory_createFromDesc},
337  * the src and dst must have the same logical size:
338  * - If the memory is created from {@link ANeuralNetworksMemory_createFromFd}, or if it is created
339  *   from {@link ANeuralNetworksMemory_createFromAHardwareBuffer} with format of
340  *   AHARDWAREBUFFER_FORMAT_BLOB, the logical size equals the size of the memory.
341  * - If the memory is created from {@link ANeuralNetworksMemory_createFromAHardwareBuffer} with a
342  *   format other than AHARDWAREBUFFER_FORMAT_BLOB, the logical size equals the size when there is
343  *   no padding and the data is tightly packed. This function may fail if the AHardwareBuffer
344  *   cannot be accessed.
345  * - If the memory is created from {@link ANeuralNetworksMemory_createFromDesc}, the logical size
346  *   equals the size indicated by the {@link OperandCode} multiplied by the number of elements. This
347  *   function will fail if the number of elements is unknown.
348  *
349  * If both src and dst are created from {@link ANeuralNetworksMemory_createFromDesc}, they must have
350  * compatible dimensions. Two dimensions are incompatible if both ranks are fully specified but
351  * have different values, or if there is at least one axis that is fully specified in both but has
352  * different values. The dst may have unspecified dimensions or rank. In such a case, the dimensions
353  * of dst will get updated according to the dimensions of the src.
354  *
355  * In both cases, if the src is created from {@link ANeuralNetworksMemory_createFromDesc}, it must
356  * have been used as an output in a successful execution, or used as the destination memory in a
357  * successful {@link ANeuralNetworksMemory_copy}.
358  *
359  * The src and dst may have different data layout, in which case the data copying is performed
360  * logically with data layout transformation.
361  *
362  * Available since NNAPI feature level 4.
363  *
364  * @param src The source memory object.
365  * @param dst The destination memory object.
366  *
367  * @return ANEURALNETWORKS_NO_ERROR if successful.
368  * @deprecated NNAPI is deprecated. See
369  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
370  *   for more details.
371  */
372 int ANeuralNetworksMemory_copy(const ANeuralNetworksMemory* src, const ANeuralNetworksMemory* dst)
373         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
374 
375 /**
376  * Get the number of available devices.
377  *
378  * @param numDevices Used to return the number of devices.
379  *
380  * @return ANEURALNETWORKS_NO_ERROR if successful.
381  *
382  * Available since NNAPI feature level 3.
383  * @deprecated NNAPI is deprecated. See
384  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
385  *   for more details.
386  */
387 int ANeuralNetworks_getDeviceCount(uint32_t* numDevices) __NNAPI_INTRODUCED_IN(29)
388         __NNAPI_DEPRECATED_IN(35);
389 
390 /**
391  * Get the representation of the specified device.
392  *
393  * @param devIndex The index of the specified device. Must be less than the
394                    number of available devices.
395  * @param device The representation of the specified device.
396  *               The same representation will always be returned for the specified
397  *               device.
398  *
399  * @return ANEURALNETWORKS_NO_ERROR if successful.
400  *
401  * Available since NNAPI feature level 3.
402  * @deprecated NNAPI is deprecated. See
403  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
404  *   for more details.
405  */
406 int ANeuralNetworks_getDevice(uint32_t devIndex, ANeuralNetworksDevice** device)
407         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
408 
409 /**
410  * Get the name of the specified device.
411  *
412  * @param device The representation of the specified device.
413  * @param name   The returned name of the specified device. The name will be in UTF-8
414  *               and will be null-terminated. It will be recognizable as a known device name
415  *               rather than a cryptic string. For devices with feature level reported by
416  *               {@link ANeuralNetworksDevice_getFeatureLevel} that is
417  *               {@link ANEURALNETWORKS_FEATURE_LEVEL_3} and higher, the format of the name is
418  *               {VENDOR}-{DEVICE}. For devices with feature level
419  *               {@link ANEURALNETWORKS_FEATURE_LEVEL_2} or lower, the format of the name is
420  *               undefined. The name will remain valid for the duration of the application.
421  *
422  * @return ANEURALNETWORKS_NO_ERROR if successful.
423  *
424  * Available since NNAPI feature level 3.
425  * @deprecated NNAPI is deprecated. See
426  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
427  *   for more details.
428  */
429 int ANeuralNetworksDevice_getName(const ANeuralNetworksDevice* device, const char** name)
430         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
431 
432 /**
433  * Get the type of a given device.
434  *
435  * The device type can be used to help application developers to distribute Machine Learning
436  * workloads and other workloads such as graphical rendering.
437  * E.g., for an app which renders AR scenes based on real time object detection results,
438  * the developer could choose an ACCELERATOR type device for ML workloads, and reserve GPU
439  * for graphical rendering.
440  *
441  * @param device The representation of the specified device.
442  * @param type The returned {@link DeviceTypeCode} of the specified device.
443  *
444  * @return ANEURALNETWORKS_NO_ERROR if successful.
445  *
446  * Available since NNAPI feature level 3.
447  * @deprecated NNAPI is deprecated. See
448  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
449  *   for more details.
450  */
451 int ANeuralNetworksDevice_getType(const ANeuralNetworksDevice* device, int32_t* type)
452         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
453 
454 /**
455  * Get the version of the driver implementation of the specified device.
456  *
457  * It’s the responsibility of the driver implementor to insure that this version string
458  * uniquely distinguishes this implementation from all previous implementations.
459  *
460  * This version string must not be confused with the feature level which is solely defined
461  * by {@link ANeuralNetworksDevice_getFeatureLevel}. There is no implicit ordering of the versions.
462  * For example, it is not possible to filter all drivers older than a certain version.
463  *
464  * Application developers may use this version string to avoid or prefer specific driver
465  * implementations. For example, an application may want to do so because:
466  *     - A specific version of the driver does not provide the required performance,
467  *       perhaps because of a performance regression.
468  *     - A specific version of the driver has a bug or returns results that don’t match
469  *       the minimum precision requirement for the application.
470  *
471  * @param device The representation of the specified device.
472  * @param version The returned version string of the driver for the specified device. The
473  *                string will be in UTF-8 and will be null-terminated. For devices with feature
474  *                level 28 or lower, "UNKNOWN" will be returned. The version string will remain
475  *                valid for the duration of the application.
476  *
477  * @return ANEURALNETWORKS_NO_ERROR if successful.
478  *
479  * Available since NNAPI feature level 3.
480  * @deprecated NNAPI is deprecated. See
481  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
482  *   for more details.
483  */
484 int ANeuralNetworksDevice_getVersion(const ANeuralNetworksDevice* device, const char** version)
485         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
486 
487 /**
488  * Get the NNAPI feature level of the specified NNAPI device.
489  *
490  * Each device has a supported feature level, which is the most advanced NNAPI specification
491  * and features this driver implements. For example, if the driver implements the features
492  * introduced in {@link ANEURALNETWORKS_FEATURE_LEVEL_2}, but does not implement the features
493  * introduced after {@link ANEURALNETWORKS_FEATURE_LEVEL_2}, the value would be
494  * {@link ANEURALNETWORKS_FEATURE_LEVEL_2}. Developers could decide whether or not the specified
495  * device should be used for a model that has certain feature requirements.
496  *
497  * NNAPI device feature level is closely related to NNAPI runtime feature level
498  * ({@link ANeuralNetworks_getRuntimeFeatureLevel}), which indicates an NNAPI runtime feature
499  * level (the most advanced NNAPI specification and features that the runtime implements).
500  * An NNAPI device feature level is always less than or equal to the runtime feature level.
501  *
502  * This function produces a {@link FeatureLevelCode} enum value, NOT an Android API level.
503  *
504  * @param device The representation of the specified device.
505  * @param featureLevel {@link FeatureLevelCode} of the most advanced feature this driver implements.
506  *
507  * @return ANEURALNETWORKS_NO_ERROR if successful.
508  *
509  * Available since NNAPI feature level 3.
510  * @deprecated NNAPI is deprecated. See
511  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
512  *   for more details.
513  */
514 int ANeuralNetworksDevice_getFeatureLevel(const ANeuralNetworksDevice* device,
515                                           int64_t* featureLevel) __NNAPI_INTRODUCED_IN(29)
516         __NNAPI_DEPRECATED_IN(35);
517 
518 /**
519  * Wait until the device is in a live state.
520  *
521  * A device may encounter internal errors and temporarily enter a dead state. A
522  * call that uses a device in such a state will return with the error
523  * {@link ANEURALNETWORKS_DEAD_OBJECT}. ANeuralNetworksDevice_wait will block until
524  * the device is in a live state.
525  *
526  * @param device The representation of the specified device.
527  *
528  * @return ANEURALNETWORKS_NO_ERROR if successful.
529  *
530  * Available since NNAPI feature level 4.
531  * @deprecated NNAPI is deprecated. See
532  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
533  *   for more details.
534  */
535 int ANeuralNetworksDevice_wait(const ANeuralNetworksDevice* device) __NNAPI_INTRODUCED_IN(30)
536         __NNAPI_DEPRECATED_IN(35);
537 
538 /**
539  * Get the supported operations for a specified set of devices. If multiple devices
540  * are selected, the supported operation list is a union of supported operations of all
541  * selected devices.
542  *
543  * @param model The model to be queried.
544  * @param devices The set of devices. Must not contain duplicates.
545  * @param numDevices The number of devices in the set.
546  * @param supportedOps The boolean array to be filled. True means supported. The size of the
547  *                     boolean array must be at least as large as the number of operations
548  *                     in the model. The order of elements in the supportedOps array matches
549  *                     the order in which the corresponding operations were added to the model.
550  *
551  * @return ANEURALNETWORKS_NO_ERROR if successful.
552  *
553  * Available since NNAPI feature level 3.
554  * @deprecated NNAPI is deprecated. See
555  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
556  *   for more details.
557  */
558 int ANeuralNetworksModel_getSupportedOperationsForDevices(
559         const ANeuralNetworksModel* model, const ANeuralNetworksDevice* const* devices,
560         uint32_t numDevices, bool* supportedOps) __NNAPI_INTRODUCED_IN(29)
561         __NNAPI_DEPRECATED_IN(35);
562 
563 /**
564  * Create a {@link ANeuralNetworksCompilation} to compile the given model for a specified set
565  * of devices. If more than one device is specified, the compilation will
566  * distribute the workload automatically across the devices. The model must be fully
567  * supported by the specified set of devices. This means that
568  * ANeuralNetworksModel_getSupportedOperationsForDevices() must have returned true for every
569  * operation for that model/devices pair.
570  *
571  * The user must handle all compilation and execution failures from the
572  * specified set of devices. This is in contrast to a use of {@link
573  * ANeuralNetworksCompilation_create}, where the runtime will attempt to recover
574  * from such failures.
575  *
576  * The model passed to this function is termed the "main model" of the
577  * compilation, to distinguish it from other models referred to by an Operand
578  * of type {@link ANEURALNETWORKS_MODEL} within this compilation.
579  *
580  * @param model The {@link ANeuralNetworksModel} to be compiled.
581  * @param devices The set of devices. Must not contain duplicates.
582  * @param numDevices The number of devices in the set.
583  * @param compilation The newly created object or NULL if unsuccessful.
584  *
585  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
586  *         if the model is invalid.
587  *
588  * Available since NNAPI feature level 3.
589  * @deprecated NNAPI is deprecated. See
590  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
591  *   for more details.
592  */
593 int ANeuralNetworksCompilation_createForDevices(ANeuralNetworksModel* model,
594                                                 const ANeuralNetworksDevice* const* devices,
595                                                 uint32_t numDevices,
596                                                 ANeuralNetworksCompilation** compilation)
597         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
598 
599 /**
600  * Sets the compilation caching signature and the cache directory.
601  *
602  * Provides optional caching information to the runtime for faster repeated
603  * compilation.
604  *
605  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
606  *
607  * @param compilation The compilation to be modified.
608  * @param cacheDir The cache directory for the runtime to store and retrieve caching
609  *                 data. It is recommended to use the code cache directory provided
610  *                 by the Android runtime. If not using the code cache directory, the
611  *                 user should choose a directory local to the application, and is
612  *                 responsible for managing the cache entries.
613  * @param token The token provided by the user to specify a model must be of length
614  *              ANEURALNETWORKS_BYTE_SIZE_OF_CACHE_TOKEN. The user should ensure that
615  *              the token is unique to a model within the application. The NNAPI
616  *              runtime cannot detect token collisions; a collision will result in a
617  *              failed execution or in a successful execution that produces incorrect
618  *              output values.
619  *
620  * @return ANEURALNETWORKS_NO_ERROR if successful.
621  *
622  * Available since NNAPI feature level 3.
623  * @deprecated NNAPI is deprecated. See
624  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
625  *   for more details.
626  */
627 int ANeuralNetworksCompilation_setCaching(ANeuralNetworksCompilation* compilation,
628                                           const char* cacheDir, const uint8_t* token)
629         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
630 
631 /**
632  * Schedule synchronous evaluation of the execution.
633  *
634  * <p>Schedules synchronous evaluation of the execution. Returns once the
635  * execution has completed and the outputs are ready to be consumed.
636  * </p>
637  *
638  * If {@link ANeuralNetworksExecution_setTimeout} was called on this execution,
639  * and the execution is not able to complete before the timeout duration is
640  * exceeded, then execution may be aborted, in which case
641  * ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be returned. If the device has
642  * a feature level reported by {@link ANeuralNetworksDevice_getFeatureLevel}
643  * that is lower than 30, then the timeout duration hint will be ignored.
644  *
645  * If this execution contains a {@link ANEURALNETWORKS_WHILE} operation, and
646  * the condition model does not output false within the loop timeout duration,
647  * then execution will be aborted and ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}
648  * will be returned.
649  *
650  * Before NNAPI feature level 5, this function may only be invoked when the execution is in the
651  * preparation state. Starting at NNAPI feature level 5, if the user sets the execution to be
652  * reusable by {@link ANeuralNetworksExecution_setReusable}, this function may also be invoked when
653  * the execution is in the completed state.
654  *
655  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
656  *
657  * See {@link ANeuralNetworksExecution_burstCompute} for burst synchronous execution.
658  * See {@link ANeuralNetworksExecution_startCompute} for regular asynchronous execution.
659  * See {@link ANeuralNetworksExecution_startComputeWithDependencies} for
660  * asynchronous execution with dependencies.
661  *
662  * Available since NNAPI feature level 3.
663  *
664  * @param execution The execution to be scheduled and executed.
665  *
666  * @return ANEURALNETWORKS_NO_ERROR if the execution completed normally.
667  *         ANEURALNETWORKS_UNMAPPABLE if the execution input or output memory cannot
668  *         be properly mapped.
669  * @deprecated NNAPI is deprecated. See
670  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
671  *   for more details.
672  */
673 int ANeuralNetworksExecution_compute(ANeuralNetworksExecution* execution) __NNAPI_INTRODUCED_IN(29)
674         __NNAPI_DEPRECATED_IN(35);
675 
676 /**
677  * Get the dimensional information of the specified output operand of the model of the
678  * latest computation evaluated on {@link ANeuralNetworksExecution}.
679  *
680  * This function may only be invoked when the execution is in the completed state.
681  *
682  * See {@link ANeuralNetworksExecution} for information on execution states.
683  *
684  * @param execution The execution to be queried.
685  * @param index The index of the output argument we are querying. It is
686  *              an index into the lists passed to
687  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
688  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
689  * @param rank The rank of the output operand.
690  *
691  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_OUTPUT_INSUFFICIENT_SIZE
692  *         if the target output is provided an insufficient buffer at execution time,
693  *         ANEURALNETWORKS_BAD_DATA if the index is invalid.
694  *
695  * Available since NNAPI feature level 3.
696  * @deprecated NNAPI is deprecated. See
697  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
698  *   for more details.
699  */
700 int ANeuralNetworksExecution_getOutputOperandRank(ANeuralNetworksExecution* execution,
701                                                   int32_t index, uint32_t* rank)
702         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
703 
704 /**
705  * Get the dimensional information of the specified output operand of the model of the
706  * latest computation evaluated on {@link ANeuralNetworksExecution}. The target output operand
707  * cannot be a scalar.
708  *
709  * This function may only be invoked when the execution is in the completed state.
710  *
711  * See {@link ANeuralNetworksExecution} for information on execution states.
712  *
713  * @param execution The execution to be queried.
714  * @param index The index of the output argument we are querying. It is an index into the lists
715  *              passed to {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
716  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
717  * @param dimensions The dimension array to be filled. The size of the array must be exactly as
718  *                   large as the rank of the output operand to be queried in the model.
719  *
720  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_OUTPUT_INSUFFICIENT_SIZE
721  *         if the target output is provided an insufficient buffer at execution time,
722  *         ANEURALNETWORKS_BAD_DATA if the index is invalid or if the target is a scalar.
723  *
724  * Available since NNAPI feature level 3.
725  * @deprecated NNAPI is deprecated. See
726  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
727  *   for more details.
728  */
729 int ANeuralNetworksExecution_getOutputOperandDimensions(ANeuralNetworksExecution* execution,
730                                                         int32_t index, uint32_t* dimensions)
731         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
732 
733 /**
734  * Create a {@link ANeuralNetworksBurst} to apply the given compilation.
735  * This only creates the burst object. Computation is only performed once
736  * {@link ANeuralNetworksExecution_burstCompute} is invoked with a valid
737  * {@link ANeuralNetworksExecution} and {@link ANeuralNetworksBurst}.
738  *
739  * <p>The provided compilation must outlive the burst object.</p>
740  *
741  * Available since NNAPI feature level 3.
742  *
743  * @param compilation The {@link ANeuralNetworksCompilation} to be evaluated.
744  * @param burst The newly created object or NULL if unsuccessful.
745  *
746  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
747  *         if the compilation is invalid.
748  * @deprecated NNAPI is deprecated. See
749  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
750  *   for more details.
751  */
752 int ANeuralNetworksBurst_create(ANeuralNetworksCompilation* compilation,
753                                 ANeuralNetworksBurst** burst) __NNAPI_INTRODUCED_IN(29)
754         __NNAPI_DEPRECATED_IN(35);
755 
756 /**
757  * Destroys the burst object.
758  *
759  * Available since NNAPI feature level 3.
760  *
761  * @param burst The burst object to be destroyed. Passing NULL is acceptable and
762  *              results in no operation.
763  * @deprecated NNAPI is deprecated. See
764  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
765  *   for more details.
766  */
767 void ANeuralNetworksBurst_free(ANeuralNetworksBurst* burst) __NNAPI_INTRODUCED_IN(29)
768         __NNAPI_DEPRECATED_IN(35);
769 
770 /**
771  * Schedule synchronous evaluation of the execution on a burst object.
772  *
773  * <p>Schedules synchronous evaluation of the execution. Returns once the
774  * execution has completed and the outputs are ready to be consumed.</p>
775  *
776  * If {@link ANeuralNetworksExecution_setTimeout} was called on the execution,
777  * and the execution is not able to complete before the timeout duration is
778  * exceeded, then execution may be aborted, in which case
779  * ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be returned.
780  *
781  * If the execution contains a {@link ANEURALNETWORKS_WHILE} operation, and
782  * the condition model does not output false within the loop timeout duration,
783  * then execution will be aborted and ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}
784  * will be returned. If the device has a feature level reported by
785  * {@link ANeuralNetworksDevice_getFeatureLevel} that is lower than
786  * {@link ANEURALNETWORKS_FEATURE_LEVEL_4}, then the timeout duration hint will be ignored.
787  *
788  * <p>There must be at most one {@link ANeuralNetworksExecution} processing at
789  * any given time for any given burst object. Any
790  * {@link ANeuralNetworksExecution} launched before the previous has finished
791  * will result in ANEURALNETWORKS_BAD_STATE.</p>
792  *
793  * Before NNAPI feature level 5, this function may only be invoked when the execution is in the
794  * preparation state. Starting at NNAPI feature level 5, if the user sets the execution to be
795  * reusable by {@link ANeuralNetworksExecution_setReusable}, this function may also be invoked when
796  * the execution is in the completed state.
797  *
798  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
799  *
800  * See {@link ANeuralNetworksExecution_compute} for synchronous execution.
801  * See {@link ANeuralNetworksExecution_startCompute} for regular asynchronous execution.
802  * See {@link ANeuralNetworksExecution_startComputeWithDependencies} for
803  * asynchronous execution with dependencies.
804  *
805  * Available since NNAPI feature level 3.
806  *
807  * @param burst The burst object to execute on.
808  * @param execution The execution to be scheduled and executed. The execution
809  *                  must be created from the same {@link
810  *                  ANeuralNetworksCompilation} as the burst object.
811  *
812  * @return ANEURALNETWORKS_NO_ERROR if the execution completed normally.
813  * @deprecated NNAPI is deprecated. See
814  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
815  *   for more details.
816  */
817 int ANeuralNetworksExecution_burstCompute(ANeuralNetworksExecution* execution,
818                                           ANeuralNetworksBurst* burst) __NNAPI_INTRODUCED_IN(29)
819         __NNAPI_DEPRECATED_IN(35);
820 
821 /**
822  * Creates a shared memory object from an AHardwareBuffer handle.
823  *
824  * If the shared memory is backed by an AHardwareBuffer of AHARDWAREBUFFER_FORMAT_BLOB
825  * format, it can be used the same way as shared memory created from a file handle. See
826  * {@link ANeuralNetworksMemory} for a description on how to use this shared memory.
827  *
828  * If the shared memory is backed by an AHardwareBuffer of a format other than
829  * AHARDWAREBUFFER_FORMAT_BLOB, it can only be used for model inputs and outputs.
830  * When calling {@link ANeuralNetworksExecution_setInputFromMemory} or
831  * {@link ANeuralNetworksExecution_setOutputFromMemory} with the shared memory, both
832  * offset and length must be set to zero and the entire memory region will be
833  * associated with the specified input or output operand. There is no guarantee
834  * that an arbitrary AHardwareBuffer_Format and AHardwareBuffer_UsageFlags combination
835  * can be used by arbitrary devices. The execution will fail if the selected set of
836  * devices cannot consume the buffer.
837  *
838  * Calling {@link ANeuralNetworksModel_setOperandValueFromMemory} with shared memory
839  * backed by an AHardwareBuffer of a format other than AHARDWAREBUFFER_FORMAT_BLOB is
840  * disallowed.
841  *
842  * The provided AHardwareBuffer must outlive the ANeuralNetworksMemory object.
843  *
844  * Available since NNAPI feature level 3.
845  *
846  * @param ahwb The AHardwareBuffer handle.
847  * @param memory The memory object to be created.
848  *               Set to NULL if unsuccessful.
849  *
850  * @return ANEURALNETWORKS_NO_ERROR if the request completed normally.
851  *
852  * @see AHardwareBuffer
853  * @deprecated NNAPI is deprecated. See
854  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
855  *   for more details.
856  */
857 #ifdef __ANDROID__
858 int ANeuralNetworksMemory_createFromAHardwareBuffer(const AHardwareBuffer* ahwb,
859                                                     ANeuralNetworksMemory** memory)
860         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
861 #endif  // __ANDROID__
862 
863 /**
864 
865  * Specifies whether duration of the {@link ANeuralNetworksExecution} is to be
866  * measured. Evaluation of the execution must not have been scheduled.
867  *
868  * By default, duration is not measured.
869  *
870  * The {@link ANeuralNetworksExecution} must have been created from an
871  * {@link ANeuralNetworksCompilation} which in turn was created from
872  * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1.
873  * If the device has a feature level reported by
874  * {@link ANeuralNetworksDevice_getFeatureLevel} that is lower than
875  * {@link ANEURALNETWORKS_FEATURE_LEVEL_3}, then the duration will not be measured.
876  *
877  * This function may only be invoked when the execution is in the preparation state.
878  *
879  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
880  *
881  * Available since NNAPI feature level 3.
882  *
883  * @param execution The execution to be modified.
884  * @param measure 'true' if duration is to be measured, 'false' if not.
885  *
886  * @return ANEURALNETWORKS_NO_ERROR if successful.
887  * @deprecated NNAPI is deprecated. See
888  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
889  *   for more details.
890  */
891 int ANeuralNetworksExecution_setMeasureTiming(ANeuralNetworksExecution* execution, bool measure)
892         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
893 
894 /**
895  * Get the time spent in the latest computation evaluated on the specified
896  * {@link ANeuralNetworksExecution}, in nanoseconds.
897  *
898  * This function may only be invoked when the execution is in the completed state.
899  *
900  * See {@link ANeuralNetworksExecution} for information on execution states.
901  *
902  * @param execution The execution to be queried.
903  * @param durationCode The measurement to be queried, specified by {@link DurationCode}.
904  * @param duration The returned duration. If no measurement was requested by
905  *                 {@link ANeuralNetworksExecution_setMeasureTiming}, if the
906  *                 device is has a feature level reported by
907  *                 {@link ANeuralNetworksDevice_getFeatureLevel} that is lower
908  *                 than {@link ANEURALNETWORKS_FEATURE_LEVEL_3}, or for some other
909  *                 reason the duration is not available, UINT64_MAX will be returned.
910  *                 A particular device need not support any given measurement.
911  *
912  * @return ANEURALNETWORKS_NO_ERROR if successful.
913  *
914  * Available since NNAPI feature level 3.
915  * @deprecated NNAPI is deprecated. See
916  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
917  *   for more details.
918  */
919 int ANeuralNetworksExecution_getDuration(const ANeuralNetworksExecution* execution,
920                                          int32_t durationCode, uint64_t* duration)
921         __NNAPI_INTRODUCED_IN(29) __NNAPI_DEPRECATED_IN(35);
922 
923 /**
924  * Creates a shared memory object from a file descriptor.
925  *
926  * The shared memory is backed by a file descriptor via mmap.
927  * See {@link ANeuralNetworksMemory} for a description on how to use
928  * this shared memory.
929  *
930  * Available since NNAPI feature level 1.
931  *
932  * @param size The requested size in bytes.
933  *             Must not be larger than the file size.
934  * @param protect The desired memory protection for the mapping.
935  *             It is either PROT_NONE or the bitwise OR of one or
936  *             more of the following flags: PROT_READ, PROT_WRITE.
937  * @param fd The requested file descriptor.
938  *           The file descriptor has to be mmap-able. The file
939  *           descriptor will be duplicated.
940  * @param offset The offset to the beginning of the file of the area to map.
941  *               The offset has to be aligned to a page size.
942  * @param memory The memory object to be created.
943  *               Set to NULL if unsuccessful.
944  *
945  * @return ANEURALNETWORKS_NO_ERROR if the request completed normally.
946  * @deprecated NNAPI is deprecated. See
947  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
948  *   for more details.
949  */
950 int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset,
951                                        ANeuralNetworksMemory** memory) __NNAPI_INTRODUCED_IN(27)
952         __NNAPI_DEPRECATED_IN(35);
953 
954 /**
955  * Delete a memory object.
956  *
957  * Destroys the object used by the run time to keep track of the memory.
958  * This will free the underlying actual memory if no other code has open
959  * handles to this memory.
960  *
961  * Available since NNAPI feature level 1.
962  *
963  * @param memory The memory object to be freed. Passing NULL is acceptable and
964  *               results in no operation.
965  * @deprecated NNAPI is deprecated. See
966  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
967  *   for more details.
968  */
969 void ANeuralNetworksMemory_free(ANeuralNetworksMemory* memory) __NNAPI_INTRODUCED_IN(27)
970         __NNAPI_DEPRECATED_IN(35);
971 
972 /**
973  * Create an empty {@link ANeuralNetworksModel}.
974  *
975  * <p>This only creates the object. Computation is performed once
976  * {@link ANeuralNetworksExecution_burstCompute},
977  * {@link ANeuralNetworksExecution_compute},
978  * {@link ANeuralNetworksExecution_startCompute} or
979  * {@link ANeuralNetworksExecution_startComputeWithDependencies} is invoked.
980  *
981  * The model should be constructed with calls to
982  * {@link ANeuralNetworksModel_addOperation} and
983  * {@link ANeuralNetworksModel_addOperand}
984  *
985  * <p>{@link ANeuralNetworksModel_finish} should be called once the model
986  * has been fully constructed.</p>
987  *
988  * <p>{@link ANeuralNetworksModel_free} should be called once the model
989  * is no longer needed.</p>
990  *
991  * Available since NNAPI feature level 1.
992  *
993  * @param model The {@link ANeuralNetworksModel} to be created.
994  *              Set to NULL if unsuccessful.
995  *
996  * @return ANEURALNETWORKS_NO_ERROR if successful.
997  * @deprecated NNAPI is deprecated. See
998  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
999  *   for more details.
1000  */
1001 int ANeuralNetworksModel_create(ANeuralNetworksModel** model) __NNAPI_INTRODUCED_IN(27)
1002         __NNAPI_DEPRECATED_IN(35);
1003 
1004 /**
1005  * Destroy a model.
1006  *
1007  * The model need not have been finished by a call to
1008  * {@link ANeuralNetworksModel_finish}.
1009  *
1010  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1011  *
1012  * Available since NNAPI feature level 1.
1013  *
1014  * @param model The model to be destroyed. Passing NULL is acceptable and
1015  *              results in no operation.
1016  * @deprecated NNAPI is deprecated. See
1017  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1018  *   for more details.
1019  */
1020 void ANeuralNetworksModel_free(ANeuralNetworksModel* model) __NNAPI_INTRODUCED_IN(27)
1021         __NNAPI_DEPRECATED_IN(35);
1022 
1023 /**
1024  * Indicate that we have finished modifying a model. Required before
1025  * calling {@link ANeuralNetworksCompilation_create} and
1026  * {@link ANeuralNetworksCompilation_createForDevices}.
1027  *
1028  * An application must ensure that no other thread uses the model at the same
1029  * time.
1030  *
1031  * This function must only be called once for a given model.
1032  *
1033  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1034  *
1035  * Available since NNAPI feature level 1.
1036  *
1037  * @param model The model to be finished.
1038  *
1039  * @return ANEURALNETWORKS_NO_ERROR if successful.
1040  * @deprecated NNAPI is deprecated. See
1041  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1042  *   for more details.
1043  */
1044 int ANeuralNetworksModel_finish(ANeuralNetworksModel* model) __NNAPI_INTRODUCED_IN(27)
1045         __NNAPI_DEPRECATED_IN(35);
1046 
1047 /**
1048  * Add an operand to a model.
1049  *
1050  * The order in which the operands are added is important. The first one added
1051  * to a model will have the index value 0, the second 1, etc. These indexes are
1052  * used as operand identifiers in
1053  * {@link ANeuralNetworksModel_addOperation},
1054  * {@link ANeuralNetworksModel_identifyInputsAndOutputs},
1055  * {@link ANeuralNetworksModel_setOperandValue},
1056  * {@link ANeuralNetworksModel_setOperandValueFromMemory},
1057  * {@link ANeuralNetworksExecution_setInput},
1058  * {@link ANeuralNetworksExecution_setInputFromMemory},
1059  * {@link ANeuralNetworksExecution_setOutput}, and
1060  * {@link ANeuralNetworksExecution_setOutputFromMemory}.
1061  *
1062  * <p>Every operand must be referenced in exactly one of the following
1063  * ways:<ul>
1064  *    <li>It is identified as a model input with
1065  *        {@link ANeuralNetworksModel_identifyInputsAndOutputs}.</li>
1066  *    <li>It is identified as a constant with
1067  *        {@link ANeuralNetworksModel_setOperandValue} or
1068  *        {@link ANeuralNetworksModel_setOperandValueFromMemory}.</li>
1069  *    <li>It is identified as an output of exactly one operation with
1070  *        {@link ANeuralNetworksModel_addOperation}.</li>
1071  *    </ul></p>
1072  * <p>An operand that is identified as a model input or as a constant
1073  * must not also be identified as a model output with
1074  * {@link ANeuralNetworksModel_identifyInputsAndOutputs}.</p>
1075  *
1076  * To build a model that can accommodate inputs of various sizes, as
1077  * you may want to do for a CNN, leave unspecified the dimensions that
1078  * will vary at run time.  If you do so, fully specify dimensions
1079  * when calling {@link ANeuralNetworksExecution_setInput} or
1080  * {@link ANeuralNetworksExecution_setInputFromMemory}.
1081  *
1082  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1083  * called will return an error.
1084  *
1085  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1086  *
1087  * Available since NNAPI feature level 1.
1088  *
1089  * @param model The model to be modified.
1090  * @param type The {@link ANeuralNetworksOperandType} that describes the shape
1091  *             of the operand.  Neither the {@link ANeuralNetworksOperandType}
1092  *             nor the dimensions it points to need to outlive the call to
1093  *             {@link ANeuralNetworksModel_addOperand}.
1094  *
1095  * @return ANEURALNETWORKS_NO_ERROR if successful.
1096  * @deprecated NNAPI is deprecated. See
1097  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1098  *   for more details.
1099  */
1100 int ANeuralNetworksModel_addOperand(ANeuralNetworksModel* model,
1101                                     const ANeuralNetworksOperandType* type)
1102         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1103 
1104 /**
1105  * Sets an operand to a constant value.
1106  *
1107  * Values of length smaller or equal to
1108  * ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES
1109  * are immediately copied into the model.
1110  *
1111  * For values of length greater than
1112  * ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES, a pointer to
1113  * the buffer is stored within the model. The application must not change the
1114  * content of this region until all executions using this model have
1115  * completed. As the data may be copied during processing, modifying the data
1116  * after this call yields undefined results. The provided buffer must outlive
1117  * this model.
1118  *
1119  * For large tensors, using {@link ANeuralNetworksModel_setOperandValueFromMemory}
1120  * is likely to be more efficient.
1121  *
1122  * To indicate that an optional operand should be considered missing,
1123  * pass nullptr for buffer and 0 for length.
1124  *
1125  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1126  * called will return an error.
1127  *
1128  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1129  *
1130  * Available since NNAPI feature level 1.
1131  *
1132  * @param model The model to be modified.
1133  * @param index The index of the model operand we're setting.
1134  * @param buffer A pointer to the data to use.
1135  * @param length The size in bytes of the data value.
1136  *
1137  * @return ANEURALNETWORKS_NO_ERROR if successful.
1138  * @deprecated NNAPI is deprecated. See
1139  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1140  *   for more details.
1141  */
1142 int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index,
1143                                          const void* buffer, size_t length)
1144         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1145 
1146 /**
1147  * Sets an operand's per channel quantization parameters.
1148  *
1149  * Sets parameters required by a tensor of type
1150  * {@link ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL}.
1151  * This function must be called for every tensor of type
1152  * {@link ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL} before
1153  * calling {@link ANeuralNetworksModel_finish}.
1154  *
1155  * Available since NNAPI feature level 3.
1156  *
1157  * @param model The model to be modified.
1158  * @param index The index of the model operand we're setting.
1159  * @param channelQuant The per channel quantization parameters for the operand.
1160  *                    No memory in this struct needs to outlive the call to
1161  *                    this function.
1162  *
1163  * @return ANEURALNETWORKS_NO_ERROR if successful.
1164  * @deprecated NNAPI is deprecated. See
1165  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1166  *   for more details.
1167  */
1168 int ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(
1169         ANeuralNetworksModel* model, int32_t index,
1170         const ANeuralNetworksSymmPerChannelQuantParams* channelQuant) __NNAPI_INTRODUCED_IN(29)
1171         __NNAPI_DEPRECATED_IN(35);
1172 
1173 /**
1174  * Sets an operand to a value stored in a memory object.
1175  *
1176  * The content of the memory is not copied. A reference to that memory is stored
1177  * inside the model. The application must not change the content of the memory
1178  * region until all executions using this model have completed.  As the data may
1179  * be copied during processing, modifying the data after this call yields
1180  * undefined results.
1181  *
1182  * <p>The provided memory must outlive this model.</p>
1183  *
1184  * To indicate that an optional operand should be considered missing,
1185  * use {@link ANeuralNetworksModel_setOperandValue} instead, passing nullptr for buffer.
1186  *
1187  * It is disallowed to set an operand value with shared memory backed by an AHardwareBuffer
1188  * of a format other than AHARDWAREBUFFER_FORMAT_BLOB.
1189  *
1190  * It is disallowed to set an operand value with memory created from
1191  * {@link ANeuralNetworksMemory_createFromDesc}.
1192  *
1193  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1194  * called will return an error.
1195  *
1196  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1197  * See {@link ANeuralNetworksMemory_createFromAHardwareBuffer} for information on
1198  * AHardwareBuffer usage.
1199  *
1200  * Available since NNAPI feature level 1.
1201  *
1202  * @param model The model to be modified.
1203  * @param index The index of the model operand we're setting.
1204  * @param memory The memory containing the data.
1205  * @param offset This specifies the location of the data within the memory.
1206  *               The offset is in bytes from the start of memory.
1207  * @param length The size in bytes of the data value.
1208  *
1209  * @return ANEURALNETWORKS_NO_ERROR if successful.
1210  * @deprecated NNAPI is deprecated. See
1211  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1212  *   for more details.
1213  */
1214 int ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel* model, int32_t index,
1215                                                    const ANeuralNetworksMemory* memory,
1216                                                    size_t offset, size_t length)
1217         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1218 
1219 /**
1220  * Sets an operand to a value that is a reference to another NNAPI model.
1221  *
1222  * The referenced model must already have been finished by a call to
1223  * {@link ANeuralNetworksModel_finish}.
1224  *
1225  * The {@link ANeuralNetworksModel_relaxComputationFloat32toFloat16} setting of
1226  * referenced models is overridden by that setting of the main model of a
1227  * compilation.
1228  *
1229  * The referenced model must outlive the model referring to it.
1230  *
1231  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has
1232  * been called will return an error.
1233  *
1234  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1235  *
1236  * Available since NNAPI feature level 4.
1237  *
1238  * @param model The model to be modified.
1239  * @param index The index of the model operand we're setting.
1240  * @param value The model to be referenced.
1241  *
1242  * @return ANEURALNETWORKS_NO_ERROR if successful.
1243  * @deprecated NNAPI is deprecated. See
1244  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1245  *   for more details.
1246  */
1247 int ANeuralNetworksModel_setOperandValueFromModel(ANeuralNetworksModel* model, int32_t index,
1248                                                   const ANeuralNetworksModel* value)
1249         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
1250 
1251 /**
1252  * Add an operation to a model.
1253  *
1254  * @param model The model to be modified.
1255  * @param type The {@link ANeuralNetworksOperationType} of the operation.
1256  * @param inputCount The number of entries in the inputs array.
1257  * @param inputs An array of indexes identifying each operand.
1258  * @param outputCount The number of entries in the outputs array.
1259  * @param outputs An array of indexes identifying each operand.
1260  *
1261  * The operands specified by inputs and outputs must have been
1262  * previously added by calls to {@link ANeuralNetworksModel_addOperand}.
1263  *
1264  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1265  * called will return an error.
1266  *
1267  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1268  *
1269  * Available since NNAPI feature level 1.
1270  *
1271  * @return ANEURALNETWORKS_NO_ERROR if successful.
1272  * @deprecated NNAPI is deprecated. See
1273  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1274  *   for more details.
1275  */
1276 int ANeuralNetworksModel_addOperation(ANeuralNetworksModel* model,
1277                                       ANeuralNetworksOperationType type, uint32_t inputCount,
1278                                       const uint32_t* inputs, uint32_t outputCount,
1279                                       const uint32_t* outputs) __NNAPI_INTRODUCED_IN(27)
1280         __NNAPI_DEPRECATED_IN(35);
1281 
1282 /**
1283  * Specifies which operands will be the model's inputs and
1284  * outputs. Every model must have at least one input and one output.
1285  *
1286  * An operand cannot be used for both input and output. Doing so will
1287  * return an error.
1288  *
1289  * @param model The model to be modified.
1290  * @param inputCount The number of entries in the inputs array.
1291  * @param inputs An array of indexes identifying the input operands.
1292  * @param outputCount The number of entries in the outputs array.
1293  * @param outputs An array of indexes identifying the output operands.
1294  *
1295  * The operands specified by inputs and outputs must have been
1296  * previously added by calls to {@link ANeuralNetworksModel_addOperand}.
1297  *
1298  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1299  * called will return an error.
1300  *
1301  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1302  *
1303  * Available since NNAPI feature level 1.
1304  *
1305  * @deprecated NNAPI is deprecated. See
1306  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1307  *   for more details.
1308  */
1309 int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, uint32_t inputCount,
1310                                                   const uint32_t* inputs, uint32_t outputCount,
1311                                                   const uint32_t* outputs) __NNAPI_INTRODUCED_IN(27)
1312         __NNAPI_DEPRECATED_IN(35);
1313 
1314 /**
1315  * Specifies whether {@link ANEURALNETWORKS_TENSOR_FLOAT32} is allowed to be
1316  * calculated with range and/or precision as low as that of the IEEE 754 16-bit
1317  * floating-point format. By default, {@link ANEURALNETWORKS_TENSOR_FLOAT32}
1318  * must be calculated using at least the range and precision of the IEEE 754
1319  * 32-bit floating-point format.
1320  *
1321  * The relaxComputationFloat32toFloat16 setting of the main model of
1322  * a compilation overrides the values of the referenced models.
1323  *
1324  * @param model The model to be modified.
1325  * @param allow 'true' indicates {@link ANEURALNETWORKS_TENSOR_FLOAT32} may be
1326  *              calculated with range and/or precision as low as that of the
1327  *              IEEE 754 16-bit floating point format. 'false' indicates
1328  *              {@link ANEURALNETWORKS_TENSOR_FLOAT32} must be calculated using
1329  *              at least the range and precision of the IEEE 754 32-bit floating
1330  *              point format.
1331  *
1332  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1333  * called will return an error.
1334  *
1335  * Available since NNAPI feature level 2.
1336  *
1337  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1338  * @deprecated NNAPI is deprecated. See
1339  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1340  *   for more details.
1341  */
1342 int ANeuralNetworksModel_relaxComputationFloat32toFloat16(ANeuralNetworksModel* model, bool allow)
1343         __NNAPI_INTRODUCED_IN(28) __NNAPI_DEPRECATED_IN(35);
1344 
1345 /**
1346  * Create a {@link ANeuralNetworksCompilation} to compile the given model.
1347  *
1348  * The model passed to this function is termed the "main model" of the
1349  * compilation, to distinguish it from other models referred to by an Operand
1350  * of type {@link ANEURALNETWORKS_MODEL} within this compilation.
1351  *
1352  * <p>This function only creates the object. Compilation is only performed once
1353  * {@link ANeuralNetworksCompilation_finish} is invoked.</p>
1354  *
1355  * <p>{@link ANeuralNetworksCompilation_finish} should be called once
1356  * all desired properties have been set on the compilation.</p>
1357  *
1358  * <p>{@link ANeuralNetworksModel_free} should be called once the compilation
1359  * is no longer needed.</p>
1360  *
1361  * <p>The provided model must outlive the compilation.</p>
1362  *
1363  * The model must already have been finished by a call to
1364  * {@link ANeuralNetworksModel_finish}.
1365  *
1366  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1367  *
1368  * Available since NNAPI feature level 1.
1369  *
1370  * @param model The {@link ANeuralNetworksModel} to be compiled.
1371  * @param compilation The newly created object or NULL if unsuccessful.
1372  *
1373  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
1374  *         if the model is invalid.
1375  * @deprecated NNAPI is deprecated. See
1376  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1377  *   for more details.
1378  */
1379 int ANeuralNetworksCompilation_create(ANeuralNetworksModel* model,
1380                                       ANeuralNetworksCompilation** compilation)
1381         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1382 
1383 /**
1384  * Destroy a compilation.
1385  *
1386  * The compilation need not have been finished by a call to
1387  * {@link ANeuralNetworksCompilation_finish}.
1388  *
1389  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1390  *
1391  * Available since NNAPI feature level 1.
1392  *
1393  * @param compilation The compilation to be destroyed. Passing NULL is acceptable and
1394  *                    results in no operation.
1395  * @deprecated NNAPI is deprecated. See
1396  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1397  *   for more details.
1398  */
1399 void ANeuralNetworksCompilation_free(ANeuralNetworksCompilation* compilation)
1400         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1401 
1402 /**
1403  * Sets the execution preference.
1404  *
1405  * <p>Provides guidance to the runtime when trade-offs are possible. By default the runtime
1406  * uses PREFER_SINGLE_FAST_ANSWER</p>
1407  *
1408  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1409  *
1410  * Available since NNAPI feature level 1.
1411  *
1412  * @param compilation The compilation to be modified.
1413  * @param preference Either {@link ANEURALNETWORKS_PREFER_LOW_POWER},
1414  *                  {@link ANEURALNETWORKS_PREFER_FAST_SINGLE_ANSWER}, or
1415  *                  {@link ANEURALNETWORKS_PREFER_SUSTAINED_SPEED}.
1416  *
1417  * @return ANEURALNETWORKS_NO_ERROR if successful.
1418  * @deprecated NNAPI is deprecated. See
1419  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1420  *   for more details.
1421  */
1422 int ANeuralNetworksCompilation_setPreference(ANeuralNetworksCompilation* compilation,
1423                                              int32_t preference) __NNAPI_INTRODUCED_IN(27)
1424         __NNAPI_DEPRECATED_IN(35);
1425 
1426 /**
1427  * Indicate that we have finished modifying a compilation. Required before
1428  * calling {@link ANeuralNetworksBurst_create} or
1429  * {@link ANeuralNetworksExecution_create}.
1430  *
1431  * An application must ensure that no other thread uses the compilation at the
1432  * same time.
1433  *
1434  * This function must only be called once for a given compilation.
1435  *
1436  * If {@link ANeuralNetworksCompilation_setTimeout} was called on this
1437  * compilation, and the compilation is not able to be finished before the
1438  * timeout duration is exceeded, then compilation may be aborted, in which case
1439  * ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be returned.
1440  *
1441  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1442  *
1443  * Available since NNAPI feature level 1.
1444  *
1445  * @param compilation The compilation to be finished.
1446  *
1447  * @return ANEURALNETWORKS_NO_ERROR if successful.
1448  * @deprecated NNAPI is deprecated. See
1449  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1450  *   for more details.
1451  */
1452 int ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation* compilation)
1453         __NNAPI_INTRODUCED_IN(27) __NNAPI_DEPRECATED_IN(35);
1454 
1455 /**
1456  * Set the execution priority.
1457  *
1458  * Execution priorities are relative to other executions created by the same
1459  * application (specifically same uid) for the same device. Specifically,
1460  * priorities of executions from one application will not affect executions from
1461  * another application. Similarly, priorities of executions on one device will
1462  * not affect executions on another device.
1463  *
1464  * Higher priority executions may use more compute resources than lower priority
1465  * executions, and may preempt or starve lower priority executions.
1466  *
1467  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1468  *
1469  * Available since NNAPI feature level 4.
1470  *
1471  * @param compilation The compilation to be modified.
1472  * @param priority The relative priority of the execution compared to other
1473  *     executions created by the application. Must be one of
1474  *     ANEURALNETWORKS_PRIORITY_*.
1475  *
1476  * @return ANEURALNETWORKS_NO_ERROR if successful.
1477  * @deprecated NNAPI is deprecated. See
1478  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1479  *   for more details.
1480  */
1481 int ANeuralNetworksCompilation_setPriority(ANeuralNetworksCompilation* compilation, int priority)
1482         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
1483 
1484 /**
1485  * Set the maximum expected duration for compiling the model.
1486  *
1487  * If the device is not able to complete the compilation within the specified
1488  * duration, the compilation may be aborted. The timeout duration begins at the
1489  * call to {@link ANeuralNetworksCompilation_finish}.
1490  *
1491  * This timeout duration acts as a hint to drivers, and can be used to both free
1492  * up compute resources within the driver and return control back to the
1493  * application quicker than is possible without the hint. It enables drivers
1494  * that are able to estimate how long a compilation will take to abort the
1495  * compilation before it has even started if the driver believes the compilation
1496  * cannot be completed within the timeout duration. Similarly, it enables
1497  * drivers to abort an ongoing compilation if it is taking too long. However,
1498  * this call does not guarantee that the compilation will complete or abort
1499  * within the timeout duration.
1500  *
1501  * By default (i.e., unless ANeuralNetworksCompilation_setTimeout is called),
1502  * the timeout duration for compiling the model is considered infinite.
1503  *
1504  * The {@link ANeuralNetworksCompilation} must have been created with
1505  * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1,
1506  * otherwise this function will fail with ANEURALNETWORKS_BAD_DATA. If the
1507  * device has a feature level reported by
1508  * {@link ANeuralNetworksDevice_getFeatureLevel} that is lower than
1509  * {@link ANEURALNETWORKS_FEATURE_LEVEL_4}, then the timeout duration hint will
1510  * be ignored.
1511  *
1512  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1513  *
1514  * @param compilation The compilation to be modified.
1515  * @param duration The maximum amount of time in nanoseconds that is expected to
1516  *     be spent finishing a compilation. If this duration is exceeded, the
1517  *     compilation may be aborted. If set to 0, the timeout duration is
1518  *     considered infinite.
1519  *
1520  * @return ANEURALNETWORKS_NO_ERROR if successful.
1521  *
1522  * Available since NNAPI feature level 4.
1523  * @deprecated NNAPI is deprecated. See
1524  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1525  *   for more details.
1526  */
1527 int ANeuralNetworksCompilation_setTimeout(ANeuralNetworksCompilation* compilation,
1528                                           uint64_t duration) __NNAPI_INTRODUCED_IN(30)
1529         __NNAPI_DEPRECATED_IN(35);
1530 
1531 /**
1532  * Create a {@link ANeuralNetworksExecution} to apply the given compilation.
1533  * This only creates the object. Computation is only performed once
1534  * {@link ANeuralNetworksExecution_burstCompute},
1535  * {@link ANeuralNetworksExecution_compute},
1536  * {@link ANeuralNetworksExecution_startCompute} or
1537  * {@link ANeuralNetworksExecution_startComputeWithDependencies} is invoked.
1538  *
1539  * <p>The provided compilation must outlive the execution.</p>
1540  *
1541  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1542  *
1543  * Available since NNAPI feature level 1.
1544  *
1545  * @param compilation The {@link ANeuralNetworksCompilation} to be evaluated.
1546  * @param execution The newly created object or NULL if unsuccessful.
1547  *
1548  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
1549  *         if the compilation is invalid.
1550  * @deprecated NNAPI is deprecated. See
1551  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1552  *   for more details.
1553  */
1554 int ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation,
1555                                     ANeuralNetworksExecution** execution) __NNAPI_INTRODUCED_IN(27)
1556         __NNAPI_DEPRECATED_IN(35);
1557 
1558 /**
1559  * Destroy an execution.
1560  *
1561  * <p>The execution need not have been scheduled by a call to
1562  * {@link ANeuralNetworksExecution_burstCompute},
1563  * {@link ANeuralNetworksExecution_compute},
1564  * {@link ANeuralNetworksExecution_startCompute} or
1565  * {@link ANeuralNetworksExecution_startComputeWithDependencies}; but if it has been scheduled,
1566  * then the application must not call {@link ANeuralNetworksExecution_free}
1567  * until the execution has completed (i.e.,
1568  * {@link ANeuralNetworksExecution_burstCompute},
1569  * {@link ANeuralNetworksExecution_compute}, or
1570  * {@link ANeuralNetworksEvent_wait} has returned).
1571  *
1572  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1573  *
1574  * Available since NNAPI feature level 1.
1575  *
1576  * @param execution The execution to be destroyed. Passing NULL is acceptable and
1577  *                  results in no operation.
1578  * @deprecated NNAPI is deprecated. See
1579  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1580  *   for more details.
1581  */
1582 void ANeuralNetworksExecution_free(ANeuralNetworksExecution* execution) __NNAPI_INTRODUCED_IN(27)
1583         __NNAPI_DEPRECATED_IN(35);
1584 
1585 /**
1586  * Associate a user buffer with an input of the model of the
1587  * {@link ANeuralNetworksExecution}. Evaluation of the execution must not have
1588  * been scheduled. Once evaluation of the execution has been scheduled, the
1589  * application must not change the content of the buffer until the execution has
1590  * completed. Evaluation of the execution will not change the content of the
1591  * buffer.
1592  *
1593  * <p>The provided buffer must outlive the execution.</p>
1594  *
1595  * If the input is optional, you can indicate that it is omitted by
1596  * passing nullptr for buffer and 0 for length.
1597  *
1598  * Otherwise, if the user has not set the execution to accept padded input buffers by
1599  * calling {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, then the length argument
1600  * must be equal to the raw size of the input (i.e. the size of an element multiplied by the
1601  * number of elements). Passing a length argument with value not equal to the raw size of the input
1602  * will result in ANEURALNETWORKS_BAD_DATA.
1603  *
1604  * Otherwise, if the user has set the execution to accept padded input buffers by calling
1605  * {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, the length argument may be greater
1606  * than the raw size of the input, and the extra bytes at the end of the buffer may be used
1607  * by the driver to access data in chunks, for efficiency. Passing a length argument with value
1608  * less than the raw size of the input will result in ANEURALNETWORKS_BAD_DATA.
1609  *
1610  * This function may only be invoked when the execution is in the preparation state.
1611  *
1612  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1613  * See {@link ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput} and
1614  * {@link ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput} for information on getting
1615  * preferred buffer alignment and padding, to improve performance.
1616  *
1617  * Available since NNAPI feature level 1.
1618  *
1619  * @param execution The execution to be modified.
1620  * @param index The index of the input argument we are setting. It is
1621  *              an index into the lists passed to
1622  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1623  *              the index associated with
1624  *              {@link ANeuralNetworksModel_addOperand}.
1625  * @param type The {@link ANeuralNetworksOperandType} of the
1626  *             operand. Unless the input is omitted, this should be
1627  *             used to specify the dimensions that were left
1628  *             unspecified when the operand was added to the
1629  *             model. All other properties of the type must be the
1630  *             same as specified in the model. If the type is the same
1631  *             as specified when the model was built, NULL can be
1632  *             passed. Neither the {@link ANeuralNetworksOperandType}
1633  *             nor the dimensions it points to need to outlive the call
1634  *             to {@link ANeuralNetworksExecution_setInput}.
1635  * @param buffer The buffer containing the data.
1636  * @param length The size of the data value in bytes plus any end padding.
1637  *
1638  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1639  *         name is not recognized or the buffer is too small for the input.
1640  * @deprecated NNAPI is deprecated. See
1641  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1642  *   for more details.
1643  */
1644 int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution* execution, int32_t index,
1645                                       const ANeuralNetworksOperandType* type, const void* buffer,
1646                                       size_t length) __NNAPI_INTRODUCED_IN(27)
1647         __NNAPI_DEPRECATED_IN(35);
1648 
1649 /**
1650  * Associate a region of a memory object with an input of the model of the
1651  * {@link ANeuralNetworksExecution}. Evaluation of the execution must not have
1652  * been scheduled. Once evaluation of the execution has been scheduled, the
1653  * application must not change the content of the region until the execution has
1654  * completed. Evaluation of the execution will not change the content of the
1655  * region.
1656  *
1657  * <p>The provided memory must outlive the execution.</p>
1658  *
1659  * If the input is optional, you can indicate that it is omitted by
1660  * using {@link ANeuralNetworksExecution_setInput} instead, passing nullptr for
1661  * buffer and 0 for length.
1662  *
1663  * If the memory is an AHardwareBuffer of a format other than AHARDWAREBUFFER_FORMAT_BLOB created
1664  * from {@link ANeuralNetworksMemory_createFromAHardwareBuffer}, or an opaque memory object created
1665  * from {@link ANeuralNetworksMemory_createFromDesc}, both offset and length must be 0, indicating
1666  * the whole memory is used.
1667  *
1668  * Otherwise, if the user has not set the execution to accept padded input memory objects by
1669  * calling {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, then the length argument
1670  * must be equal to the raw size of the input (i.e. the size of an element multiplied by the
1671  * number of elements). Passing a length argument with value not equal to the raw size of the input
1672  * will result in ANEURALNETWORKS_BAD_DATA.
1673  *
1674  * Otherwise, if the user has set the execution to accept padded input memory objects by calling
1675  * {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, the length argument may be greater
1676  * than the raw size of the input, and the extra bytes at the end of the memory region may be used
1677  * by the driver to access data in chunks, for efficiency. Passing a length argument with value
1678  * less than the raw size of the input will result in ANEURALNETWORKS_BAD_DATA.
1679  *
1680  * This function may only be invoked when the execution is in the preparation state.
1681  *
1682  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1683  * See {@link ANeuralNetworksMemory_createFromAHardwareBuffer} for information on
1684  * AHardwareBuffer usage.
1685  * See {@link ANeuralNetworksMemory_createFromDesc} for information on usage of memory objects
1686  * created from memory descriptors.
1687  * See {@link ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput} and
1688  * {@link ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput} for information on getting
1689  * preferred memory alignment and padding, to improve performance.
1690  *
1691  * Available since NNAPI feature level 1.
1692  *
1693  * @param execution The execution to be modified.
1694  * @param index The index of the input argument we are setting. It is
1695  *              an index into the lists passed to
1696  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1697  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1698  * @param type The {@link ANeuralNetworksOperandType} of the
1699  *             operand. This should be used to specify the dimensions
1700  *             that were left unspecified when the operand was added
1701  *             to the model. All other properties of the type must be
1702  *             the same as specified in the model. If the type is the
1703  *             same as specified when the model was built, NULL can be
1704  *             passed. Neither the {@link ANeuralNetworksOperandType}
1705  *             nor the dimensions it points to need to outlive the call
1706  *             to {@link ANeuralNetworksExecution_setInputFromMemory}.
1707  * @param memory The memory containing the data.
1708  * @param offset This specifies the location of the data within the memory.
1709  *               The offset is in bytes from the start of memory.
1710  * @param length The size of the data value in bytes plus any end padding.
1711  *
1712  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1713  *         name is not recognized or the buffer is too small for the input.
1714  * @deprecated NNAPI is deprecated. See
1715  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1716  *   for more details.
1717  */
1718 int ANeuralNetworksExecution_setInputFromMemory(ANeuralNetworksExecution* execution, int32_t index,
1719                                                 const ANeuralNetworksOperandType* type,
1720                                                 const ANeuralNetworksMemory* memory, size_t offset,
1721                                                 size_t length) __NNAPI_INTRODUCED_IN(27)
1722         __NNAPI_DEPRECATED_IN(35);
1723 
1724 /**
1725  * Associate a user buffer with an output of the model of the
1726  * {@link ANeuralNetworksExecution}. Evaluation of the execution must not have
1727  * been scheduled. Once evaluation of the execution has been scheduled, the
1728  * application must not change the content of the buffer until the execution has
1729  * completed.
1730  *
1731  * <p>The provided buffer must outlive the execution.</p>
1732  *
1733  * If the output is optional, you can indicate that it is omitted by
1734  * passing nullptr for buffer and 0 for length.
1735  *
1736  * Otherwise, if the user has not set the execution to accept padded output buffers by
1737  * calling {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, then the length argument
1738  * must be equal to the raw size of the output (i.e. the size of an element multiplied by the
1739  * number of elements). Passing a length argument with value not equal to the raw size of the output
1740  * will result in ANEURALNETWORKS_BAD_DATA.
1741  *
1742  * Otherwise, if the user has set the execution to accept padded output buffers by calling
1743  * {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, the length argument may be greater
1744  * than the raw size of the output, and the extra bytes at the end of the buffer may be used
1745  * by the driver to access data in chunks, for efficiency. Passing a length argument with value
1746  * less than the raw size of the output will result in ANEURALNETWORKS_BAD_DATA.
1747  *
1748  * This function may only be invoked when the execution is in the preparation state.
1749  *
1750  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1751  * See {@link ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput} and
1752  * {@link ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput} for information on getting
1753  * preferred buffer alignment and padding, to improve performance.
1754  *
1755  * Available since NNAPI feature level 1.
1756  *
1757  * @param execution The execution to be modified.
1758  * @param index The index of the output argument we are setting. It is
1759  *              an index into the lists passed to
1760  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1761  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1762  * @param type The {@link ANeuralNetworksOperandType} of the
1763  *             operand. Unless the output is omitted, this should be
1764  *             used to specify the dimensions that were left
1765  *             unspecified when the operand was added to the
1766  *             model. All other properties of the type must be the
1767  *             same as specified in the model. If the type is the same
1768  *             as specified when the model was built, NULL can be
1769  *             passed. Neither the {@link ANeuralNetworksOperandType}
1770  *             nor the dimensions it points to need to outlive the call
1771  *             to {@link ANeuralNetworksExecution_setOutput}.
1772  *             Since NNAPI feature level 3, the output operand can have unspecified
1773  *             dimensions or rank to be deduced dynamically during the execution.
1774  *             However, the user must provide a large enough buffer. The user
1775  *             can retrieve the output dimensional information after the execution
1776  *             by {@link ANeuralNetworksExecution_getOutputOperandRank} and
1777  *             {@link ANeuralNetworksExecution_getOutputOperandDimensions}.
1778  * @param buffer The buffer where the data is to be written.
1779  * @param length The size of the data value in bytes plus any end padding.
1780  *
1781  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1782  *         name is not recognized or the buffer is too small for the output.
1783  * @deprecated NNAPI is deprecated. See
1784  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1785  *   for more details.
1786  */
1787 int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* execution, int32_t index,
1788                                        const ANeuralNetworksOperandType* type, void* buffer,
1789                                        size_t length) __NNAPI_INTRODUCED_IN(27)
1790         __NNAPI_DEPRECATED_IN(35);
1791 
1792 /**
1793  * Associate a region of a memory object with an output of the model of the
1794  * {@link ANeuralNetworksExecution}. Evaluation of the execution must not have
1795  * been scheduled. Once evaluation of the execution has been scheduled, the
1796  * application must not change the content of the region until the execution has
1797  * completed.
1798  *
1799  * <p>The provided memory must outlive the execution.</p>
1800  *
1801  * If the output is optional, you can indicate that it is omitted by
1802  * using {@link ANeuralNetworksExecution_setOutput} instead, passing nullptr for
1803  * buffer and 0 for length.
1804  *
1805  * If the memory is an AHardwareBuffer of a format other than AHARDWAREBUFFER_FORMAT_BLOB created
1806  * from {@link ANeuralNetworksMemory_createFromAHardwareBuffer}, or an opaque memory object created
1807  * from {@link ANeuralNetworksMemory_createFromDesc}, both offset and length must be 0, indicating
1808  * the whole memory is used.
1809  *
1810  * Otherwise, if the user has not set the execution to accept padded output memory objects by
1811  * calling {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, then the length argument
1812  * must be equal to the raw size of the output (i.e. the size of an element multiplied by the
1813  * number of elements). Passing a length argument with value not equal to the raw size of the output
1814  * will result in ANEURALNETWORKS_BAD_DATA.
1815  *
1816  * Otherwise, if the user has set the execution to accept padded output memory objects by calling
1817  * {@link ANeuralNetworksExecution_enableInputAndOutputPadding}, the length argument may be greater
1818  * than the raw size of the output, and the extra bytes at the end of the memory region may be used
1819  * by the driver to access data in chunks, for efficiency. Passing a length argument with value
1820  * less than the raw size of the output will result in ANEURALNETWORKS_BAD_DATA.
1821  *
1822  * This function may only be invoked when the execution is in the preparation state.
1823  *
1824  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1825  * See {@link ANeuralNetworksMemory_createFromAHardwareBuffer} for information on
1826  * AHardwareBuffer usage.
1827  * See {@link ANeuralNetworksMemory_createFromDesc} for information on usage of memory objects
1828  * created from memory descriptors.
1829  * See {@link ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput} and
1830  * {@link ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput} for information on getting
1831  * preferred memory alignment and padding, to improve performance.
1832  *
1833  * Available since NNAPI feature level 1.
1834  *
1835  * @param execution The execution to be modified.
1836  * @param index The index of the output argument we are setting. It is
1837  *              an index into the lists passed to
1838  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1839  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1840  * @param type The {@link ANeuralNetworksOperandType} of the operand. This should be
1841  *             used to specify the dimensions that were left
1842  *             unspecified when the operand was added to the
1843  *             model. All other properties of the type must be the
1844  *             same as specified in the model. If the type is the same
1845  *             as specified when the model was built, NULL can be
1846  *             passed. Neither the {@link ANeuralNetworksOperandType}
1847  *             nor the dimensions it points to need to outlive the call
1848  *             to {@link ANeuralNetworksExecution_setOutputFromMemory}.
1849  *             Since NNAPI feature level 3, the output operand can have unspecified
1850  *             dimensions or rank to be deduced dynamically during the execution.
1851  *             However, the user must provide a large enough memory. The user
1852  *             can retrieve the output dimensional information after the execution
1853  *             by {@link ANeuralNetworksExecution_getOutputOperandRank} and
1854  *             {@link ANeuralNetworksExecution_getOutputOperandDimensions}.
1855  * @param memory The memory where the data is to be stored.
1856  * @param offset This specifies the location of the data within the memory.
1857  *               The offset is in bytes from the start of memory.
1858  * @param length The size of the data value in bytes plus any end padding.
1859  *
1860  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1861  *         name is not recognized or the buffer is too small for the output.
1862  * @deprecated NNAPI is deprecated. See
1863  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1864  *   for more details.
1865  */
1866 int ANeuralNetworksExecution_setOutputFromMemory(ANeuralNetworksExecution* execution, int32_t index,
1867                                                  const ANeuralNetworksOperandType* type,
1868                                                  const ANeuralNetworksMemory* memory, size_t offset,
1869                                                  size_t length) __NNAPI_INTRODUCED_IN(27)
1870         __NNAPI_DEPRECATED_IN(35);
1871 
1872 /**
1873  * Schedule asynchronous evaluation of the execution.
1874  *
1875  * <p>Schedules asynchronous evaluation of the execution. Once the execution
1876  * has completed and the outputs are ready to be consumed, the returned event
1877  * will be signaled. Use {@link ANeuralNetworksEvent_wait} to wait for that
1878  * event.
1879  * </p>
1880  *
1881  * ANeuralNetworksEvent_wait must be called to recuperate the resources used
1882  * by the execution.
1883  *
1884  * If {@link ANeuralNetworksExecution_setTimeout} was called on this execution,
1885  * and the execution is not able to complete before the timeout duration is
1886  * exceeded, then execution may be aborted, in which case
1887  * ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be returned through
1888  * {@link ANeuralNetworksExecution_startCompute} or
1889  * {@link ANeuralNetworksEvent_wait} on the event object. If the device has a
1890  * feature level reported by {@link ANeuralNetworksDevice_getFeatureLevel} that
1891  * is lower than {@link ANEURALNETWORKS_FEATURE_LEVEL_4}, then the timeout
1892  * duration hint will be ignored.
1893  *
1894  * If this execution contains a {@link ANEURALNETWORKS_WHILE} operation, and
1895  * the condition model does not output false within the loop timeout duration,
1896  * then execution will be aborted and ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}
1897  * will be returned through {@link ANeuralNetworksEvent_wait} on the event
1898  * object.
1899  *
1900  * If the device can detect before the execution has started that the execution
1901  * will not complete within the timeout duration, the device may choose to skip
1902  * the execution and instead return ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}.
1903  *
1904  * Before NNAPI feature level 5, this function may only be invoked when the execution is in the
1905  * preparation state. Starting at NNAPI feature level 5, if the user sets the execution to be
1906  * reusable by {@link ANeuralNetworksExecution_setReusable}, this function may also be invoked when
1907  * the execution is in the completed state.
1908  *
1909  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1910  *
1911  * See {@link ANeuralNetworksExecution_compute} for synchronous execution.
1912  * See {@link ANeuralNetworksExecution_burstCompute} for burst synchronous execution.
1913  * See {@link ANeuralNetworksExecution_startComputeWithDependencies} for
1914  * asynchronous execution with dependencies.
1915  *
1916  * Available since NNAPI feature level 1.
1917  *
1918  * @param execution The execution to be scheduled and executed.
1919  * @param event The event that will be signaled on completion. event is set to
1920  *              NULL if there's an error.
1921  *
1922  * @return ANEURALNETWORKS_NO_ERROR if the evaluation is successfully scheduled.
1923  * @deprecated NNAPI is deprecated. See
1924  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1925  *   for more details.
1926  */
1927 int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution,
1928                                           ANeuralNetworksEvent** event) __NNAPI_INTRODUCED_IN(27)
1929         __NNAPI_DEPRECATED_IN(35);
1930 
1931 /**
1932  * Set the maximum expected duration of the specified execution.
1933  *
1934  * If the device is not able to complete the execution within the specified
1935  * duration, the execution may be aborted. The timeout duration begins at a
1936  * call to one of:
1937  * - {@link ANeuralNetworksExecution_burstCompute}
1938  * - {@link ANeuralNetworksExecution_compute}
1939  * - {@link ANeuralNetworksExecution_startCompute}
1940  * - {@link ANeuralNetworksExecution_startComputeWithDependencies}
1941  *
1942  * This timeout duration acts as a hint to drivers, and can be used to both free
1943  * up compute resources within the driver and return control back to the
1944  * application quicker than is possible without the hint. It enables drivers
1945  * that are able to estimate how long an execution will take to abort the
1946  * execution before it has even started if the driver believes the execution
1947  * cannot be completed within the timeout duration. Similarly, it enables
1948  * drivers to abort an ongoing execution if it is taking too long. However, this
1949  * call does not guarantee that the execution will complete or abort within the
1950  * timeout duration.
1951  *
1952  * By default (i.e., unless ANeuralNetworksExecution_setTimeout is called),
1953  * the timeout duration for execution is considered infinite.
1954  *
1955  * The {@link ANeuralNetworksExecution} must have been created from an
1956  * {@link ANeuralNetworksCompilation} which in turn was created from
1957  * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1,
1958  * otherwise this function will fail with ANEURALNETWORKS_BAD_DATA. If the
1959  * device has a feature level reported by
1960  * {@link ANeuralNetworksDevice_getFeatureLevel} that is lower than
1961  * {@link ANEURALNETWORKS_FEATURE_LEVEL_4}, then the timeout duration hint will
1962  * be ignored.
1963  *
1964  * This function may only be invoked when the execution is in the preparation state.
1965  *
1966  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1967  *
1968  * @param execution The execution to be modified.
1969  * @param duration The maximum amount of time in nanoseconds that is expected to
1970  *     be spent executing a model. If this duration is exceeded, the execution
1971  *     may be aborted. If set to 0, the timeout duration is considered infinite.
1972  *
1973  * @return ANEURALNETWORKS_NO_ERROR if successful.
1974  *
1975  * Available since NNAPI feature level 4.
1976  * @deprecated NNAPI is deprecated. See
1977  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
1978  *   for more details.
1979  */
1980 int ANeuralNetworksExecution_setTimeout(ANeuralNetworksExecution* execution, uint64_t duration)
1981         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
1982 
1983 /**
1984  * Set the maximum duration of WHILE loops in the specified execution.
1985  *
1986  * This is a fuzzy per-loop timeout intended to prevent infinite loops.
1987  *
1988  * If a WHILE loop condition model does not output false within the specified
1989  * duration, the execution will be aborted.
1990  *
1991  * See {@link ANeuralNetworks_getDefaultLoopTimeout} and
1992  * {@link ANeuralNetworks_getMaximumLoopTimeout} for the default
1993  * and maximum timeout values.
1994  *
1995  * This function may only be invoked when the execution is in the preparation state.
1996  *
1997  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
1998  *
1999  * @param execution The execution to be modified.
2000  * @param duration The maximum amount of time in nanoseconds that can be spent
2001  *     executing a WHILE loop. If the specified duration value exceeds the value
2002  *     produced by {@link ANeuralNetworks_getMaximumLoopTimeout}, it will be
2003  *     overridden by that value.
2004  *
2005  * @return ANEURALNETWORKS_NO_ERROR if successful.
2006  *         ANEURALNETWORKS_BAD_STATE if execution has started.
2007  *         ANEURALNETWORKS_UNEXPECTED_NULL if execution is NULL.
2008  *
2009  * Available since NNAPI feature level 4.
2010  * @deprecated NNAPI is deprecated. See
2011  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2012  *   for more details.
2013  */
2014 int ANeuralNetworksExecution_setLoopTimeout(ANeuralNetworksExecution* execution, uint64_t duration)
2015         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
2016 
2017 /**
2018  * Get the default timeout value for WHILE loops.
2019  *
2020  * @return The default timeout value in nanoseconds.
2021  *
2022  * Available since NNAPI feature level 4.
2023  * @deprecated NNAPI is deprecated. See
2024  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2025  *   for more details.
2026  */
2027 uint64_t ANeuralNetworks_getDefaultLoopTimeout() __NNAPI_INTRODUCED_IN(30)
2028         __NNAPI_DEPRECATED_IN(35);
2029 
2030 /**
2031  * Get the maximum timeout value for WHILE loops.
2032  *
2033  * @return The maximum timeout value in nanoseconds.
2034  *
2035  * Available since NNAPI feature level 4.
2036  * @deprecated NNAPI is deprecated. See
2037  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2038  *   for more details.
2039  */
2040 uint64_t ANeuralNetworks_getMaximumLoopTimeout() __NNAPI_INTRODUCED_IN(30)
2041         __NNAPI_DEPRECATED_IN(35);
2042 
2043 /**
2044  * Waits until the execution completes.
2045  *
2046  * More than one thread can wait on an event. When the execution completes,
2047  * all threads will be released.
2048  *
2049  * If {@link ANeuralNetworksExecution_setTimeout} was called on the execution
2050  * corresponding to this event, and the execution is not able to complete
2051  * before the duration is exceeded, the execution may be aborted, in which case
2052  * ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be returned here.
2053  *
2054  * If the execution contains a {@link ANEURALNETWORKS_WHILE} operation, and
2055  * the condition model does not output false within the loop timeout duration,
2056  * the execution will be aborted, and ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}
2057  * will be returned here.
2058  *
2059  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
2060  *
2061  * Available since NNAPI feature level 1.
2062  *
2063  * @param event The event that will be signaled on completion.
2064  * @return ANEURALNETWORKS_NO_ERROR if the execution completed normally.
2065  *         ANEURALNETWORKS_UNMAPPABLE if the execution input or output memory cannot
2066  *         be properly mapped.
2067  * @deprecated NNAPI is deprecated. See
2068  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2069  *   for more details.
2070  */
2071 int ANeuralNetworksEvent_wait(ANeuralNetworksEvent* event) __NNAPI_INTRODUCED_IN(27)
2072         __NNAPI_DEPRECATED_IN(35);
2073 
2074 /**
2075  * Destroys the event.
2076  *
2077  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
2078  *
2079  * Available since NNAPI feature level 1.
2080  *
2081  * @param event The event object to be destroyed. Passing NULL is acceptable and
2082  *              results in no operation.
2083  * @deprecated NNAPI is deprecated. See
2084  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2085  *   for more details.
2086  */
2087 void ANeuralNetworksEvent_free(ANeuralNetworksEvent* event) __NNAPI_INTRODUCED_IN(27)
2088         __NNAPI_DEPRECATED_IN(35);
2089 
2090 /**
2091  * Create a {@link ANeuralNetworksEvent} from a sync_fence file descriptor.
2092  *
2093  * The newly created ANeuralNetworksEvent does not take ownership of the provided sync_fence_fd,
2094  * it will instead dup the provided sync_fence_fd and own the duplicate.
2095  *
2096  * @param sync_fence_fd The sync_fence file descriptor.
2097  * @param event The newly created object or NULL if unsuccessful.
2098  *
2099  * @return ANEURALNETWORKS_NO_ERROR if successful.
2100  *
2101  * Available since NNAPI feature level 4.
2102  * @deprecated NNAPI is deprecated. See
2103  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2104  *   for more details.
2105  */
2106 int ANeuralNetworksEvent_createFromSyncFenceFd(int sync_fence_fd, ANeuralNetworksEvent** event)
2107         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
2108 
2109 /**
2110  * Get sync_fence file descriptor from the event.
2111  *
2112  * If the ANeuralNetworksEvent is not backed by a sync fence, the sync_fence_fd
2113  * will be set to -1, and ANEURALNETWORKS_BAD_DATA will be returned.
2114  *
2115  * See {@link ANeuralNetworksEvent_createFromSyncFenceFd} and
2116  * {@link ANeuralNetworksExecution_startComputeWithDependencies} to see how to create
2117  * an event backed by a sync fence.
2118  *
2119  * The user takes ownership of the returned fd, and must close the returned file descriptor when
2120  * it is no longer needed.
2121  *
2122  * @param event An event that is backed by a sync fence.
2123  * @param sync_fence_fd The sync_fence file descriptor. The file descriptor will
2124  *                      be set to -1 if there is an error.
2125  *
2126  * @return ANEURALNETWORKS_NO_ERROR if successful.
2127  *
2128  * Available since NNAPI feature level 4.
2129  * @deprecated NNAPI is deprecated. See
2130  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2131  *   for more details.
2132  */
2133 int ANeuralNetworksEvent_getSyncFenceFd(const ANeuralNetworksEvent* event, int* sync_fence_fd)
2134         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
2135 
2136 /**
2137  * Schedule asynchronous evaluation of the execution with dependencies.
2138  *
2139  * The execution will wait for all the depending events to be signaled before
2140  * starting the evaluation. Once the execution has completed and the outputs
2141  * are ready to be consumed, the returned event will be signaled. Depending on which
2142  * devices are handling the execution, the event could be backed by a sync fence.
2143  * Use {@link ANeuralNetworksEvent_wait} to wait for that event.
2144  *
2145  * ANeuralNetworksEvent_wait must be called to recurperate the resources used
2146  * by the execution.
2147  *
2148  * If parts of the execution are scheduled on devices that do not support fenced execution,
2149  * the function call may wait for such parts to finish before returning.
2150  *
2151  * The function will return an error if any of the events in dependencies is already in a bad
2152  * state. After the execution is scheduled, if any of the events in dependencies does not complete
2153  * normally, the execution will fail, and {@link ANeuralNetworksEvent_wait} on the returned
2154  * event will return an error.
2155  *
2156  * The function will return an error if any of the execution outputs has a tensor operand type
2157  * that is not fully specified.
2158  *
2159  * The function can be passed a timeout duration in nanoseconds. This timeout
2160  * duration acts as a hint to drivers in the same way that the timeout durations
2161  * in {@link ANeuralNetworksCompilation_setTimeout} and {@link
2162  * ANeuralNetworksExecution_setTimeout} act as hints to drivers. The duration
2163  * begins when all waitFor sync fences have been signaled, and can be used
2164  * together with {@link ANeuralNetworksExecution_setTimeout} which specifies the
2165  * maximum timeout duration beginning at the call to
2166  * {@link ANeuralNetworksExecution_startComputeWithDependencies}.
2167  * If the duration is non-zero, the {@link ANeuralNetworksExecution} must have been created
2168  * from an {@link ANeuralNetworksCompilation} which in turn was created from
2169  * {@link ANeuralNetworksCompilation_createForDevices} with numDevices = 1,
2170  * otherwise this function will fail with ANEURALNETWORKS_BAD_DATA. If either
2171  * the timeout duration from {@link ANeuralNetworksExecution_setTimeout} or the
2172  * timeout duration passed to this call is exceeded, the execution may be
2173  * aborted, in which case ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode} will be
2174  * returned through {@link ANeuralNetworksExecution_startComputeWithDependencies}
2175  * or {@link ANeuralNetworksEvent_wait} on the event object. If the device has a
2176  * feature level reported by {@link ANeuralNetworksDevice_getFeatureLevel} that
2177  * is lower than {@link ANEURALNETWORKS_FEATURE_LEVEL_4}, then the timeout duration
2178  * hints will be ignored.
2179  *
2180  * If this execution contains a {@link ANEURALNETWORKS_WHILE} operation, and
2181  * the condition model does not output false within the loop timeout duration,
2182  * then execution will be aborted and ANEURALNETWORKS_MISSED_DEADLINE_* {@link ResultCode}
2183  * will be returned through {@link ANeuralNetworksEvent_wait} on the event
2184  * object.
2185  *
2186  * Before NNAPI feature level 5, this function may only be invoked when the execution is in the
2187  * preparation state. Starting at NNAPI feature level 5, if the user sets the execution to be
2188  * reusable by {@link ANeuralNetworksExecution_setReusable}, this function may also be invoked when
2189  * the execution is in the completed state.
2190  *
2191  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
2192  *
2193  * See {@link ANeuralNetworksExecution_compute} for synchronous execution.
2194  * See {@link ANeuralNetworksExecution_burstCompute} for burst synchronous execution.
2195  * See {@link ANeuralNetworksExecution_startCompute} for regular asynchronous execution.
2196  *
2197  * @param execution The execution to be scheduled and executed.
2198  * @param dependencies A set of depending events. The actual evaluation will not start
2199  *                     until all the events are signaled.
2200  * @param num_dependencies The number of events in the dependencies set.
2201  * @param duration The maximum amount of time in nanoseconds that is expected to
2202  *                 be spent executing the model after all dependencies are
2203  *                 signaled. If set to 0, the timeout duration is considered
2204  *                 infinite.
2205  * @param event The event that will be signaled on completion. event is set to
2206  *              NULL if there's an error.
2207  *
2208  * @return ANEURALNETWORKS_NO_ERROR if the evaluation is successfully scheduled.
2209  *
2210  * Available since NNAPI feature level 4.
2211  * @deprecated NNAPI is deprecated. See
2212  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2213  *   for more details.
2214  */
2215 int ANeuralNetworksExecution_startComputeWithDependencies(
2216         ANeuralNetworksExecution* execution, const ANeuralNetworksEvent* const* dependencies,
2217         uint32_t num_dependencies, uint64_t duration, ANeuralNetworksEvent** event)
2218         __NNAPI_INTRODUCED_IN(30) __NNAPI_DEPRECATED_IN(35);
2219 
2220 /**
2221  * Get the NNAPI runtime feature level.
2222  *
2223  * Since API level 31 (NNAPI feature level 5), the NNAPI runtime (libneuralnetworks.so) and its
2224  * API specification can be updated between Android API releases.
2225  *
2226  * On Android devices with API level 31 and newer, for NNAPI runtime feature discovery,
2227  * the NNAPI runtime feature level must be used instead of the Android device API level.
2228  *
2229  * On Android devices with API level 30 and older, the Android API level of the Android
2230  * device must be used for NNAPI runtime feature discovery. Enum values in
2231  * {@link FeatureLevelCode} from feature level 1 to 5 have their corresponding Android
2232  * API levels listed in their documentation, and each such enum value equals the corresponding
2233  * API level. This allows using the Android API level as the feature level.
2234  * This mapping between enum value and Android API level does not exist for feature levels
2235  * after NNAPI feature level 5 and API levels after S (31).
2236  *
2237  * Example usage:
2238  * int device_api_level = android_get_device_api_level();
2239  * int64_t runtime_feature_level = (device_api_level < __ANDROID_API_S__) ?
2240  *                                  device_api_level : ANeuralNetworks_getRuntimeFeatureLevel();
2241  *
2242  * Runtime feature level is closely related to NNAPI device feature level
2243  * ({@link ANeuralNetworksDevice_getFeatureLevel}), which indicates an NNAPI device feature level
2244  * (the most advanced NNAPI specification and features that the driver implements).
2245  * This function expresses NNAPI runtime feature level, which indicates the most advanced
2246  * NNAPI specification and features the runtime implements. An NNAPI device feature level is
2247  * always less than or equal to the runtime feature level.
2248  *
2249  * This function returns a {@link FeatureLevelCode} enum value,
2250  * which is the NNAPI specification version that this NNAPI runtime implements.
2251  * It is NOT an Android API level.
2252  *
2253  * Available since NNAPI feature level 5.
2254  * @deprecated NNAPI is deprecated. See
2255  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2256  *   for more details.
2257  */
2258 int64_t ANeuralNetworks_getRuntimeFeatureLevel() __NNAPI_INTRODUCED_IN(31)
2259         __NNAPI_DEPRECATED_IN(35);
2260 
2261 /**
2262  * Specifies whether the {@link ANeuralNetworksExecution} is able to accept padded input and output
2263  * buffers and memory objects.
2264  *
2265  * By default, the input and output buffers and memory objects of {@link ANeuralNetworksExecution}
2266  * do not allow padding.
2267  *
2268  * Setting the execution to accept padded input and output buffers and memory objects enables the
2269  * length argument of {@link ANeuralNetworksExecution_setInput},
2270  * {@link ANeuralNetworksExecution_setInputFromMemory}, {@link ANeuralNetworksExecution_setOutput},
2271  * and {@link ANeuralNetworksExecution_setOutputFromMemory} to be greater than the raw size of the
2272  * operand (i.e. the size of an element multiplied by the number of elements). The extra bytes
2273  * at the end of the buffer or memory region may be used by the driver to access data in chunks,
2274  * for efficiency.
2275  *
2276  * This method must not be called after {@link ANeuralNetworksExecution_setInput},
2277  * {@link ANeuralNetworksExecution_setInputFromMemory}, {@link ANeuralNetworksExecution_setOutput},
2278  * or {@link ANeuralNetworksExecution_setOutputFromMemory}.
2279  *
2280  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
2281  *
2282  * @param execution The execution to be modified.
2283  * @param enable 'true' if the execution is to be able to accept padded input and output buffers
2284  *               and memory objects, 'false' if not.
2285  *
2286  * @return ANEURALNETWORKS_NO_ERROR if successful.
2287  *         ANEURALNETWORKS_UNEXPECTED_NULL if execution is NULL.
2288  *         ANEURALNETWORKS_BAD_STATE if {@link ANeuralNetworksExecution_setInput},
2289  *         {@link ANeuralNetworksExecution_setInputFromMemory},
2290  *         {@link ANeuralNetworksExecution_setOutput}, or
2291  *         {@link ANeuralNetworksExecution_setOutputFromMemory} has been called on the execution.
2292  *
2293  * Available since NNAPI feature level 5.
2294  * @deprecated NNAPI is deprecated. See
2295  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2296  *   for more details.
2297  */
2298 int ANeuralNetworksExecution_enableInputAndOutputPadding(ANeuralNetworksExecution* execution,
2299                                                          bool enable) __NNAPI_INTRODUCED_IN(31)
2300         __NNAPI_DEPRECATED_IN(35);
2301 
2302 /**
2303  * Get the preferred buffer and memory alignment of an input to an execution created from a
2304  * particular compilation.
2305  *
2306  * The user may use the returned alignment value to guide the layout of the input buffer or memory
2307  * pool. To achieve the best performance, make sure the address of the buffer passed in
2308  * {@link ANeuralNetworksExecution_setInput}, or the offset value passed in
2309  * {@link ANeuralNetworksExecution_setInputFromMemory}, is a multiple of the perferred alignment
2310  * value of the same input. A driver may choose to allocate a separate buffer and do memory copying
2311  * if the provided buffer or memory does not satisfy the preferred alignment.
2312  *
2313  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
2314  *
2315  * @param compilation The compilation object. It must already have been finished by calling
2316  *                    {@link ANeuralNetworksCompilation_finish}.
2317  * @param index The index of the input argument we are referencing from the compilation. It is
2318  *              an index into the inputs list passed to
2319  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
2320  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
2321  * @param alignment The returned preferred alignment in bytes. It will be a power of 2.
2322  *
2323  * @return ANEURALNETWORKS_NO_ERROR if successful.
2324  *         ANEURALNETWORKS_UNEXPECTED_NULL if either compilation or alignment is NULL.
2325  *         ANEURALNETWORKS_BAD_STATE if the compilation has not been finished.
2326  *         ANEURALNETWORKS_BAD_DATA if the index is out of range.
2327  *
2328  * Available since NNAPI feature level 5.
2329  * @deprecated NNAPI is deprecated. See
2330  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2331  *   for more details.
2332  */
2333 int ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput(
2334         const ANeuralNetworksCompilation* compilation, uint32_t index, uint32_t* alignment)
2335         __NNAPI_INTRODUCED_IN(31) __NNAPI_DEPRECATED_IN(35);
2336 
2337 /**
2338  * Get the preferred buffer and memory end padding of an input to an execution created from a
2339  * particular compilation.
2340  *
2341  * The user may use the returned padding value to guide the layout of the input buffer or memory
2342  * pool. To achieve the best performance, make sure the length value passed in
2343  * {@link ANeuralNetworksExecution_setInput} or
2344  * {@link ANeuralNetworksExecution_setInputFromMemory} is greater than or equal to the raw size of
2345  * the input (i.e. the size of an element multiplied by the number of elements) rounding up to
2346  * a multiple of the perferred padding value of the same input. A driver may choose to allocate a
2347  * separate buffer and do memory copying if the provided buffer or memory value does not satisfy
2348  * the preferred padding.
2349  *
2350  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
2351  * See {@link ANeuralNetworksExecution_enableInputAndOutputPadding},
2352  * {@link ANeuralNetworksExecution_setInput}, and
2353  * {@link ANeuralNetworksExecution_setInputFromMemory} for information on passing
2354  * input buffer or memory padding to the driver.
2355  *
2356  * @param compilation The compilation object. It must already have been finished by calling
2357  *                    {@link ANeuralNetworksCompilation_finish}.
2358  * @param index The index of the input argument we are referencing from the compilation. It is
2359  *              an index into the inputs list passed to
2360  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
2361  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
2362  * @param padding The returned preferred padding in bytes. It will be a power of 2.
2363  *
2364  * @return ANEURALNETWORKS_NO_ERROR if successful.
2365  *         ANEURALNETWORKS_UNEXPECTED_NULL if either compilation or padding is NULL.
2366  *         ANEURALNETWORKS_BAD_STATE if the compilation has not been finished.
2367  *         ANEURALNETWORKS_BAD_DATA if the index is out of range.
2368  *
2369  * Available since NNAPI feature level 5.
2370  * @deprecated NNAPI is deprecated. See
2371  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2372  *   for more details.
2373  */
2374 int ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput(
2375         const ANeuralNetworksCompilation* compilation, uint32_t index, uint32_t* padding)
2376         __NNAPI_INTRODUCED_IN(31) __NNAPI_DEPRECATED_IN(35);
2377 
2378 /**
2379  * Get the preferred buffer and memory alignment of an output to an execution created from a
2380  * particular compilation.
2381  *
2382  * The user may use the returned alignment value to guide the layout of the output buffer or memory
2383  * pool. To achieve the best performance, make sure the address of the buffer passed in
2384  * {@link ANeuralNetworksExecution_setOutput}, or the offset value passed in
2385  * {@link ANeuralNetworksExecution_setOutputFromMemory}, is a multiple of the perferred alignment
2386  * value of the same output. A driver may choose to allocate a separate buffer and do memory copying
2387  * if the provided buffer or memory does not satisfy the preferred alignment.
2388  *
2389  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
2390  *
2391  * @param compilation The compilation object. It must already have been finished by calling
2392  *                    {@link ANeuralNetworksCompilation_finish}.
2393  * @param index The index of the output argument we are referencing from the compilation. It is
2394  *              an index into the outputs list passed to
2395  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
2396  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
2397  * @param alignment The returned perferred alignment in bytes. It will be a power of 2.
2398  *
2399  * @return ANEURALNETWORKS_NO_ERROR if successful.
2400  *         ANEURALNETWORKS_UNEXPECTED_NULL if either compilation or alignment is NULL.
2401  *         ANEURALNETWORKS_BAD_STATE if the compilation has not been finished.
2402  *         ANEURALNETWORKS_BAD_DATA if the index is out of range.
2403  *
2404  * Available since NNAPI feature level 5.
2405  * @deprecated NNAPI is deprecated. See
2406  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2407  *   for more details.
2408  */
2409 int ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput(
2410         const ANeuralNetworksCompilation* compilation, uint32_t index, uint32_t* alignment)
2411         __NNAPI_INTRODUCED_IN(31) __NNAPI_DEPRECATED_IN(35);
2412 
2413 /**
2414  * Get the preferred memory end padding of an output to an execution created from a particular
2415  * compilation.
2416  *
2417  * The user may use the returned padding value to guide the layout of the output buffer or memory
2418  * pool. To achieve the best performance, make sure the length value passed in
2419  * {@link ANeuralNetworksExecution_setOutput} or
2420  * {@link ANeuralNetworksExecution_setOutputFromMemory} is greater than or equal to the raw size of
2421  * the output (i.e. the size of an element multiplied by the number of elements) rounding up to
2422  * a multiple of the perferred padding value of the same output. A driver may choose to allocate a
2423  * separate buffer and do memory copying if the provided buffer or memory value does not satisfy
2424  * the preferred padding.
2425  *
2426  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
2427  * See {@link ANeuralNetworksExecution_enableInputAndOutputPadding},
2428  * {@link ANeuralNetworksExecution_setOutput}, and
2429  * {@link ANeuralNetworksExecution_setOutputFromMemory} for information on passing
2430  * output buffer or memory padding to the driver.
2431  *
2432  * @param compilation The compilation object. It must already have been finished by calling
2433  *                    {@link ANeuralNetworksCompilation_finish}.
2434  * @param index The index of the output argument we are referencing from the compilation. It is
2435  *              an index into the outputs list passed to
2436  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
2437  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
2438  * @param padding The returned perferred padding in bytes. It will be a power of 2.
2439  *
2440  * @return ANEURALNETWORKS_NO_ERROR if successful.
2441  *         ANEURALNETWORKS_UNEXPECTED_NULL if either compilation or padding is NULL.
2442  *         ANEURALNETWORKS_BAD_STATE if the compilation has not been finished.
2443  *         ANEURALNETWORKS_BAD_DATA if the index is out of range.
2444  *
2445  * Available since NNAPI feature level 5.
2446  * @deprecated NNAPI is deprecated. See
2447  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2448  *   for more details.
2449  */
2450 int ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput(
2451         const ANeuralNetworksCompilation* compilation, uint32_t index, uint32_t* padding)
2452         __NNAPI_INTRODUCED_IN(31) __NNAPI_DEPRECATED_IN(35);
2453 
2454 /**
2455  * Specifies whether the {@link ANeuralNetworksExecution} can be reused for multiple computations.
2456  *
2457  * By default, the {@link ANeuralNetworksExecution} is not reusable.
2458  *
2459  * Setting the execution to be reusable enables multiple computations to be scheduled and evaluated
2460  * on the same execution sequentially, either by means of
2461  * {@link ANeuralNetworksExecution_burstCompute}, {@link ANeuralNetworksExecution_compute},
2462  * {@link ANeuralNetworksExecution_startCompute} or
2463  * {@link ANeuralNetworksExecution_startComputeWithDependencies}: The application may schedule and
2464  * evaluate a computation again from the completed state of a reusable execution.
2465  *
2466  * This function may only be invoked when the execution is in the preparation state.
2467  *
2468  * See {@link ANeuralNetworksExecution} for information on execution states and multithreaded usage.
2469  *
2470  * @param execution The execution to be modified.
2471  * @param reusable 'true' if the execution is to be reusable, 'false' if not.
2472  *
2473  * @return ANEURALNETWORKS_NO_ERROR if successful.
2474  *         ANEURALNETWORKS_UNEXPECTED_NULL if execution is NULL.
2475  *         ANEURALNETWORKS_BAD_STATE if the execution is not in the preparation state.
2476  *
2477  * Available since NNAPI feature level 5.
2478  * @deprecated NNAPI is deprecated. See
2479  *   <a href="https://developer.android.com/ndk/guides/neuralnetworks">this webpage</a>
2480  *   for more details.
2481  */
2482 int ANeuralNetworksExecution_setReusable(ANeuralNetworksExecution* execution, bool reusable)
2483         __NNAPI_INTRODUCED_IN(31) __NNAPI_DEPRECATED_IN(35);
2484 
2485 __END_DECLS
2486 
2487 #endif  // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_NEURAL_NETWORKS_H
2488 
2489 #undef __NNAPI_INTRODUCED_IN
2490 
2491 /** @} */
2492