• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ML_NN_RUNTIME_NEURAL_NETWORKS_H
27 #define ANDROID_ML_NN_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 #if __ANDROID_API__ >= __ANDROID_API_O_MR1__
46 
47 #include <stddef.h>
48 #include <stdint.h>
49 #include <sys/cdefs.h>
50 
51 __BEGIN_DECLS
52 
53 /**
54  * Operand types.
55  *
56  * The type of operands that can be added to a model.
57  *
58  * Although we define many types, most operators accept just a few
59  * types. Most used are {@link ANEURALNETWORKS_TENSOR_FLOAT32},
60  * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM},
61  * and {@link ANEURALNETWORKS_INT32}.
62  */
63 typedef enum {
64     /** The following entries are used to declare scalars. */
65 
66     /** A 32 bit floating point scalar value. */
67     ANEURALNETWORKS_FLOAT32 = 0,
68     /** A signed 32 bit integer scalar value. */
69     ANEURALNETWORKS_INT32 = 1,
70     /** An unsigned 32 bit integer scalar value. */
71     ANEURALNETWORKS_UINT32 = 2,
72 
73     /** The following entries are used to declare tensors. */
74 
75     /** A tensor of 32 bit floating point values. */
76     ANEURALNETWORKS_TENSOR_FLOAT32 = 3,
77     /** A tensor of 32 bit integer values. */
78     ANEURALNETWORKS_TENSOR_INT32 = 4,
79     /** A tensor of 8 bit integers that represent real numbers.
80      *
81      * Attached to this tensor are two numbers that can be used to convert
82      * the 8 bit integer to the real value and vice versa.  These two numbers are:
83      * - scale: a 32 bit non-negative floating point value.
84      * - zeroPoint: an 32 bit integer, in range [0, 255].
85      *
86      * The formula is:
87      * real_value = (integer_value - zeroPoint) * scale.
88      */
89     ANEURALNETWORKS_TENSOR_QUANT8_ASYMM = 5,
90 } OperandCode;
91 
92 /**
93  * Operation types.
94  *
95  * The type of operations that can be added to a model.
96  */
97 typedef enum {
98     /** Adds two tensors, element-wise.
99      *
100      * Takes two input tensors of identical type and compatible dimensions. The output
101      * is the sum of both input tensors, optionally modified by an activation function.
102      *
103      * Two dimensions are compatible when:
104      *     1. they are equal, or
105      *     2. one of them is 1
106      *
107      * The size of the output is the maximum size along each dimension of the input operands.
108      * It starts with the trailing dimensions, and works its way forward.
109      *
110      * Example:
111      *
112      *     input1.dimension = {4, 1, 2}
113      *     input2.dimension = {5, 4, 3, 1}
114      *     output.dimension = {5, 4, 3, 2}
115      *
116      * Supported tensor types:
117      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
118      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
119      *
120      * Supported tensor rank: up to 4
121      *
122      * Inputs:
123      * * 0: A tensor.
124      * * 1: A tensor of the same type, and compatible dimensions as input0.
125      * * 2: An INT32 value, and has to be one of the {@link FuseCode} values.
126      *      Specifies the activation to invoke on the result of each addition.
127      *
128      * Outputs:
129      * * 0: The sum, a tensor of the same type as input0.
130      */
131     ANEURALNETWORKS_ADD = 0,
132 
133     /** Performs a 2-D average pooling operation.
134      *
135      * The output dimensions are functions of the filter dimensions, stride, and padding.
136      *
137      * The values in the output tensor are computed as:
138      *
139      *     output[batch, row, col, channel] =
140      *         sum_{i, j}(input[batch, row + i, col + j, channel]) / sum(1)
141      *
142      * Supported tensor types:
143      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
144      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
145      *
146      * Supported tensor rank: 4, with "NHWC" (i.e., Num_samples, Height, Width, and Channels)
147      * data layout.
148      *
149      * Both explicit padding and implicit padding are supported.
150      *
151      * Inputs (explicit padding):
152      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
153      * * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
154      * * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
155      * * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
156      * * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
157      * * 5: An INT32 value, specifying the stride when walking through input
158      *      in the ‘width’ dimension.
159      * * 6: An INT32 value, specifying the stride when walking through input
160      *      in the ‘height’ dimension.
161      * * 7: An INT32 value, specifying the filter width.
162      * * 8: An INT32 value, specifying the filter height.
163      * * 9: An INT32 value, and has to be one of the {@link FuseCode} values.
164      *      Specifies the activation to invoke on the result of each addition.
165      *
166      * Inputs (implicit padding):
167      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
168      * * 1: An INT32 value, specifying the implicit padding scheme, has to be one of the
169      *      {@link PaddingCode} values.
170      * * 2: An INT32 value, specifying the stride when walking through input
171      *      in the ‘width’ dimension.
172      * * 3: An INT32 value, specifying the stride when walking through input
173      *      in the ‘height’ dimension.
174      * * 4: An INT32 value, specifying the filter width.
175      * * 5: An INT32 value, specifying the filter height.
176      * * 6: An INT32 value, and has to be one of the {@link FuseCode} values.
177      *      Specifies the activation to invoke on the result of each addition.
178      *
179      * Outputs:
180      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
181      */
182     ANEURALNETWORKS_AVERAGE_POOL_2D = 1,
183 
184     /** Concatenates the input tensors along the given dimension.
185      *
186      * The input tensors must have identical type and the same dimensions except the
187      * dimension along the concatenation axis.
188      *
189      * Supported tensor types:
190      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
191      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
192      *
193      * Supported tensor rank: up to 4
194      *
195      * Inputs:
196      * * 0 ~ n-1: The list of n input tensors, of shape [D0, D1, ..., Daxis(i), ..., Dm].
197      *            For inputs of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, all
198      *            input tensors must have the same scale and zeroPoint.
199      * * n: An INT32 value, specifying the concatenation axis.
200      *
201      * Outputs:
202      * * 0: The output, a tensor of the same type as the input tensors.
203      *      The output shape is [D0, D1, ..., sum(Daxis(i)), ..., Dm].
204      */
205     ANEURALNETWORKS_CONCATENATION = 2,
206 
207     /** Performs an 2-D convolution operation.
208      *
209      * The CONV_2D op sweeps a 2-D filter that can mix channels together over a batch of
210      * images, applying the filter to each window of each image of the appropriate size.
211      *
212      * The output dimensions are functions of the filter dimensions, stride, and padding.
213      *
214      * The values in the output tensor are computed as:
215      *
216      *     output[batch, row, col, channel] =
217      *         sum_{i, j} (
218      *             input[batch, row + i, col + j, k] *
219      *             filter[channel, row + i, col + j, k] +
220      *             bias[channel]
221      *         )
222      *
223      * Supported tensor types:
224      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
225      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
226      *
227      * Supported tensor rank: 4, with "NHWC" data layout.
228      *
229      * Both explicit padding and implicit padding are supported.
230      *
231      * Inputs (explicit padding):
232      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
233      * * 1: A 4-D tensor, of shape [depth_out, filter_height, filter_width, depth_in],
234      *      specifying the filter.
235      * * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
236      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_FLOAT32} type, the bias should
237      *      also be of {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
238      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the bias
239      *      should be of {@link ANEURALNETWORKS_TENSOR_INT32}, with zeroPoint of 0 and
240      *      bias_scale == input_scale * filter_scale.
241      * * 3: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
242      * * 4: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
243      * * 5: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
244      * * 6: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
245      * * 7: An INT32 value, specifying the stride when walking through input
246      *      in the ‘width’ dimension.
247      * * 8: An INT32 value, specifying the stride when walking through input
248      *      in the ‘height’ dimension.
249      * * 9: An INT32 value, and has to be one of the {@link FuseCode} values.
250      *      Specifies the activation to invoke on the result of each addition.
251      *
252      * Inputs (implicit padding):
253      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
254      * * 1: A 4-D tensor, of shape [depth_out, filter_height, filter_width, depth_in],
255      *      specifying the filter.
256      * * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
257      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_FLOAT32} type, the bias should
258      *      also be of {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
259      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the bias
260      *      should be of {@link ANEURALNETWORKS_TENSOR_INT32}, with zeroPoint of 0 and
261      *      bias_scale == input_scale * filter_scale.
262      * * 3: An INT32 value, specifying the implicit padding scheme, has to be one of the
263      *      {@link PaddingCode} values.
264      * * 4: An INT32 value, specifying the stride when walking through input
265      *      in the ‘width’ dimension.
266      * * 5: An INT32 value, specifying the stride when walking through input
267      *      in the ‘height’ dimension.
268      * * 6: An INT32 value, and has to be one of the {@link FuseCode} values.
269      *      Specifies the activation to invoke on the result of each addition.
270      *
271      * Outputs:
272      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
273      *      For output tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the following
274      *      condition must be satisfied: output_scale > input_scale * filter_scale.
275      */
276     ANEURALNETWORKS_CONV_2D = 3,
277 
278     /** Performs a depthwise 2-D convolution operation.
279      *
280      * Given an input tensor of shape [batches, height, width, depth_in] and a filter
281      * tensor of shape [1, filter_height, filter_width, depth_out] containing
282      * depth_out convolutional filters of depth 1, DEPTHWISE_CONV applies a different
283      * filter to each input channel (expanding from 1 channel to channel_multiplier channels
284      * for each), then concatenates the results together.
285      *
286      * The output has depth_out = depth_in * depth_multiplier channels.
287      * The output dimensions are functions of the filter dimensions, stride, and padding.
288      *
289      * The values in the output tensor are computed as:
290      *
291      *     output[b, i, j, k * channel_multiplier + q] =
292      *         sum_{di, dj} (
293      *             input[b, strides[1] * i + di, strides[2] * j + dj, k] *
294      *             filter[1, di, dj, k * channel_multiplier + q]
295      *         )
296      *
297      * Supported tensor types:
298      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
299      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
300      *
301      * Supported tensor rank: 4, with "NHWC" data layout.
302      *
303      * Both explicit padding and implicit padding are supported.
304      *
305      * Inputs (explicit padding):
306      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
307      * * 1: A 4-D tensor, of shape [1, filter_height, filter_width, depth_out],
308      *      specifying the filter.
309      * * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
310      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_FLOAT32} type, the bias should
311      *      also be of {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
312      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the bias
313      *      should be of {@link ANEURALNETWORKS_TENSOR_INT32}, with zeroPoint of 0 and
314      *      bias_scale == input_scale * filter_scale.
315      * * 3: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
316      * * 4: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
317      * * 5: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
318      * * 6: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
319      * * 7: An INT32 value, specifying the stride when walking through input
320      *      in the ‘width’ dimension.
321      * * 8: An INT32 value, specifying the stride when walking through input
322      *      in the ‘height’ dimension.
323      * * 9: An INT32 value, specifying the depthwise multiplier.
324      * * 10: An INT32 value, and has to be one of the {@link FuseCode} values.
325      *       Specifies the activation to invoke on the result of each addition.
326      *
327      * Inputs (explicit padding):
328      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
329      * * 1: A 4-D tensor, of shape [1, filter_height, filter_width, depth_out],
330      *      specifying the filter.
331      * * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
332      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_FLOAT32} type, the bias should
333      *      also be of {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
334      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the bias
335      *      should be of {@link ANEURALNETWORKS_TENSOR_INT32}, with zeroPoint of 0 and
336      *      bias_scale == input_scale * filter_scale.
337      * * 3: An INT32 value, specifying the implicit padding scheme, has to be one of the
338      *      {@link PaddingCode} values.
339      * * 4: An INT32 value, specifying the stride when walking through input
340      *      in the ‘width’ dimension.
341      * * 5: An INT32 value, specifying the stride when walking through input
342      *      in the ‘height’ dimension.
343      * * 6: An INT32 value, specifying the depthwise multiplier.
344      * * 7: An INT32 value, and has to be one of the {@link FuseCode} values.
345      *       Specifies the activation to invoke on the result of each addition.
346      *
347      * Outputs:
348      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
349      *      For output tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the following
350      *      condition must be satisfied: output_scale > input_scale * filter_scale.
351      */
352     ANEURALNETWORKS_DEPTHWISE_CONV_2D = 4,
353 
354     /** Rearranges data from depth into blocks of spatial data.
355      *
356      * More specifically, this op outputs a copy of the input tensor where values from
357      * the depth dimension are moved in spatial blocks to the height and width dimensions.
358      * The value block_size indicates the input block size and how the data is moved.
359      *
360      * Chunks of data of size block_size * block_size from depth are rearranged into
361      * non-overlapping blocks of size block_size x block_size.
362      *
363      * The width of the output tensor is input_depth * block_size, whereas the height is
364      * input_height * block_size.
365      * The depth of the input tensor must be divisible by block_size * block_size
366      *
367      * Supported tensor types:
368      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
369      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
370      *
371      * Supported tensor rank: 4, with "NHWC" data layout.
372      *
373      * Inputs:
374      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
375      * * 1: An INT32 value, specifying the block_size. block_size must be >=1 and
376      *      block_size * block_size must be a divisor of the input depth.
377      *
378      * Outputs:
379      * * 0: The output 4-D tensor, of shape [batch, height*block_size, width*block_size,
380      *      depth/(block_size*block_size)].
381      */
382     ANEURALNETWORKS_DEPTH_TO_SPACE = 5,
383 
384     /** Dequantizes the input tensor.
385      *
386      * The formula is:
387      *
388      *     output = (input - zeroPoint) * scale.
389      *
390      * Supported tensor types:
391      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
392      *
393      * Supported tensor rank: up to 4
394      *
395      * Inputs:
396      * * 0: A tensor of type {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}.
397      *
398      * Outputs:
399      * * 0: The output tensor of same shape as input0, but with type
400      *      {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
401      */
402     ANEURALNETWORKS_DEQUANTIZE = 6,
403 
404     /** Looks up sub-tensors in the input tensor.
405      *
406      * This operator takes for input a tensor of values (Values) and
407      * a one-dimensional tensor of selection indices (Lookups).
408      * The output tensor is the concatenation of sub-tensors of Values as
409      * selected by Lookups.
410      *
411      * Think of Values as being sliced along its first dimension:
412      * The entries in Lookups select which slices are concatenated together
413      * to create the output tensor.
414      *
415      * For example, if Values has shape of [40, 200, 300] and
416      * Lookups has shape of [3], we would expect all three values
417      * found in Lookups to be  between 0 and 39. The resulting tensor will
418      * have shape of [3, 200, 300].
419      *
420      * If a value in Lookups is out of bounds, the operation will fail
421      * and an error will be reported.
422      *
423      * Inputs:
424      * * 0: Lookups. A 1-D tensor of {@link ANEURALNETWORKS_TENSOR_INT32} type.
425      *      The values are indices into the first dimension of Values.
426      * * 1: Values. An n-D tensor, where n >= 2, from which sub-tensors are
427      *      extracted.
428      *
429      * Output:
430      * * 0: A n-D tensor with the same rank and shape as the Values
431      *      tensor, except for the first dimension which has the same size
432      *      as Lookups' only dimension.
433      */
434     ANEURALNETWORKS_EMBEDDING_LOOKUP = 7,
435 
436     /** Computes element-wise floor() on the input tensor.
437      *
438      * Supported tensor types:
439      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
440      *
441      * Supported tensor rank: up to 4
442      *
443      * Inputs:
444      * * 0: A tensor.
445      *
446      * Outputs:
447      * * 0: The output tensor, of the same type and dimensions as the input tensor.
448      */
449     ANEURALNETWORKS_FLOOR = 8,
450 
451     /** Denotes a fully (densely) connected layer, which connects all elements in the input
452      * tensor with each element in the output tensor.
453      *
454      * This layer implements the operation:
455      *
456      *     outputs = activation(inputs * weights’ + bias)
457      *
458      * Supported tensor types:
459      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
460      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
461      *
462      * Supported tensor rank: up to 4.
463      *
464      * Inputs:
465      * * 0: A tensor, specifying the input. If rank is greater than 2, then it gets flattened to
466      *      a 2-D Tensor. The 2-D Tensor is handled as if dimensions corresponded to shape
467      *      [batch_size, input_size], where “batch_size” corresponds to the batching dimension,
468      *      and “input_size” is the size of the input.
469      * * 1: A 2-D tensor, specifying the weights, of shape [num_units, input_size], where
470      *      "num_units" corresponds to the number of output nodes.
471      * * 2: A 1-D tensor, of shape [num_units], specifying the bias.
472      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_FLOAT32} type, the bias should
473      *      also be of {@link ANEURALNETWORKS_TENSOR_FLOAT32}.
474      *      For input tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the bias
475      *      should be of {@link ANEURALNETWORKS_TENSOR_INT32}, with zeroPoint of 0 and
476      *      bias_scale == input_scale * filter_scale.
477      * * 3: An INT32 value, and has to be one of the {@link FuseCode} values.
478      *      Specifies the activation to invoke on the result of each addition.
479      *
480      * Outputs:
481      * * 0: The output tensor, of shape [batch_size, num_units].
482      *      For output tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the following
483      *      condition must be satisfied: output_scale > input_scale * filter_scale.
484      */
485     ANEURALNETWORKS_FULLY_CONNECTED = 9,
486 
487     /** Looks up sub-tensors in the input tensor using a key-value map.
488      *
489      * This operator takes for input a tensor of values (Values),
490      * a one-dimensional tensor of selection values (Lookups) and
491      * a one-dimensional tensor that maps these values to Values
492      * indexes. The output tensor is the concatenation of sub-tensors of
493      * Values as selected by Lookups via Keys.
494      *
495      * Think of Values as being sliced along its outer-most dimension.
496      * The output is a concatenation of selected slices, with one slice
497      * for each entry of Lookups. The slice selected is the one at the
498      * same index as the Maps entry that matches the value in Lookups.
499      *
500      * For a hit, the corresponding sub-tensor of Values is included
501      * in the Output tensor.  For a miss, the corresponding sub-tensor in
502      * Output will have zero values.
503      *
504      * For example, if Values has shape of [40, 200, 300],
505      * Keys should have a shape of [40]. If Lookups tensor has shape
506      * of [3], we're concatenating three slices, so the resulting tensor
507      * will have the shape of [3, 200, 300]. If the first entry in
508      * Lookups has the value 123456, we'll look for that value in Keys tensor.
509      * If the sixth entry of Keys contains 123456, we'll select the sixth
510      * slice of Values. If no entry in Keys has 123456, a slice of zeroes
511      * will be concatenated.
512      *
513      * Inputs:
514      * * 0: Lookups. A 1-D {@link ANEURALNETWORKS_TENSOR_INT32} tensor with shape [ k ].
515      * * 1: Keys. A 1-D {@link ANEURALNETWORKS_TENSOR_INT32} tensor with shape [ n ];
516      *      Keys and Values pair represent a map, i.e., the ith element
517      *      in Keys (Keys[i]) is the key to select the ith sub-tensor
518      *      in Values (Values[i]), where 0 <= i <= n-1.
519      *      Keys tensor *MUST* be sorted in ascending order.
520      * * 2: Values. A tensor with shape of [ n, … ]; i.e., the first dimension must be n.
521      *
522      * Outputs:
523      * * 0: Output. A tensor with shape [ k …].
524      * * 1: Hits. A boolean tensor with shape [ k ] indicates whether the lookup
525      *      hits (True) or not (False).
526      *      Stored as {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} with offset 0 and scale 1.0f.
527      *      A non-zero byte represents True, a hit. A zero indicates otherwise.
528      */
529     ANEURALNETWORKS_HASHTABLE_LOOKUP = 10,
530 
531     /** Applies L2 normalization along the depth dimension.
532      *
533      * The values in the output tensor are computed as:
534      *
535      *     output[batch, row, col, channel] =
536      *         input[batch, row, col, channel] /
537      *         sqrt(sum_{c} pow(input[batch, row, col, c], 2))
538      *
539      * For input tensor with more dimensions, independently normalizes each 1-D slice along dimension dim.
540      *
541      * Supported tensor types:
542      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
543      *
544      * Supported tensor rank: 4, with "NHWC" data layout (i.e., Num_samples, Height, Width, and Channels).
545      *
546      * Inputs:
547      * * 0: A 4-D tensor, of shape [batches, height, width, depth].
548      *
549      * Outputs:
550      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
551      */
552     ANEURALNETWORKS_L2_NORMALIZATION = 11,
553 
554     /** Performs an 2-D L2 pooling operation.
555      *
556      * The output dimensions are functions of the filter dimensions, stride, and padding.
557      *
558      * The values in the output tensor are computed as:
559      *
560      *     output[batch, row, col, channel] =
561      *         sqrt(sum_{i, j} pow(input[batch, row + i, col + j, channel], 2) / sum(1))
562      *
563      * Supported tensor types:
564      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
565      *
566      * Supported tensor rank: 4, with "NHWC" data layout.
567      *
568      * Both explicit padding and implicit padding are supported.
569      *
570      * Inputs (explicit padding):
571      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
572      * * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
573      * * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
574      * * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
575      * * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
576      * * 5: An INT32 value, specifying the stride when walking through input
577      *      in the ‘width’ dimension.
578      * * 6: An INT32 value, specifying the stride when walking through input
579      *      in the ‘height’ dimension.
580      * * 7: An INT32 value, specifying the filter width.
581      * * 8: An INT32 value, specifying the filter height.
582      * * 9: An INT32 value, and has to be one of the {@link FuseCode} values.
583      *      Specifies the activation to invoke on the result of each addition.
584      *
585      * Inputs (implicit padding):
586      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
587      * * 1: An INT32 value, specifying the implicit padding scheme, has to be one of the
588      *      {@link PaddingCode} values.
589      * * 2: An INT32 value, specifying the stride when walking through input
590      *      in the ‘width’ dimension.
591      * * 3: An INT32 value, specifying the stride when walking through input
592      *      in the ‘height’ dimension.
593      * * 4: An INT32 value, specifying the filter width.
594      * * 5: An INT32 value, specifying the filter height.
595      * * 6: An INT32 value, and has to be one of the {@link FuseCode} values.
596      *      Specifies the activation to invoke on the result of each addition.
597      *
598      * Outputs:
599      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
600      */
601     ANEURALNETWORKS_L2_POOL_2D = 12,
602 
603     /** Applies Local Response Normalization along the depth dimension.
604      *
605      * The 4-D input tensor is treated as a 3-D array of 1-D vectors (along the last
606      * dimension), and each vector is normalized independently. Within a given vector,
607      * each component is divided by the weighted, squared sum of inputs within depth_radius.
608      *
609      * The output is calculated using this formula:
610      *
611      *     sqr_sum[a, b, c, d] =
612      *         sum(pow(input[a, b, c, d - depth_radius : d + depth_radius + 1], 2)
613      *     output = input / pow((bias + alpha * sqr_sum), beta)
614      *
615      * Supported tensor types:
616      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
617      *
618      * Supported tensor rank: 4, with "NHWC" data layout.
619      *
620      * Inputs:
621      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
622      * * 1: An INT32 value, specifying the radius of the normalization window.
623      * * 2: A FLOAT32 value, specifying the bias, must not be zero.
624      * * 3: A FLOAT32 value, specifying the scale factor, alpha.
625      * * 4: A FLOAT32 value, specifying the exponent, beta.
626      *
627      * Outputs:
628      * * 0: The output tensor of same shape as input0.
629      */
630     ANEURALNETWORKS_LOCAL_RESPONSE_NORMALIZATION = 13,
631 
632     /** Computes sigmoid activation on the input tensor element-wise.
633      *
634      * The output is calculated using this formula:
635      *
636      *     output = 1 / (1 + exp(-input))
637      *
638      * Supported tensor types:
639      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
640      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
641      *
642      * Supported tensor rank: up to 4.
643      *
644      * Inputs:
645      * * 0: A tensor, specifying the input.
646      *
647      * Outputs:
648      * * 0: The output tensor of same shape as input0.
649      *      For {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type,
650      *      the scale must be 1.f / 256 and the zeroPoint must be 0.
651      */
652     ANEURALNETWORKS_LOGISTIC = 14,
653 
654     /**
655      * Projects an input to a bit vector via locality senstive hashing.
656      *
657      * Inputs:
658      * * 0: Hash functions. Dim.size == 2, DataType: Float.
659      *            Tensor[0].Dim[0]: Number of hash functions.
660      *            Tensor[0].Dim[1]: Number of seeds per hash functions.
661      *            Tensor[0].Dim[1] <= 32 in sparse case.
662      *
663      * * 1: Input. Dim.size >= 1, no restriction on DataType.
664      * * 2: Weight. Optional. Dim.size == 1, DataType: Float.
665      *     If not set, each input element is considered to have the same weight of
666      *     1.0.
667      *     Tensor[1].Dim[0] == Tensor[2].Dim[0]
668      * * 3: Type:
669      *        Sparse: Value LSHProjectionType_SPARSE(=1).
670      *          Computed bit vector is considered to be sparse.
671      *          Each output element is an int32 made up of multiple bits computed from
672      *          hash functions.
673      *
674      *        Dense: Value LSHProjectionType_DENSE(=2).
675      *          Computed bit vector is considered to be dense. Each output element
676      *          represents a bit and can take the value of either 0 or 1.
677      *
678      * Outputs:
679      * * 0: If the projection type is sparse:
680      *        Output.Dim == { Tensor[0].Dim[0] }
681      *        A tensor of int32 that represents hash signatures.
682      *      If the projection type is Dense:
683      *        Output.Dim == { Tensor[0].Dim[0] * Tensor[0].Dim[1] }
684      *        A flattened tensor that represents projected bit vectors.
685      */
686     ANEURALNETWORKS_LSH_PROJECTION = 15,
687 
688     /**
689      * Long short-term memory unit (LSTM) recurrent network layer.
690      *
691      * The default non-peephole implementation is based on:
692      * http://deeplearning.cs.cmu.edu/pdfs/Hochreiter97_lstm.pdf
693      * S. Hochreiter and J. Schmidhuber. "Long Short-Term Memory". Neural
694      * Computation, 9(8):1735-1780, 1997.
695      *
696      * The peephole implementation is based on:
697      * https://research.google.com/pubs/archive/43905.pdf
698      * Hasim Sak, Andrew Senior, and Francoise Beaufays. "Long short-term memory
699      * recurrent neural network architectures for large scale acoustic modeling."
700      * INTERSPEECH, 2014.
701      *
702      * The coupling of input and forget gate (CIFG) is based on:
703      * http://arxiv.org/pdf/1503.04069.pdf
704      * Greff et al. "LSTM: A Search Space Odyssey"
705      *
706      * The class has the following independently optional inputs:
707      * * If input gate (if CIFG): “input_to_forget_weights”,
708      *   “recurrent_to_input_weights”, “cell_to_input_weights”, “input_gate_bias”.
709      * * If no peephole connections: “cell_to_input_weights”,
710      *   “cell_to_forget_weights”, “cell_to_output_weights”.
711      * * If no projection layer: “projection_weights” and “projection_bias”.
712      * * If no projection bias: “projection_bias”.
713      *
714      * Supported tensor types (type T):
715      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
716      *
717      * Inputs:
718      * * 0: Input.
719      *      A 2-D tensor of type T, of shape [batch_size, input_size], where
720      *      “batch_size” corresponds to the batching dimension, and “input_size”
721      *      is the size of the input.
722      * * 1: input_to_input_weights.
723      *      A 2-D tensor of type T, of shape [num_units, input_size], where
724      *      “num_units” corresponds to the number of cell units.
725      * * 2: input_to_forget_weights.
726      *      A 2-D tensor of type T, of shape [num_units, input_size].
727      * * 3: input_to_cell_weights.
728      *      A 2-D tensor of type T, of shape [num_units, input_size].
729      * * 4: input_to_output_weights.
730      *      A 2-D tensor of type T, of shape [num_units, input_size].
731      * * 5: recurrent_to_input_weights.
732      *      A 2-D tensor of type T, of shape [num_units, output_size], where
733      *      “output_size” corresponds to either the number of cell units (i.e.,
734      *      “num_units”), or the second dimension of the “projection_weights”, if
735      *      defined.
736      * * 6: recurrent_to_forget_weights.
737      *      A 2-D tensor of type T, of shape [num_units, output_size].
738      * * 7: recurrent_to_cell_weights.
739      *      A 2-D tensor of type T, of shape [num_units, output_size].
740      * * 8: recurrent_to_output_weights.
741      *      A 2-D tensor of type T, of shape [num_units, output_size].
742      * * 9: cell_to_input_weights.
743      *      A 1-D tensor of type T, of shape [num_units].
744      * * 10:cell_to_forget_weights.
745      *      A 1-D tensor of type T, of shape [num_units].
746      * * 11:cell_to_output_weights.
747      *      A 1-D tensor of type T, of shape [num_units].
748      * * 12:input_gate_bias.
749      *      A 1-D tensor of type T, of shape [num_units].
750      * * 13:forget_gate_bias.
751      *      A 1-D tensor of type T, of shape [num_units].
752      * * 14:cell_bias.
753      *      A 1-D tensor of type T, of shape [num_units].
754      * * 15:output_gate_bias.
755      *      A 1-D tensor of type T, of shape [num_units].
756      * * 16:projection_weights.
757      *      A 2-D tensor of type T, of shape [output_size, num_units].
758      * * 17:projection_bias.
759      *      A 1-D tensor of type T, of shape [output_size].
760      * * 18: output_state (in).
761      *      A 2-D tensor of type T, of shape [batch_size, output_size].
762      * * 19: cell_state (in).
763      *      A 2-D tensor of type T, of shape [batch_size, num_units].
764      * * 20:fused_activation_function.
765      *      An optional {@link FuseCode} value indicating the activation
766      *      function.
767      *      If “NONE” is specified then it results in a linear activation.
768      * * 21:cell_clip.
769      *      A clipping threshold for the cell state, such that values are bound
770      *      within [-cell_clip, cell_clip]. If set to 0.0 then clipping is
771      *      disabled.
772      * * 22:proj_clip.
773      *      A clipping threshold for the output from the projection layer, such
774      *      that values are bound within [-proj_clip, proj_clip]. If set to 0.0
775      *      then clipping is disabled.
776      *
777      * Outputs:
778      * * 0: scratch_buffer.
779      *      A 3-D tensor of type T, of shape [batch_size, num_cell, 4].
780      * * 1: output_state (out).
781      *      A 2-D tensor of type T, of shape [batch_size, output_size].
782      * * 2: cell_state (out).
783      *      A 2-D tensor of type T, of shape [batch_size, num_units].
784      * * 3: output.
785      *      A 2-D tensor of type T, of shape [batch_size, output_size]. This is
786      *      effectively the same as the current “output_state” value.
787      */
788     ANEURALNETWORKS_LSTM = 16,
789 
790     /** Performs an 2-D max pooling operation.
791      *
792      * The output dimensions are functions of the filter dimensions, stride, and padding.
793      *
794      * The values in the output tensor are computed as:
795      *
796      *     output[batch, row, col, channel] =
797      *         max_{i, j} (input[batch, row + i, col + j, channel])
798      *
799      * Supported tensor types:
800      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
801      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
802      *
803      * Supported tensor rank: 4, with "NHWC" data layout.
804      *
805      * Both explicit padding and implicit padding are supported.
806      *
807      * Inputs (explicit padding):
808      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
809      * * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
810      * * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
811      * * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
812      * * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
813      * * 5: An INT32 value, specifying the stride when walking through input
814      *      in the ‘width’ dimension.
815      * * 6: An INT32 value, specifying the stride when walking through input
816      *      in the ‘height’ dimension.
817      * * 7: An INT32 value, specifying the filter width.
818      * * 8: An INT32 value, specifying the filter height.
819      * * 9: An INT32 value, and has to be one of the {@link FuseCode} values.
820      *      Specifies the activation to invoke on the result of each addition.
821      *
822      * Inputs (implicit padding):
823      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
824      * * 1: An INT32 value, specifying the implicit padding scheme, has to be one of the
825      *      {@link PaddingCode} values.
826      * * 2: An INT32 value, specifying the stride when walking through input
827      *      in the ‘width’ dimension.
828      * * 3: An INT32 value, specifying the stride when walking through input
829      *      in the ‘height’ dimension.
830      * * 4: An INT32 value, specifying the filter width.
831      * * 5: An INT32 value, specifying the filter height.
832      * * 6: An INT32 value, and has to be one of the {@link FuseCode} values.
833      *      Specifies the activation to invoke on the result of each addition.
834      *
835      * Outputs:
836      * * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
837      */
838     ANEURALNETWORKS_MAX_POOL_2D = 17,
839 
840     /** Multiplies two tensors, element-wise.
841      *
842      * Takes two input tensors of identical type and compatible dimensions. The output
843      * is the product of both input tensors, optionally modified by an activation function.
844      *
845      * Two dimensions are compatible when:
846      *     1. they are equal, or
847      *     2. one of them is 1
848      *
849      * The size of the resulting output is the maximum size along each dimension of the
850      * input operands. It starts with the trailing dimensions, and works its way forward.
851      *
852      * Supported tensor types:
853      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
854      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
855      *
856      * Supported tensor rank: up to 4
857      *
858      * Inputs:
859      * * 0: A tensor.
860      * * 1: A tensor of the same type, and compatible dimensions as input0.
861      * * 2: An INT32 value, and has to be one of the {@link FuseCode} values.
862      *      Specifies the activation to invoke on the result of each addition.
863      *
864      * Outputs:
865      * * 0: The product, a tensor of the same type as input0.
866      *      For output tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type, the following
867      *      condition must be satisfied: output_scale > input1_scale * input2_scale.
868      */
869     ANEURALNETWORKS_MUL = 18,
870 
871     /** Computes rectified linear activation on the input tensor element-wise.
872      *
873      * The output is calculated using this formula:
874      *
875      *     output = max(0, input)
876      *
877      * Supported tensor types:
878      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
879      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
880      *
881      * Supported tensor rank: up to 4.
882      *
883      * Inputs:
884      * * 0: A tensor, specifying the input.
885      *
886      * Outputs:
887      * * 0: The output tensor of same shape as input0.
888      */
889     ANEURALNETWORKS_RELU = 19,
890 
891     /** Computes rectified linear 1 activation on the input tensor element-wise.
892      *
893      * The output is calculated using this formula:
894      *
895      *     output = min(1.f, max(-1.f, input))
896      *
897      * Supported tensor types:
898      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
899      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
900      *
901      * Supported tensor rank: up to 4.
902      *
903      * Inputs:
904      * * 0: A tensor, specifying the input.
905      *
906      * Outputs:
907      * * 0: The output tensor of same shape as input0.
908      */
909     ANEURALNETWORKS_RELU1 = 20,
910 
911     /** Computes rectified linear 6 activation on the input tensor element-wise.
912      *
913      * The output is calculated using this formula:
914      *
915      *     output = min(6, max(0, input))
916      *
917      * Supported tensor types:
918      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
919      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
920      *
921      * Supported tensor rank: up to 4.
922      *
923      * Inputs:
924      * * 0: A tensor, specifying the input.
925      *
926      * Outputs:
927      * * 0: The output tensor of same shape as input0.
928      */
929     ANEURALNETWORKS_RELU6 = 21,
930 
931     /** Reshapes a tensor.
932      *
933      * Given tensor, this operation returns a tensor that has the same values as tensor,
934      * but with a newly specified shape.
935      *
936      * Supported tensor types:
937      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
938      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
939      *
940      * Supported tensor rank: up to 4.
941      *
942      * Inputs:
943      * * 0: A tensor, specifying the tensor to be reshaped.
944      * * 1: A 1-D tensor of type {@link ANEURALNETWORKS_TENSOR_INT32}, defining the shape
945      *      of the output tensor. The number of elements implied by shape must be the same
946      *      as the number of elements in the input tensor.
947      *
948      * Outputs:
949      * * 0: The output tensor, of shape specified by the input shape.
950      */
951     ANEURALNETWORKS_RESHAPE = 22,
952 
953     /** Resizes images to given size using the bilinear interpretation.
954      *
955      * Resized images will be distorted if their output aspect ratio is not the same as
956      * input aspect ratio.
957      *
958      * Supported tensor types:
959      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
960      *
961      * Supported tensor rank: 4, with "NHWC" data layout.
962      *
963      * Inputs:
964      * * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
965      * * 1: An INT32 value, specifying the output height of the output tensor.
966      * * 2: An INT32 value, specifying the output width of the output tensor.
967      *
968      * Outputs:
969      * * 0: The output 4-D tensor, of shape [batches, new_height, new_width, depth].
970      */
971     ANEURALNETWORKS_RESIZE_BILINEAR = 23,
972 
973     /**
974      * A basic recurrent neural network layer.
975      *
976      * This layer implements the operation:
977      * outputs = state = activation(inputs * input_weights + state * recurrent_weights + bias)
978      *
979      * Where:
980      * * “input_weights” is a weight matrix that multiplies the inputs;
981      * * “recurrent_weights” is a weight matrix that multiplies the current
982      *    “state” which itself is the output from the previous time step
983      *    computation;
984      * * “bias” is a bias vector (added to each output vector in the batch);
985      * * “activation” is the function passed as the “fused_activation_function”
986      *   argument (if not “NONE”).
987      *
988      * Supported tensor types (Type T):
989      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
990      *
991      * Inputs:
992      * * 0: input.
993      *      A 2-D tensor of type T, of shape [batch_size, input_size], where
994      *      “batch_size” corresponds to the batching dimension, and “input_size” is
995      *      the size of the input.
996      * * 1: weights.
997      *      A 2-D tensor of type T, of shape [num_units, input_size], where
998      *      “num_units” corresponds to the number of units.
999      * * 2: recurrent_weights.
1000      *      A 2-D tensor of type T, of shape [num_units, num_units], with columns
1001      *      corresponding to the weights from each unit.
1002      * * 3: bias.
1003      *      A 1-D tensor of type T, of shape [num_units].
1004      * * 4: hidden state (in).
1005      *      A 2-D tensor of type T, of shape [batch_size, num_units].
1006      * * 5: fused_activation_function.
1007      *      An optional {@link FuseCode} value indicating the activation
1008      *      function. If “NONE” is specified then it results in a linear
1009      *      activation.
1010      *
1011      * Outputs:
1012      * * 0: hidden state (out).
1013      *      A 2-D tensor of type T, of shape [batch_size, num_units].
1014      *
1015      * * 1: output.
1016      *      A 2-D tensor of type T, of shape [batch_size, num_units]. This is
1017      *      effectively the same as the current state value.
1018      */
1019     ANEURALNETWORKS_RNN = 24,
1020 
1021     /** Computes the softmax activation on the input tensor element-wise, per batch, by
1022      * normalizing the input vector so the maximum coefficient is zero.
1023      *
1024      * The output is calculated using this formula:
1025      *
1026      *     output[batch, i] =
1027      *         exp((input[batch, i] - max(input[batch, :])) * beta) /
1028      *         sum_{k}{exp((input[batch, k] - max(input[batch, :])) * beta)}
1029      *
1030      * Supported tensor types:
1031      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
1032      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
1033      *
1034      * Supported tensor rank: 2 or 4.
1035      *
1036      * Inputs:
1037      * * 0: A 2-D or 4-D tensor, specifying the tensor to be reshaped.
1038      * * 1: A FLOAT32 value, specifying the positive scaling factor for the exponent, beta.
1039      *
1040      * Outputs:
1041      * * 0: The output tensor of same shape as input0.
1042      *      For {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM} type,
1043      *      the scale must be 1.f / 256 and the zeroPoint must be 0.
1044      */
1045     ANEURALNETWORKS_SOFTMAX = 25,
1046 
1047     /** Rearranges blocks of spatial data, into depth.
1048      *
1049      * More specifically, this op outputs a copy of the input tensor where values from
1050      * the height and width dimensions are moved to the depth dimension.
1051      * The value block_size indicates the input block size and how the data is moved.
1052      *
1053      * Chunks of data of size block_size * block_size from depth are rearranged into
1054      * non-overlapping blocks of size block_size x block_size.
1055      *
1056      * The depth of the output tensor is input_depth * block_size * block_size.
1057      * The input tensor's height and width must be divisible by block_size.
1058      *
1059      * Supported tensor types:
1060      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
1061      * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
1062      *
1063      * Supported tensor rank: 4, with "NHWC" data layout.
1064      *
1065      * Inputs:
1066      * * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
1067      * * 1: An INT32 value, specifying the block_size. block_size must be >=1 and
1068      *      block_size must be a divisor of both the input height and width.
1069      *
1070      * Outputs:
1071      * * 0: The output 4-D tensor, of shape [batch, height/block_size, width/block_size,
1072      *      depth*block_size*block_size].
1073      */
1074     ANEURALNETWORKS_SPACE_TO_DEPTH = 26,
1075 
1076     /**
1077      * SVDF op is a kind of stateful layer derived from the notion that a
1078      * densely connected layer that's processing a sequence of input frames can
1079      * be approximated by using a singular value decomposition of each of its
1080      * nodes. The implementation is based on:
1081      *
1082      * https://research.google.com/pubs/archive/43813.pdf
1083      *
1084      * P. Nakkiran, R. Alvarez, R. Prabhavalkar, C. Parada.
1085      * “Compressing Deep Neural Networks using a Rank-Constrained Topology”.
1086      * INTERSPEECH, 2015.
1087      *
1088      * It processes the incoming input using a 2-stage filtering mechanism:
1089      * * stage 1 performs filtering on the "features" dimension, whose outputs get
1090      *   pushed into a memory of fixed-size memory_size.
1091      * * stage 2 performs filtering on the "time" dimension of the memory_size
1092      *   memoized outputs of stage 1.
1093      *
1094      * Specifically, for rank 1, this layer implements the operation:
1095      *
1096      *    memory = push(conv1d(inputs, weights_feature, feature_dim,
1097      *                  "ANEURALNETWORKS_PADDING_VALID"));
1098      *    outputs = activation(memory * weights_time + bias);
1099      *
1100      * Where:
1101      * * “weights_feature” is a weights matrix that processes the inputs (by
1102      *   convolving the input with every “feature filter”), and whose outputs get
1103      *   pushed, stacked in order, into the fixed-size “memory” (the oldest entry
1104      *   gets dropped);
1105      * * “weights_time” is a weights matrix that processes the “memory” (by a
1106      *   batched matrix multiplication on the num_units);
1107      * * “bias” is an optional bias vector (added to each output vector in the
1108      *   batch); and
1109      * * “activation” is the function passed as the “fused_activation_function”
1110      *   argument (if not “NONE”).
1111      *
1112      * Each rank adds a dimension to the weights matrices by means of stacking
1113      * the filters.
1114      *
1115      * Supported tensor types (type T):
1116      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
1117      *
1118      * Inputs:
1119      * * 0: input.
1120      *      A 2-D tensor of type T, of shape [batch_size, input_size], where
1121      *      “batch_size” corresponds to the batching dimension, and “input_size” is
1122      *      the size of the input.
1123      * * 1: weights_feature.
1124      *      A 2-D tensor of type T, of shape [num_units, input_size], where
1125      *      “num_units” corresponds to the number of units.
1126      * * 2: weights_time.
1127      *      A 2-D tensor of type T, of shape [num_units, memory_size], where
1128      *      “memory_size” corresponds to the fixed-size of the memory.
1129      * * 3: bias.
1130      *      An optional 1-D tensor of type T, of shape [num_units].
1131      * * 4: state (in).
1132      *      A 2-D tensor of type T, of shape [batch_size, (memory_size - 1) * num_units * rank].
1133      * * 5: rank.
1134      *      The rank of the SVD approximation.
1135      * * 6: fused_activation_function.
1136      *      An optional {@link FuseCode} value indicating the activation function.
1137      *      If “NONE” is specified then it results in a linear activation.
1138      *
1139      * Outputs:
1140      * * 0: state (out).
1141      *      A 2-D tensor of type T, of shape [batch_size, (memory_size - 1) * num_units * rank].
1142      * * 1: output.
1143      *      A 2-D tensor of type T, of shape [batch_size, num_units].
1144      */
1145     ANEURALNETWORKS_SVDF = 27,
1146 
1147     /** Computes hyperbolic tangent of input tensor element-wise.
1148      *
1149      * The output is calculated using this formula:
1150      *
1151      *     output = tanh(input)
1152      *
1153      * Supported tensor types:
1154      * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
1155      *
1156      * Supported tensor rank: up to 4.
1157      *
1158      * Inputs:
1159      * * 0: A tensor, specifying the input.
1160      *
1161      * Outputs:
1162      * * 0: The output tensor of same shape as input0.
1163      */
1164     ANEURALNETWORKS_TANH = 28,
1165 } OperationCode;
1166 
1167 /**
1168  * Fused activation function types.
1169  *
1170  */
1171 typedef enum {
1172     /** NO fused activation function. */
1173     ANEURALNETWORKS_FUSED_NONE = 0,
1174     /** Fused ReLU activation function. */
1175     ANEURALNETWORKS_FUSED_RELU = 1,
1176     /** Fused ReLU1 activation function. */
1177     ANEURALNETWORKS_FUSED_RELU1 = 2,
1178     /** Fused ReLU6 activation function. */
1179     ANEURALNETWORKS_FUSED_RELU6 = 3,
1180 } FuseCode;
1181 
1182 /**
1183  * Implicit padding algorithms.
1184  *
1185  */
1186 typedef enum {
1187     /**
1188      * SAME padding.
1189      * Padding on both ends are the "same":
1190      *     padding_to_beginning =  total_padding / 2
1191      *     padding_to_end       = (total_padding + 1)/2.
1192      * i.e., for even number of padding, padding to both ends are exactly
1193      * the same; for odd number of padding, padding to the ending is bigger
1194      * than the padding to the beginning by 1.
1195      *
1196      * total_padding is a function of input, stride and filter size.
1197      * It could be computed as follows:
1198      *    out_size = (input + stride - 1) / stride;
1199      *    needed_input = (out_size - 1) * stride + filter_size
1200      *    total_padding = max(0, needed_input - output_size)
1201      *  The computation is the same for the horizontal and vertical directions.
1202      */
1203     ANEURALNETWORKS_PADDING_SAME = 1,
1204 
1205     /**
1206      * VALID padding.
1207      * No padding. When the input size is not evenly divisible by
1208      * the filter size, the input at the end that could not fill
1209      * the whole filter tile will simply be ignored.
1210      */
1211     ANEURALNETWORKS_PADDING_VALID = 2,
1212 } PaddingCode;
1213 
1214 /**
1215  * Execution preferences.
1216  */
1217 typedef enum {
1218     /**
1219      * Prefer executing in a way that minimizes battery drain.
1220      * This is desirable for compilations that will be executed often.
1221      */
1222     ANEURALNETWORKS_PREFER_LOW_POWER = 0,
1223     /**
1224      * Prefer returning a single answer as fast as possible, even if this causes
1225      * more power consumption.
1226      */
1227     ANEURALNETWORKS_PREFER_FAST_SINGLE_ANSWER = 1,
1228     /**
1229      * Prefer maximizing the throughput of successive frames, for example when
1230      * processing successive frames coming from the camera.
1231      */
1232     ANEURALNETWORKS_PREFER_SUSTAINED_SPEED = 2,
1233 } PreferenceCode;
1234 
1235 /**
1236  * Result codes.
1237  */
1238 typedef enum {
1239     ANEURALNETWORKS_NO_ERROR = 0,
1240     ANEURALNETWORKS_OUT_OF_MEMORY = 1,
1241     ANEURALNETWORKS_INCOMPLETE = 2,
1242     ANEURALNETWORKS_UNEXPECTED_NULL = 3,
1243     ANEURALNETWORKS_BAD_DATA = 4,
1244     ANEURALNETWORKS_OP_FAILED = 5,
1245     ANEURALNETWORKS_UNMAPPABLE = 5,
1246     ANEURALNETWORKS_BAD_STATE = 6,
1247 } ResultCode;
1248 
1249 /**
1250  * For {@link ANeuralNetworksModel_setOperandValue}, values with a
1251  * length smaller or equal to this will be immediately copied into
1252  * the model. The size is in bytes.
1253  */
1254 enum {
1255     ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES = 128
1256 };
1257 
1258 /**
1259  * ANeuralNetworksMemory is an opaque type that represents memory.
1260  *
1261  * This type is used to represent shared memory, memory mapped files,
1262  * and similar memories.
1263  *
1264  * By using shared memory, a program can efficiently communicate to the
1265  * runtime and drivers the tensors that define a model. See
1266  * {@link ANeuralNetworksModel_setOperandValueFromMemory}. An application
1267  * should typically create one shared memory object that contains every tensor
1268  * needed to define a model. {@link ANeuralNetworksMemory_createFromFd} can be
1269  * used to create shared memory from a file handle. {@link ANeuralNetworksMemory_createShared}
1270  * can be used to directly created shared memory.
1271  *
1272  * Memory objects can also be used to specify the input and output arguments of
1273  * an execution. See {@link ANeuralNetworksExecution_setInputFromMemory}
1274  * and {@link ANeuralNetworksExecution_setOutputFromMemory}.
1275  */
1276 typedef struct ANeuralNetworksMemory ANeuralNetworksMemory;
1277 
1278 /**
1279  * ANeuralNetworksModel is an opaque type that contains a description of the
1280  * mathematical operations that constitute the model.
1281  *
1282  * <p>The model will be built by calling<ul>
1283  * <li>{@link ANeuralNetworksModel_create},</li>
1284  * <li>{@link ANeuralNetworksModel_addOperation},</li>
1285  * <li>{@link ANeuralNetworksModel_addOperand},</li>
1286  * </ul>
1287  *
1288  * A model is completed by calling {@link ANeuralNetworksModel_finish}.
1289  * A model is destroyed by calling {@link ANeuralNetworksModel_free}.
1290  *
1291  * <p>A model cannot be modified once {@link ANeuralNetworksModel_finish}
1292  * has been called on it.</p>
1293  *
1294  * <p>It is the application's responsibility to make sure that only one thread
1295  * modifies a model at a given time. It is however safe for more than one
1296  * thread to use the model once {@link ANeuralNetworksModel_finish} has returned.</p>
1297  *
1298  * <p>It is also the application's responsibility to ensure that there are no other
1299  * uses of the model after calling {@link ANeuralNetworksModel_free}.
1300  * This includes any compilation or execution object created using the model.</p>
1301  */
1302 typedef struct ANeuralNetworksModel ANeuralNetworksModel;
1303 
1304 /**
1305  * ANeuralNetworksCompilation is an opaque type that can be used to compile
1306  * a machine learning model.
1307  *
1308  * <p>To use:<ul>
1309  *    <li>Create a new compilation instance by calling the
1310  *        {@link ANeuralNetworksCompilation_create} function.</li>
1311  *    <li>Set any desired properties on the compilation (for example,
1312  *        {@link ANeuralNetworksCompilation_setPreference}).</li>
1313  *    <li>Complete the compilation with {@link ANeuralNetworksCompilation_finish}.</li>
1314  *    <li>Use the compilation as many times as needed
1315  *        with {@link ANeuralNetworksExecution_create}.</li>
1316  *    <li>Destroy the compilation with {@link ANeuralNetworksCompilation_free}
1317  *        once all executions using the compilation have completed.</li></ul></p>
1318  *
1319  * A compilation is completed by calling {@link ANeuralNetworksCompilation_finish}.
1320  * A compilation is destroyed by calling {@link ANeuralNetworksCompilation_free}.
1321  *
1322  * <p>A compilation cannot be modified once {@link ANeuralNetworksCompilation_finish}
1323  * has been called on it.</p>
1324  *
1325  * <p>It is the application's responsibility to make sure that only
1326  * one thread modifies a compilation at a given time. It is however
1327  * safe for more than one thread to use the compilation once
1328  * {@link ANeuralNetworksCompilation_finish} has returned.</p>
1329  *
1330  * <p>It is also the application's responsibility to ensure that there are no other
1331  * uses of the compilation after calling {@link ANeuralNetworksCompilation_free}.
1332  * This includes any execution object created using the compilation.</p>
1333  */
1334 typedef struct ANeuralNetworksCompilation ANeuralNetworksCompilation;
1335 
1336 /**
1337  * ANeuralNetworksExecution is an opaque type that can be used to apply a machine
1338  * learning model to a set of inputs.
1339  *
1340  * <p>To use:<ul>
1341  *    <li>Create a new execution instance by calling the
1342  *        {@link ANeuralNetworksExecution_create} function.</li>
1343  *    <li>Associate data to the model inputs with
1344  *        {@link ANeuralNetworksExecution_setInput} or
1345  *        {@link ANeuralNetworksExecution_setInputFromMemory}.</li>
1346  *    <li>Associate output buffers to the model outputs with
1347  *        {@link ANeuralNetworksExecution_setOutput} or
1348  *        {@link ANeuralNetworksExecution_setOutputFromMemory}.</li>
1349  *    <li>Apply the model with {@link ANeuralNetworksExecution_startCompute}.</li>
1350  *    <li>Wait for the execution to complete with {@link
1351  *        ANeuralNetworksEvent_wait}.</li>
1352  *    <li>Destroy the execution with
1353  *        {@link ANeuralNetworksExecution_free}.</li></ul></p>
1354  *
1355  * <p>An execution cannot be modified once {@link ANeuralNetworksExecution_startCompute}
1356  * has been called on it.</p>
1357  *
1358  * <p>An execution can be applied to a model with
1359  * {@link ANeuralNetworksExecution_startCompute} only once. Create new executions
1360  * to do new evaluations of the model.</p>
1361  *
1362  * <p>It is the application's responsibility to make sure that only one thread
1363  * modifies an execution at a given time. It is however safe for more than one
1364  * thread to use {@link ANeuralNetworksEvent_wait} at the same time.</p>
1365  *
1366  * <p>It is also the application's responsibility to ensure that there are no other
1367  * uses of the request after calling {@link ANeuralNetworksExecution_free}.</p>
1368  */
1369 typedef struct ANeuralNetworksExecution ANeuralNetworksExecution;
1370 
1371 /**
1372  * ANeuralNetworksOperandType describes the type of an operand.
1373  * This structure is used to describe both scalars and tensors.
1374  */
1375 typedef struct ANeuralNetworksOperandType {
1376     /** The data type, e.g ANEURALNETWORKS_INT8. */
1377     int32_t type;
1378     /** The number of dimensions. It should be 0 for scalars. */
1379     uint32_t dimensionCount;
1380     /** The dimensions of the tensor. It should be nullptr for scalars. */
1381     const uint32_t* dimensions;
1382     /** These two fields are only used for quantized tensors.
1383      * They should be zero for scalars and non-fixed point tensors.
1384      * The dequantized value of each entry is (value - zeroPoint) * scale.
1385      */
1386     float scale;
1387     int32_t zeroPoint;
1388 } ANeuralNetworksOperandType;
1389 
1390 typedef int32_t ANeuralNetworksOperationType;
1391 
1392 /**
1393  * ANeuralNetworksEvent is an opaque type that represents an event
1394  * that will be signaled once an execution completes.
1395  */
1396 typedef struct ANeuralNetworksEvent ANeuralNetworksEvent;
1397 
1398 
1399 /**
1400  * Creates a shared memory object from a file descriptor.
1401  *
1402  * The shared memory is backed by a file descriptor via mmap.
1403  * See {@link ANeuralNetworksMemory} for a description on how to use
1404  * this shared memory.
1405  *
1406  * @param size The requested size in bytes.
1407  *             Must not be larger than the file size.
1408  * @param prot The desired memory protection for the mapping.
1409  *             It is either PROT_NONE or the bitwise OR of one or
1410  *             more of the following flags: PROT_READ, PROT_WRITE.
1411  * @param fd The requested file descriptor.
1412  *           The file descriptor has to be mmap-able. The file
1413  *           descriptor will be duplicated.
1414  * @param offset The offset to the beginning of the file of the area to map.
1415  *               The offset has to be aligned to a page size.
1416  * @param memory The memory object to be created.
1417  *               Set to NULL if unsuccessful.
1418  *
1419  * @return ANEURALNETWORKS_NO_ERROR if the request completed normally.
1420  */
1421 int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset,
1422                                        ANeuralNetworksMemory** memory);
1423 
1424 /**
1425  * Delete a memory object.
1426  *
1427  * Destroys the object used by the run time to keep track of the memory.
1428  * This will free the underlying actual memory if no other code has open
1429  * handles to this memory.
1430  *
1431  * @param memory The memory object to be freed.
1432  */
1433 void ANeuralNetworksMemory_free(ANeuralNetworksMemory* memory);
1434 
1435 /**
1436  * Create an empty {@link ANeuralNetworksModel}.
1437  *
1438  * <p>This only creates the object. Computation is performed once
1439  * {@link ANeuralNetworksExecution_startCompute} is invoked.
1440  *
1441  * The model should be constructed with calls to
1442  * {@link ANeuralNetworksModel_addOperation} and
1443  * {@link ANeuralNetworksModel_addOperand}
1444  *
1445  * <p>{@link ANeuralNetworksModel_finish} should be called once the model
1446  * has been fully constructed.</p>
1447  *
1448  * <p>{@link ANeuralNetworksModel_free} should be called once the model
1449  * is no longer needed.</p>
1450  *
1451  * @param model The {@link ANeuralNetworksModel} to be created.
1452  *              Set to NULL if unsuccessful.
1453  *
1454  * @return ANEURALNETWORKS_NO_ERROR if successful.
1455  */
1456 int ANeuralNetworksModel_create(ANeuralNetworksModel** model);
1457 
1458 /**
1459  * Destroy a model.
1460  *
1461  * The model need not have been finished by a call to
1462  * {@link ANeuralNetworksModel_finish}.
1463  *
1464  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1465  *
1466  * @param model The model to be destroyed. Passing NULL is acceptable and
1467  *              results in no operation.
1468  */
1469 void ANeuralNetworksModel_free(ANeuralNetworksModel* model);
1470 
1471 /**
1472  * Indicate that we have finished modifying a model. Required before
1473  * calling {@link ANeuralNetworksCompilation_create}.
1474  *
1475  * An application is responsible to make sure that no other thread uses
1476  * the model at the same time.
1477  *
1478  * This function must only be called once for a given model.
1479  *
1480  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1481  *
1482  * @param model The model to be finished.
1483  *
1484  * @return ANEURALNETWORKS_NO_ERROR if successful.
1485  */
1486 int ANeuralNetworksModel_finish(ANeuralNetworksModel* model);
1487 
1488 /**
1489  * Add an operand to a model.
1490  *
1491  * The order in which the operands are added is important. The first one added
1492  * to a model will have the index value 0, the second 1, etc. These indexes are
1493  * used as operand identifiers in {@link ANeuralNetworksModel_addOperation},
1494  * {@link ANeuralNetworksExecution_setInput},
1495  * {@link ANeuralNetworksExecution_setInputFromMemory},
1496  * {@link ANeuralNetworksExecution_setOutput},
1497  * {@link ANeuralNetworksExecution_setOutputFromMemory} and
1498  * {@link ANeuralNetworksExecution_setOperandValue}.
1499  *
1500  * To build a model that can accomodate inputs of various sizes, as you may want
1501  * to do for a CNN, set the size of the dimensions that will vary at run time to 0.
1502  * If you do so, provide the full dimensions when calling
1503  * {@link ANeuralNetworksExecution_setInput} or {@link ANeuralNetworksExecution_setInputFromMemory}.
1504  *
1505  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1506  * called will return an error.
1507  *
1508  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1509  *
1510  * @param model The model to be modified.
1511  * @param type The {@link ANeuralNetworksOperandType} that describes the shape
1512  * of the operand.
1513  *
1514  * @return ANEURALNETWORKS_NO_ERROR if successful.
1515  */
1516 int ANeuralNetworksModel_addOperand(ANeuralNetworksModel* model,
1517                                     const ANeuralNetworksOperandType* type);
1518 
1519 /**
1520  * Sets an operand to a constant value.
1521  *
1522  * Values of length smaller or equal to
1523  * {@link ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES}
1524  * are immediately copied into the model.
1525  *
1526  * For values of length greater than {@link ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES},
1527  * a pointer to the buffer is stored within the model. The application is responsible
1528  * for not changing the content of this region until all executions using this model
1529  * have completed. As the data may be copied during processing, modifying the data
1530  * after this call yields undefined results.
1531  *
1532  * For large tensors, using {@link ANeuralNetworksModel_setOperandValueFromMemory}
1533  * is likely to be more efficient.
1534  *
1535  * To indicate that an optional operand should be considered missing,
1536  * pass nullptr for buffer and 0 for length.
1537  *
1538  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1539  * called will return an error.
1540  *
1541  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1542  *
1543  * @param model The model to be modified.
1544  * @param index The index of the model operand we're setting.
1545  * @param buffer A pointer to the data to use.
1546  * @param length The size in bytes of the data value.
1547  *
1548  * @return ANEURALNETWORKS_NO_ERROR if successful.
1549  */
1550 int ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel* model, int32_t index,
1551                                          const void* buffer, size_t length);
1552 
1553 /**
1554  * Sets an operand to a value stored in a memory object.
1555  *
1556  * The content of the memory is not copied. A reference to that memory is stored
1557  * inside the model. The application is responsible for not changing the content
1558  * of the memory region until all executions using this model have completed.
1559  * As the data may be copied during processing, modifying the data after this call
1560  * yields undefined results.
1561  *
1562  * To indicate that an optional operand should be considered missing,
1563  * use {@link ANeuralNetworksModel_setOperandValue} instead, passing nullptr for buffer.
1564  *
1565  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1566  * called will return an error.
1567  *
1568  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1569  *
1570  * @param model The model to be modified.
1571  * @param index The index of the model operand we're setting.
1572  * @param buffer A pointer to the data to use.
1573  * @param memory The memory containing the data.
1574  * @param offset This specifies the location of the data within the memory.
1575  *               The offset is in bytes from the start of memory.
1576  * @param length The size in bytes of the data value.
1577  *
1578  * @return ANEURALNETWORKS_NO_ERROR if successful.
1579  */
1580 int ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel* model, int32_t index,
1581                                                    const ANeuralNetworksMemory* memory,
1582                                                    size_t offset, size_t length);
1583 
1584 /**
1585  * Add an operation to a model.
1586  *
1587  * @param model The model to be modified.
1588  * @param type The type of the operation.
1589  * @param inputCount The number of entries in the inputs array.
1590  * @param inputs An array of indexes identifying each operand.
1591  * @param outputCount The number of entries in the outputs array.
1592  * @param outputs An array of indexes identifying each operand.
1593  *
1594  * The operands specified by inputs and outputs must have been
1595  * previously added by calls to {@link ANeuralNetworksModel_addOperand}.
1596  *
1597  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1598  * called will return an error.
1599  *
1600  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1601  *
1602  * @return ANEURALNETWORKS_NO_ERROR if successful.
1603  */
1604 int ANeuralNetworksModel_addOperation(ANeuralNetworksModel* model,
1605                                       ANeuralNetworksOperationType type, uint32_t inputCount,
1606                                       const uint32_t* inputs, uint32_t outputCount,
1607                                       const uint32_t* outputs);
1608 
1609 /**
1610  * Specfifies which operands will be the model's inputs and outputs.
1611  *
1612  * An operand cannot be used for both input and output. Doing so will
1613  * return an error.
1614  *
1615  * @param model The model to be modified.
1616  * @param inputCount The number of entries in the inputs array.
1617  * @param inputs An array of indexes identifying the input operands.
1618  * @param outputCount The number of entries in the outputs array.
1619  * @param outputs An array of indexes identifying the output operands.
1620  *
1621  * The operands specified by inputs and outputs must have been
1622  * previously added by calls to {@link ANeuralNetworksModel_addOperand}.
1623  *
1624  * Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
1625  * called will return an error.
1626  *
1627  * See {@link ANeuralNetworksModel} for information on multithreaded usage.
1628  *
1629  */
1630 int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, uint32_t inputCount,
1631                                                   const uint32_t* inputs, uint32_t outputCount,
1632                                                   const uint32_t* outputs);
1633 
1634 /**
1635  * Create a {@link ANeuralNetworksCompilation} to compile the given model.
1636  *
1637  * <p>This only creates the object. Compilation is only performed once
1638  * {@link ANeuralNetworksCompilation_finish} is invoked.</p>
1639  *
1640  * <p>{@link ANeuralNetworksCompilation_finish} should be called once
1641  * all desired properties have been set on the compilation.</p>
1642  *
1643  * <p>{@link ANeuralNetworksModel_free} should be called once the compilation
1644  * is no longer needed.</p>
1645  *
1646  * <p>The provided model must outlive the compilation.</p>
1647  *
1648  * The model must already have been finished by a call to
1649  * {@link ANeuralNetworksModel_finish}.
1650  *
1651  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1652  *
1653  * @param model The {@link ANeuralNetworksModel} to be compiled.
1654  * @param compilation The newly created object or NULL if unsuccessful.
1655  *
1656  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
1657  *         if the model is invalid.
1658  */
1659 int ANeuralNetworksCompilation_create(ANeuralNetworksModel* model,
1660                                       ANeuralNetworksCompilation** compilation);
1661 
1662 /**
1663  * Destroy a compilation.
1664  *
1665  * The compilation need not have been finished by a call to
1666  * {@link ANeuralNetworksModel_finish}.
1667  *
1668  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1669  *
1670  * @param compilation The compilation to be destroyed. Passing NULL is acceptable and
1671  *                    results in no operation.
1672  */
1673 void ANeuralNetworksCompilation_free(ANeuralNetworksCompilation* compilation);
1674 
1675 /**
1676  * Sets the execution preference.
1677  *
1678  * <p>Provides guidance to the runtime when trade-offs are possible.</p>
1679  *
1680  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1681  *
1682  * @param compilation The compilation to be modified.
1683  * @param preference Either {@link PREFER_LOW_POWER},
1684  *                  {@link PREFER_SINGLE_FAST_ANSWER}, or
1685  *                  {@link PREFER_SUSTAINED_SPEED}.
1686  *
1687  * @return ANEURALNETWORKS_NO_ERROR if successful.
1688  */
1689 int ANeuralNetworksCompilation_setPreference(ANeuralNetworksCompilation* compilation,
1690                                              int32_t preference);
1691 
1692 /**
1693  * Indicate that we have finished modifying a compilation. Required before
1694  * calling {@link ANeuralNetworksExecution_create}.
1695  *
1696  * An application is responsible to make sure that no other thread uses
1697  * the compilation at the same time.
1698  *
1699  * This function must only be called once for a given compilation.
1700  *
1701  * See {@link ANeuralNetworksCompilation} for information on multithreaded usage.
1702  *
1703  * @param compilation The compilation to be finished.
1704  *
1705  * @return ANEURALNETWORKS_NO_ERROR if successful.
1706  */
1707 int ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation* compilation);
1708 
1709 /**
1710  * Create a {@link ANeuralNetworksExecution} to apply the given compilation.
1711  * This only creates the object. Computation is only performed once
1712  * {@link ANeuralNetworksExecution_startCompute} is invoked.
1713  *
1714  * <p>The provided compilation must outlive the execution.</p>
1715  *
1716  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1717  *
1718  * @param compilation The {@link ANeuralNetworksCompilation} to be evaluated.
1719  * @param execution The newly created object or NULL if unsuccessful.
1720  *
1721  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA
1722  *         if the compilation is invalid.
1723  */
1724 int ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation,
1725                                     ANeuralNetworksExecution** execution);
1726 
1727 /**
1728  * Destroy an execution.
1729  *
1730  * <p>If called on an execution for which
1731  * {@link ANeuralNetworksExecution_startCompute} has been called, the
1732  * function will return immediately but will mark the execution to be deleted
1733  * once the computation completes. The related {@link ANeuralNetworksEvent}
1734  * will be signaled and the {@link ANeuralNetworksEvent_wait} will return
1735  * ANEURALNETWORKS_ERROR_DELETED.
1736  *
1737  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1738  *
1739  * @param execution The execution to be destroyed. Passing NULL is acceptable and
1740  *                  results in no operation.
1741  */
1742 void ANeuralNetworksExecution_free(ANeuralNetworksExecution* execution);
1743 
1744 /**
1745  * Associate a user buffer with an input of the model of the
1746  * {@link ANeuralNetworksExecution}.
1747  *
1748  * <p>The provided buffer must outlive the execution.</p>
1749  *
1750  * If the input is optional, you can indicate that it is omitted by
1751  * passing nullptr for buffer and 0 for length.
1752  *
1753  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1754  *
1755  * @param execution The execution to be modified.
1756  * @param index The index of the input argument we are setting. It is
1757  *              an index into the lists passed to
1758  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1759  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1760  * @param type The type of the operand. This should be used to specify the
1761  *             dimensions that were set to 0 when the operand was added to the
1762  *             model. All other properties of the type must be the same as
1763  *             specified in the model. If the type is the same as specified
1764  *             when the model was built, NULL can be passed.
1765  * @param buffer The buffer containing the data.
1766  * @param length The length in bytes of the buffer.
1767  *
1768  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1769  *         name is not recognized or the buffer is too small for the input.
1770  */
1771 int ANeuralNetworksExecution_setInput(ANeuralNetworksExecution* execution, int32_t index,
1772                                       const ANeuralNetworksOperandType* type, const void* buffer,
1773                                       size_t length);
1774 
1775 /**
1776  * Associate part of a memory object with an input of the model of the
1777  * {@link ANeuralNetworksExecution}.
1778  *
1779  * <p>The provided memory must outlive the execution.</p>
1780  *
1781  * If the input is optional, you can indicate that it is omitted by
1782  * using @{Link ANeuralNetworks_setInput} instead, passing nullptr for buffer
1783  * and 0 for length.
1784  *
1785  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1786  *
1787  * @param execution The execution to be modified.
1788  * @param index The index of the input argument we are setting. It is
1789  *              an index into the lists passed to
1790  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1791  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1792  * @param type The type of the operand. This can be used to specify the
1793  *             dimensions that were set to 0 when the operand was added to the
1794  *             model. All other values must be the same as specified in the
1795  *             model. If the type is the same as specified when the model
1796  *             was built, NULL can be passed.
1797  * @param memory The memory containing the data.
1798  * @param offset This specifies the location of the data whithin the memory.
1799  *               The offset is in bytes from the start of memory.
1800  * @param length The size in bytes of the data value.
1801  *
1802  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1803  *         name is not recognized or the buffer is too small for the input.
1804  */
1805 int ANeuralNetworksExecution_setInputFromMemory(ANeuralNetworksExecution* execution, int32_t index,
1806                                                 const ANeuralNetworksOperandType* type,
1807                                                 const ANeuralNetworksMemory* memory, size_t offset,
1808                                                 size_t length);
1809 
1810 /**
1811  * Associate a user buffer with an output of the model of the
1812  * {@link ANeuralNetworksExecution}.
1813  *
1814  * If the output is optional, you can indicate that it is omitted by
1815  * passing nullptr for buffer and 0 for length.
1816  *
1817  * <p>The provided buffer must outlive the execution.</p>
1818  *
1819  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1820  *
1821  * @param execution The execution to be modified.
1822  * @param index The index of the output argument we are setting. It is
1823  *              an index into the lists passed to
1824  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1825  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1826  * @param type The type of the operand. This can be used to specify the
1827  *             dimensions that were set to 0 when the operand was added to the
1828  *             model. All other values must be the same as specified in the
1829  *             model. If the type is the same as specified when the model
1830  *             was built, NULL can be passed.
1831  * @param buffer The buffer where the data is to be written.
1832  * @param length The length in bytes of the buffer.
1833  *
1834  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1835  *         name is not recognized or the buffer is too small for the output.
1836  */
1837 int ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution* execution, int32_t index,
1838                                        const ANeuralNetworksOperandType* type, void* buffer,
1839                                        size_t length);
1840 
1841 /**
1842  * Associate part of a memory object with an output of the model of the
1843  * {@link ANeuralNetworksExecution}.
1844  *
1845  * If the output is optional, you can indicate that it is omitted by
1846  * using @{Link ANeuralNetworks_setOutput} instead, passing nullptr for buffer
1847  * and 0 for length.
1848  *
1849  * <p>The provided memory must outlive the execution.</p>
1850  *
1851  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1852  *
1853  * @param execution The execution to be modified.
1854  * @param index The index of the output argument we are setting. It is
1855  *              an index into the lists passed to
1856  *              {@link ANeuralNetworksModel_identifyInputsAndOutputs}. It is not
1857  *              the index associated with {@link ANeuralNetworksModel_addOperand}.
1858  * @param type The type of the operand. This can be used to specify the
1859  *             dimensions that were set to 0 when the operand was added to the
1860  *             model. All other values must be the same as specified in the
1861  *             model. If the type is the same as specified when the model
1862  *             was built, NULL can be passed.
1863  * @param memory The memory where the data is to be stored.
1864  * @param offset This specifies the location of the data whithin the memory.
1865  *               The offset is in bytes from the start of memory.
1866  * @param length The length in bytes of the data value.
1867  *
1868  * @return ANEURALNETWORKS_NO_ERROR if successful, ANEURALNETWORKS_BAD_DATA if the
1869  *         name is not recognized or the buffer is too small for the output.
1870  */
1871 int ANeuralNetworksExecution_setOutputFromMemory(ANeuralNetworksExecution* execution, int32_t index,
1872                                                  const ANeuralNetworksOperandType* type,
1873                                                  const ANeuralNetworksMemory* memory, size_t offset,
1874                                                  size_t length);
1875 
1876 /**
1877  * Schedule evaluation of the execution.
1878  *
1879  * <p>Schedules evaluation of the execution. Once the model has been
1880  * applied and the outputs are ready to be consumed, the returned event will be
1881  * signaled. Use {@link ANeuralNetworksEvent_wait} to wait for that event.
1882  * </p>
1883  *
1884  * Multiple executions can be scheduled and evaluated concurrently. The
1885  * runtime makes no guarantee on the ordering of completion of
1886  * executions. If it's important to the application, the application
1887  * should enforce the ordering by using
1888  * {@link ANeuralNetworksEvent_wait}.
1889  *
1890  * ANeuralNetworksEvent_wait must be called to recuperate the resources used
1891  * by the execution.
1892  *
1893  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1894  *
1895  * @param execution The execution to be scheduled and executed.
1896  * @param event The event that will be signaled on completion. event is set to
1897  *              NULL if there's an error.
1898  *
1899  * @return ANEURALNETWORKS_NO_ERROR if successful.
1900  */
1901 int ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution,
1902                                           ANeuralNetworksEvent** event);
1903 
1904 /**
1905  * Waits until the execution completes.
1906  *
1907  * More than one thread can wait on an event. When the execution completes,
1908  * all threads will be released.
1909  *
1910  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1911  *
1912  * @return ANEURALNETWORKS_NO_ERROR if the execution completed normally.
1913  */
1914 int ANeuralNetworksEvent_wait(ANeuralNetworksEvent* event);
1915 
1916 /**
1917  * Destroys the event.
1918  *
1919  * See {@link ANeuralNetworksExecution} for information on multithreaded usage.
1920  */
1921 void ANeuralNetworksEvent_free(ANeuralNetworksEvent* event);
1922 
1923 __END_DECLS
1924 
1925 #endif  //  __ANDROID_API__ >= 27
1926 
1927 #endif  // ANDROID_ML_NN_RUNTIME_NEURAL_NETWORKS_H
1928 
1929 /** @} */
1930