Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / nnapi-header / include / NeuralNetworksEx.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  * @file     NeuralNetworksEx.h
20  * @brief    This file contains ANeuralNetworksModel_addOperationEx function definition
21  * @note     This header describes experimental feature,
22  *           so specification here can be changed or/and removed
23  */
24 #ifndef NN_RUNTIME_NEURAL_NETWORKS_EX_H
25 #define NN_RUNTIME_NEURAL_NETWORKS_EX_H
26
27 #include <sys/cdefs.h>
28
29 __BEGIN_DECLS
30
31 /**
32  * @brief Extended operation types
33  */
34 typedef enum {
35   /** extends operation. */
36
37   /**
38    *
39    * IMPORTANT NOTICE:
40    * ANEURALNETWORKS_CAST_EX operation is DEPRECATED
41    * Use ANEURALNETWORKS_CAST instead
42    *
43    */
44   ANEURALNETWORKS_CAST_EX = 50000,
45
46   /**
47    *
48    * IMPORTANT NOTICE:
49    * ANEURALNETWORKS_GATHER_EX operation is DEPRECATED
50    * Use ANEURALNETWORKS_GATHER instead
51    *
52    */
53   ANEURALNETWORKS_GATHER_EX = 50001, /**< Gather slices according to indexes and axis */
54
55   /**
56    *
57    * IMPORTANT NOTICE:
58    * ANEURALNETWORKS_TOPK_V2_EX operation is DEPRECATED
59    * Use ANEURALNETWORKS_TOPK_V2 instead
60    *
61    */
62   ANEURALNETWORKS_TOPK_V2_EX = 50002,
63
64   /**
65    *
66    * IMPORTANT NOTICE:
67    * ANEURALNETWORKS_REDUCE_MAX_EX operation is DEPRECATED
68    * Use ANEURALNETWORKS_REDUCE_MAX instead
69    *
70    */
71   ANEURALNETWORKS_REDUCE_MAX_EX = 50003,
72
73   /**
74    *
75    * IMPORTANT NOTICE:
76    * ANEURALNETWORKS_SPLIT_EX operation is DEPRECATED
77    * Use ANEURALNETWORKS_SPLIT instead
78    *
79    */
80   ANEURALNETWORKS_SPLIT_EX = 50004, /**< Splits a tensor into sub tensors */
81
82   /**
83    *
84    * IMPORTANT NOTICE:
85    * ANEURALNETWORKS_RSQRT_EX operation is DEPRECATED
86    * Use ANEURALNETWORKS_RSQRT instead
87    *
88    */
89   ANEURALNETWORKS_RSQRT_EX = 50005,
90
91   /**
92    * Computes element-wise squared difference on the input tensors.
93    *
94    * Takes two input tensors of identical {@link OperandCode} and compatible dimensions.
95    * The output is the result of squaring of difference given by subtracting the second input tensor
96    * from the first one.
97    *
98    * Two dimensions are compatible when:
99    *     1. they are equal, or
100    *     2. one of them is 1
101    *
102    * The size of the output is the maximum size along each dimension of the
103    * input operands. It starts with the trailing dimensions, and works its way
104    * forward.
105    *
106    * Supported tensor {@link OperandCode}:
107    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
108    *
109    * Supported tensor rank: up to 4
110    *
111    * Inputs:
112    * * 0: An n-D tensor, specifying the first input.
113    * * 1: A tensor of the same {@link OperandCode}, and compatible dimensions
114    *      as input0.
115    *
116    * Outputs:
117    * * 0: The output tensor, of the same {@link OperandCode} as input0.
118    */
119   ANEURALNETWORKS_SQUARED_DIFFERENCE_EX = 50006,
120
121   /**
122    *
123    * IMPORTANT NOTICE:
124    * ANEURALNETWORKS_NEG_EX operation is DEPRECATED
125    * Use ANEURALNETWORKS_NEG instead
126    *
127    */
128   ANEURALNETWORKS_NEG_EX = 50007,
129
130   /**
131    *
132    * IMPORTANT NOTICE:
133    * ANEURALNETWORKS_EXP_EX operation is DEPRECATED
134    * Use ANEURALNETWORKS_EXP instead
135    *
136    */
137   ANEURALNETWORKS_EXP_EX = 50008,
138
139   /**
140    *
141    * IMPORTANT NOTICE:
142    * ANEURALNETWORKS_REDUCE_SUM_EX operation is DEPRECATED
143    * Use ANEURALNETWORKS_REDUCE_SUM instead
144    *
145    */
146   ANEURALNETWORKS_REDUCE_SUM_EX = 50009,
147
148   /**
149    * A transposed convolutional layer carries out a regular convolution
150    * but reverts its spatial transformation.
151    * Transpose convolution basically performs convolution with transposed weights.
152    *
153    * Supported tensor {@link OperandCode}:
154    * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
155    * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
156    *
157    * Supported tensor rank: only 4
158    *
159    * Inputs:
160    *   0: An {@link ANEURALNETWORKS_INT32} 1-D four element tensor, specifying the output shape.
161    *   1: A 4-D tensor, of shape [depth_out, filter_height, filter_width, depth_in],
162    *      specifying the filter.
163    *   2: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
164    *   3: An {@link ANEURALNETWORKS_INT32} scalar, specifying the padding type.
165    *   4: An {@link ANEURALNETWORKS_INT32} scalar, specifying the stride when
166    *      walking through input in the ‘width’ dimension.
167    *   5: An {@link ANEURALNETWORKS_INT32} scalar, specifying the stride when
168    *      walking through input in the height dimension.
169    *
170    * Outputs:
171    *   0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
172    */
173   ANEURALNETWORKS_TRANSPOSE_CONV_EX = 50010,
174
175   /**
176    *
177    * IMPORTANT NOTICE:
178    * ANEURALNETWORKS_EQUAL_EX operation is DEPRECATED
179    * Use ANEURALNETWORKS_EQUAL instead
180    *
181    */
182   ANEURALNETWORKS_EQUAL_EX = 50011,
183
184   /**
185    *
186    * IMPORTANT NOTICE:
187    * ANEURALNETWORKS_ABS_EX operation is DEPRECATED
188    * Use ANEURALNETWORKS_ABS instead
189    *
190    */
191   ANEURALNETWORKS_ABS_EX = 50012,
192   /**
193    * Packs a list of rank-R tensors into one rank- (R+1) tensor along the axis dimension.
194    *
195    * The input tensors must have identical {@link OperandCode} and the same
196    * dimensions.
197    *
198    * Supported tensor {@link OperandCode}:
199    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
200    * * {@link ANEURALNETWORKS_TENSOR_INT32}
201    * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
202    *
203    * Supported tensor rank: up to 3
204    *
205    * Inputs:
206    * * 0 ~ n-1: The list of n input tensors, of shape
207    *            [D0, D1, ..., Daxis(i), ..., Dm]. For inputs of
208    *            {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}, all input tensors
209    *            must have the same scale and zeroPoint.
210    * * n: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
211    *      number of input tensors.
212    * * n+1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
213    *        pack axis.
214    *
215    * Outputs:
216    * * 0: The output, a tensor of the same {@link OperandCode} as the input
217    *      tensors. The output shape is [D0, D1, ..., N at Daxis(i), ..., Dm+1]
218    *      where N is the number of tensors to be packed.
219    */
220   ANEURALNETWORKS_PACK_EX = 50013,
221   /**
222    * Unpacks a given rank-R tensors into num_splits rank- (R-1) tensors along the axis dimension.
223    * num_splits has to respect integral divisibility of dimension value along axis dimension
224    * of the input.
225    *
226    * Supported tensor {@link OperandCode}:
227    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
228    * * {@link ANEURALNETWORKS_TENSOR_INT32}
229    * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
230    *
231    * Supported tensor rank: up to 4
232    *
233    * Inputs:
234    * * 0: The input shape is [D0, D1, ..., N at Daxis(i), ..., Dm+1].
235    * * 1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
236    *      number of splits along unpack axis.
237    * * 2: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
238    *      unpack axis.
239    *
240    * Outputs:
241    * * 0 ~ n-1: The list of n output tensors, of shape
242    *            [D0, D1, ..., Daxis(i), ..., Dm]. The output tensors are of the same
243    *            {@link OperandCode} as the input tensor 0.
244    */
245   ANEURALNETWORKS_UNPACK_EX = 50014,
246
247   /**
248    *
249    * IMPORTANT NOTICE:
250    * ANEURALNETWORKS_ARGMAX_EX operation is DEPRECATED
251    * Use ANEURALNETWORKS_ARGMAX instead
252    *
253    */
254   ANEURALNETWORKS_ARGMAX_EX = 50015,
255
256   /**
257    *
258    * IMPORTANT NOTICE:
259    * ANEURALNETWORKS_SQRT_EX operation is DEPRECATED
260    * Use ANEURALNETWORKS_SQRT instead
261    *
262    */
263   ANEURALNETWORKS_SQRT_EX = 50016,
264
265   /**
266    *
267    * IMPORTANT NOTICE:
268    * ANEURALNETWORKS_NOT_EQUAL_EX operation is DEPRECATED
269    * Use ANEURALNETWORKS_NOT_EQUAL instead
270    *
271    */
272   ANEURALNETWORKS_NOT_EQUAL_EX = 50017,
273
274   /**
275    *
276    * IMPORTANT NOTICE:
277    * ANEURALNETWORKS_LOGICAL_NOT_EX operation is DEPRECATED
278    * Use ANEURALNETWORKS_LOGICAL_NOT instead
279    *
280    */
281   ANEURALNETWORKS_LOGICAL_NOT_EX = 50018,
282
283   /**
284    *
285    * IMPORTANT NOTICE:
286    * ANEURALNETWORKS_LOGICAL_AND_EX operation is DEPRECATED
287    * Use ANEURALNETWORKS_LOGICAL_AND instead
288    *
289    */
290   ANEURALNETWORKS_LOGICAL_AND_EX = 50019,
291
292   /**
293    *
294    * IMPORTANT NOTICE:
295    * ANEURALNETWORKS_LOGICAL_OR_EX operation is DEPRECATED
296    * Use ANEURALNETWORKS_LOGICAL_OR instead
297    *
298    */
299   ANEURALNETWORKS_LOGICAL_OR_EX = 50020,
300
301   /**
302    *
303    * IMPORTANT NOTICE:
304    * ANEURALNETWORKS_REDUCE_MIN_EX operation is DEPRECATED
305    * Use ANEURALNETWORKS_REDUCE_MIN instead
306    *
307    */
308   ANEURALNETWORKS_REDUCE_MIN_EX = 50021,
309
310   /**
311    *
312    * IMPORTANT NOTICE:
313    * ANEURALNETWORKS_PRELU_EX operation is DEPRECATED
314    * Use ANEURALNETWORKS_PRELU instead
315    *
316    */
317   ANEURALNETWORKS_PRELU_EX = 50022,
318
319   /**
320    * Returns a one-hot tensor.
321    *
322    * The locations represented by indices in indices take value on_value, while all other locations
323    * take value off_value.
324    * The on_value and off_value must have matching data types. They must be the same data type as
325    * specified by the data type of output.
326    *
327    * If the input indices is rank N, the output will have rank N+1. The new axis is created at
328    * dimension axis.
329    * If indices is a scalar the output shape will be a vector of length depth.
330    *
331    * Supported tensor {@link OperandCode}:
332    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
333    * * {@link ANEURALNETWORKS_TENSOR_INT32}
334    *
335    * Supported tensor rank: up to 4
336    *
337    * Supported tensor type {@link OperandCode} for on_value and off_value:
338    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
339    *
340    * Inputs:
341    * * 0: An {@link ANEURALNETWORKS_INT32} tensor, specifying the indices.
342    * * 1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the depth.
343    * * 2: A tensor, specifying the on_value.
344    * * 3: A tensor, specifying the off_value.
345    * * 4: An {@link ANEURALNETWORKS_INT32} scalar, specifying the axis to fill. Optional.
346    *      (default: -1, a new inner-most axis).
347    *
348    * Outputs:
349    * * 0: The one-hot tensor.
350    */
351   ANEURALNETWORKS_ONE_HOT_EX = 50023,
352
353   /**
354    *
355    * IMPORTANT NOTICE:
356    * ANEURALNETWORKS_GREATER_EQUAL_EX operation is DEPRECATED
357    * Use ANEURALNETWORKS_GREATER_EQUAL instead
358    *
359    */
360   ANEURALNETWORKS_GREATER_EQUAL_EX = 50024,
361
362   /**
363    *
364    * IMPORTANT NOTICE:
365    * ANEURALNETWORKS_LESS_EX operation is DEPRECATED
366    * Use ANEURALNETWORKS_LESS instead
367    *
368    */
369   ANEURALNETWORKS_LESS_EX = 50025,
370
371   /**
372    * Returns the input tensor's shape as a rank 1 output tensor
373    * If the input shape is [D0, D1, ..., D(N-1) ] and rank is N,
374    * the output tensor is [D0, D1, ... D(N-1)], shape is [N] and rank is 1.
375    *
376    * Supported tensor {@link OperandCode}:
377    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
378    * * {@link ANEURALNETWORKS_TENSOR_INT32}
379    * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
380    *
381    * Supported tensor rank: virtually unlimited
382    *
383    * Inputs:
384    * * 0: The input tensor.
385    *
386    * Outputs:
387    * * 0: The rank-1 shape tensor.
388    */
389   ANEURALNETWORKS_SHAPE_EX = 50026,
390
391   /**
392    * Computes element-wise round() on the input tensor.
393    *
394    * Supported tensor {@link OperandCode}:
395    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
396    *
397    * Supported tensor rank: up to 4
398    *
399    * Inputs:
400    * * 0: A tensor.
401    *
402    * Outputs:
403    * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
404    *      the input tensor.
405    */
406   ANEURALNETWORKS_ROUND_EX = 50027,
407
408   /**
409    * Reverses specific dimensions of a tensor.
410    *
411    * Supported tensor {@link OperandCode}:
412    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
413    *
414    * Supported tensor rank: up to 4
415    *
416    * Inputs:
417    * * 0: A tensor to reverse.
418    * * 1: A 1-D tensor of {@link ANEURALNETWORKS_TENSOR_INT32}. The dimensions to reverse
419    *
420    * Outputs:
421    * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
422    *      the input tensor.
423    */
424   ANEURALNETWORKS_REVERSE_EX = 50028,
425
426   ANEURALNETWORKS_FILL_EX = 50029,
427
428   ANEURALNETWORKS_SELECT_V2_EX = 50030,
429
430   /**
431    * Make the output tensor same shape to the input tensor and fill zero for all elements.
432    *
433    * Supported tensor {@link OperandCode}:
434    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
435    *
436    * Supported tensor rank: up to 4
437    *
438    * Inputs:
439    * * 0: A tensor.
440    *
441    * Outputs:
442    * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
443    *      the input tensor.
444    */
445   ANEURALNETWORKS_ZEROS_LIKE_EX = 50031,
446
447   /**
448    * Computes cosine of x element-wise
449    *
450    * Supported tensor {@link OperandCode}:
451    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
452    *
453    * Supported tensor rank: up to 4
454    *
455    * Inputs:
456    * * 0: A tensor.
457    *
458    * Outputs:
459    * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
460    *      the input tensor.
461    */
462   ANEURALNETWORKS_COS_EX = 50032,
463
464   /**
465    * Creates a sequence of numbers
466    * that begins at 'start' and extends by increments of 'delta' up to but not including 'limit'.
467    *
468    * Supported tensor {@link OperandCode}:
469    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
470    *
471    * Supported tensor rank: up to 4
472    *
473    * Inputs:
474    * * 0: A 0-D Tensor (scalar). 'start' acts as first entry in the range
475    * * 1: A 0-D Tensor (scalar). 'limit' acts as upper limit of sequence
476    * * 2: A 0-D Tensor (scalar). 'delta' acts as number that increments 'start'
477    *
478    * Outputs:
479    * * 0: An 1-D output tensor
480    */
481   ANEURALNETWORKS_RANGE_EX = 50033,
482
483   ANEURALNETWORKS_FUSED_BATCH_NORM_V3_EX = 50034,
484
485   ANEURALNETWORKS_BATCH_MATMUL_EX = 50035,
486
487   /**
488    * Copy a tensor setting everything outside a central band in each innermost matrix.
489    *
490    * Supported tensor {@link OperandCode}:
491    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
492    *
493    * Supported tensor rank: up to 4
494    *
495    * Inputs:
496    * * 0: A tensor.
497    * * 1: An {@link ANEURALNETWORKS_INT32} scalar. Number of subdiagonals to keep. If negative, keep
498    * entire lower triangle.
499    * * 2: An {@link ANEURALNETWORKS_INT32} scalar. Number of superdiagonals to keep. If negative,
500    * keep entire upper triangle.
501    *
502    * Outputs:
503    * * 0: An output tensor. The extracted banded tensor with the same shape as input.
504    */
505   ANEURALNETWORKS_MATRIX_BAND_PART_EX = 50036,
506
507   /**
508    * Tensor contraction over specified indices and outer product
509    *
510    * Supported tensor {@link OperandCode}:
511    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
512    *
513    * Supported tensor rank: up to 4
514    *
515    * Inputs:
516    * * 0 ~ n-1: The list of n input tensors.
517    * * 1: An 1-D tensor of {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}. Each element represent
518    * equation character.
519    *      Always scalar is 1.0 and zeroPoint is 0
520    *
521    * Outputs:
522    * * 0: An output tensor.
523    */
524   ANEURALNETWORKS_EINSUM_EX = 50037,
525
526   ANEURALNETWORKS_BROADCAST_TO_EX = 50038,
527
528   /** Adds two tensors, element-wise.
529    *
530    * Takes two input tensors of identical type and compatible dimensions. The output
531    * is the sum of both input tensors, optionally modified by an activation function.
532    *
533    * Two dimensions are compatible when:
534    *     1. they are equal, or
535    *     2. one of them is 1
536    *
537    * The size of the output is the maximum size along each dimension of the input operands.
538    * It starts with the trailing dimensions, and works its way forward.
539    *
540    * Example:
541    *
542    *     input1.dimension = {4, 1, 2}
543    *     input2.dimension = {5, 4, 3, 1}
544    *     output.dimension = {5, 4, 3, 2}
545    *
546    * Supported tensor types:
547    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
548    * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
549    *
550    * Supported tensor rank: up to 4
551    *
552    * Inputs:
553    * * 0: A tensor.
554    * * 1: A tensor of the same type, and compatible dimensions as input0.
555    * * 2: An INT32 value, and has to be one of the {@link FuseCode} values.
556    *      Specifies the activation to invoke on the result of each addition.
557    *
558    * Outputs:
559    * * 0: The sum, a tensor of the same type as input0.
560    */
561   ANEURALNETWORKS_ADDV2_EX = 50039,
562
563   ANEURALNETWORKS_STATELESS_RANDOM_UNIFORM_EX = 50040,
564
565   /** Splits a tensor value into a list of sub tensors.
566    *
567    * Supported tensor {@link OperandCode}:
568    * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
569    *
570    * Supported tensor rank: up to 4
571    *
572    * Inputs:
573    * * 0: A tensor to split.
574    * * 1: A tensor containing the sizes of each output tensor along split_dim
575    * * 2: The dimension along which to split
576    *
577    * Outputs:
578    * * 0: Tensor objects resulting from splitting value.
579    */
580   ANEURALNETWORKS_SPLIT_V_EX = 50041
581
582 } OperationCodeEx; // extends OperationCode
583
584 typedef OperationCodeEx ANeuralNetworksOperationTypeEx;
585
586 /**
587  * @brief Add an extended operation to a model.
588  *
589  * @param[in] model The model to be modified.
590  * @param[in] type The type of extended operation.
591  * @param[in] inputCount The number of entries in the inputs array.
592  * @param[in] inputs An array of indexes identifying each operand.
593  * @param[in] outputCount The number of entries in the outputs array.
594  * @param[in] outputs An array of indexes identifying each operand.
595  *
596  * @note The operands specified by inputs and outputs must have been
597  *       previously added by calls to {@link ANeuralNetworksModel_addOperand}.\n
598  *       Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
599  *       called will return an error.\n
600  *       See {@link ANeuralNetworksModel} for information on multithreaded usage.
601  *
602  * @return ANEURALNETWORKS_NO_ERROR if successful.
603  */
604 int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model,
605                                         ANeuralNetworksOperationTypeEx type, uint32_t inputCount,
606                                         const uint32_t *inputs, uint32_t outputCount,
607                                         const uint32_t *outputs);
608
609 __END_DECLS
610
611 #endif // NN_RUNTIME_NEURAL_NETWORKS_EX_H