summaryrefslogtreecommitdiff
path: root/runtime/nnapi-header/include/NeuralNetworksEx.h
blob: 99f015d0f5b0f31e66d875ea444852197f2a4017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file     NeuralNetworksEx.h
 * @brief    This file contains ANeuralNetworksModel_addOperationEx function definition
 * @note     This header describes experimental feature,
 *           so specification here can be changed or/and removed
 */
#ifndef NN_RUNTIME_NEURAL_NETWORKS_EX_H
#define NN_RUNTIME_NEURAL_NETWORKS_EX_H

#include <sys/cdefs.h>

__BEGIN_DECLS

/**
 * @brief Extended operation types
 */
typedef enum {
  /** extends operation. */

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_CAST_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_CAST instead
   *
   */
  ANEURALNETWORKS_CAST_EX = 50000,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_GATHER_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_GATHER instead
   *
   */
  ANEURALNETWORKS_GATHER_EX = 50001, /**< Gather slices according to indexes and axis */

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_TOPK_V2_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_TOPK_V2 instead
   *
   */
  ANEURALNETWORKS_TOPK_V2_EX = 50002,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_REDUCE_MAX_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_REDUCE_MAX instead
   *
   */
  ANEURALNETWORKS_REDUCE_MAX_EX = 50003,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_SPLIT_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_SPLIT instead
   *
   */
  ANEURALNETWORKS_SPLIT_EX = 50004, /**< Splits a tensor into sub tensors */

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_RSQRT_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_RSQRT instead
   *
   */
  ANEURALNETWORKS_RSQRT_EX = 50005,

  /**
   * Computes element-wise squared difference on the input tensors.
   *
   * Takes two input tensors of identical {@link OperandCode} and compatible dimensions.
   * The output is the result of squaring of difference given by subtracting the second input tensor
   * from the first one.
   *
   * Two dimensions are compatible when:
   *     1. they are equal, or
   *     2. one of them is 1
   *
   * The size of the output is the maximum size along each dimension of the
   * input operands. It starts with the trailing dimensions, and works its way
   * forward.
   *
   * Supported tensor {@link OperandCode}:
   * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   *
   * Supported tensor rank: up to 4
   *
   * Inputs:
   * * 0: An n-D tensor, specifying the first input.
   * * 1: A tensor of the same {@link OperandCode}, and compatible dimensions
   *      as input0.
   *
   * Outputs:
   * * 0: The output tensor, of the same {@link OperandCode} as input0.
   */
  ANEURALNETWORKS_SQUARED_DIFFERENCE_EX = 50006,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_NEG_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_NEG instead
   *
   */
  ANEURALNETWORKS_NEG_EX = 50007,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_EXP_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_EXP instead
   *
   */
  ANEURALNETWORKS_EXP_EX = 50008,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_REDUCE_SUM_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_REDUCE_SUM instead
   *
   */
  ANEURALNETWORKS_REDUCE_SUM_EX = 50009,

  /**
   * A transposed convolutional layer carries out a regular convolution
   * but reverts its spatial transformation.
   * Transpose convolution basically performs convolution with transposed weights.
   *
   * Supported tensor {@link OperandCode}:
   * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
   *
   * Supported tensor rank: only 4
   *
   * Inputs:
   *   0: An {@link ANEURALNETWORKS_INT32} 1-D four element tensor, specifying the output shape.
   *   1: A 4-D tensor, of shape [depth_out, filter_height, filter_width, depth_in],
   *      specifying the filter.
   *   2: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
   *   3: An {@link ANEURALNETWORKS_INT32} scalar, specifying the padding type.
   *   4: An {@link ANEURALNETWORKS_INT32} scalar, specifying the stride when
   *      walking through input in the ‘width’ dimension.
   *   5: An {@link ANEURALNETWORKS_INT32} scalar, specifying the stride when
   *      walking through input in the height dimension.
   *
   * Outputs:
   *   0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
   */
  ANEURALNETWORKS_TRANSPOSE_CONV_EX = 50010,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_EQUAL_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_EQUAL instead
   *
   */
  ANEURALNETWORKS_EQUAL_EX = 50011,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_ABS_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_ABS instead
   *
   */
  ANEURALNETWORKS_ABS_EX = 50012,
  /**
   * Packs a list of rank-R tensors into one rank- (R+1) tensor along the axis dimension.
   *
   * The input tensors must have identical {@link OperandCode} and the same
   * dimensions.
   *
   * Supported tensor {@link OperandCode}:
   * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   * * {@link ANEURALNETWORKS_TENSOR_INT32}
   * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
   *
   * Supported tensor rank: up to 3
   *
   * Inputs:
   * * 0 ~ n-1: The list of n input tensors, of shape
   *            [D0, D1, ..., Daxis(i), ..., Dm]. For inputs of
   *            {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}, all input tensors
   *            must have the same scale and zeroPoint.
   * * n: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
   *      number of input tensors.
   * * n+1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
   *        pack axis.
   *
   * Outputs:
   * * 0: The output, a tensor of the same {@link OperandCode} as the input
   *      tensors. The output shape is [D0, D1, ..., N at Daxis(i), ..., Dm+1]
   *      where N is the number of tensors to be packed.
   */
  ANEURALNETWORKS_PACK_EX = 50013,
  /**
   * Unpacks a given rank-R tensors into num_splits rank- (R-1) tensors along the axis dimension.
   * num_splits has to respect integral divisibility of dimension value along axis dimension
   * of the input.
   *
   * Supported tensor {@link OperandCode}:
   * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   * * {@link ANEURALNETWORKS_TENSOR_INT32}
   * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
   *
   * Supported tensor rank: up to 4
   *
   * Inputs:
   * * 0: The input shape is [D0, D1, ..., N at Daxis(i), ..., Dm+1].
   * * 1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
   *      number of splits along unpack axis.
   * * 2: An {@link ANEURALNETWORKS_INT32} scalar, specifying the
   *      unpack axis.
   *
   * Outputs:
   * * 0 ~ n-1: The list of n output tensors, of shape
   *            [D0, D1, ..., Daxis(i), ..., Dm]. The output tensors are of the same
   *            {@link OperandCode} as the input tensor 0.
   */
  ANEURALNETWORKS_UNPACK_EX = 50014,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_ARGMAX_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_ARGMAX instead
   *
   */
  ANEURALNETWORKS_ARGMAX_EX = 50015,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_SQRT_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_SQRT instead
   *
   */
  ANEURALNETWORKS_SQRT_EX = 50016,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_NOT_EQUAL_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_NOT_EQUAL instead
   *
   */
  ANEURALNETWORKS_NOT_EQUAL_EX = 50017,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_LOGICAL_NOT_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_LOGICAL_NOT instead
   *
   */
  ANEURALNETWORKS_LOGICAL_NOT_EX = 50018,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_LOGICAL_AND_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_LOGICAL_AND instead
   *
   */
  ANEURALNETWORKS_LOGICAL_AND_EX = 50019,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_LOGICAL_OR_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_LOGICAL_OR instead
   *
   */
  ANEURALNETWORKS_LOGICAL_OR_EX = 50020,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_REDUCE_MIN_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_REDUCE_MIN instead
   *
   */
  ANEURALNETWORKS_REDUCE_MIN_EX = 50021,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_PRELU_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_PRELU instead
   *
   */
  ANEURALNETWORKS_PRELU_EX = 50022,

  /**
   * Returns a one-hot tensor.
   *
   * The locations represented by indices in indices take value on_value, while all other locations
   * take value off_value.
   * The on_value and off_value must have matching data types. They must be the same data type as
   * specified by the data type of output.
   *
   * If the input indices is rank N, the output will have rank N+1. The new axis is created at
   * dimension axis.
   * If indices is a scalar the output shape will be a vector of length depth.
   *
   * Supported tensor {@link OperandCode}:
   * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   * * {@link ANEURALNETWORKS_TENSOR_INT32}
   *
   * Supported tensor rank: up to 4
   *
   * Inputs:
   * * 0: An {@link ANEURALNETWORKS_INT32} tensor, specifying the indices.
   * * 1: An {@link ANEURALNETWORKS_INT32} scalar, specifying the depth.
   * * 2: A scalar, specifying the on_value.
   * * 3: A scalar, specifying the off_value.
   * * 4: An {@link ANEURALNETWORKS_INT32} scalar, specifying the axis to fill. Optional.
   *      (default: -1, a new inner-most axis).
   *
   * Outputs:
   * * 0: The one-hot tensor.
   */
  ANEURALNETWORKS_ONE_HOT_EX = 50023,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_GREATER_EQUAL_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_GREATER_EQUAL instead
   *
   */
  ANEURALNETWORKS_GREATER_EQUAL_EX = 50024,

  /**
   *
   * IMPORTANT NOTICE:
   * ANEURALNETWORKS_LESS_EX operation is DEPRECATED
   * Use ANEURALNETWORKS_LESS instead
   *
   */
  ANEURALNETWORKS_LESS_EX = 50025,

  /**
   * Returns the input tensor's shape as a rank 1 output tensor
   * If the input shape is [D0, D1, ..., D(N-1) ] and rank is N,
   * the output tensor is [D0, D1, ... D(N-1)], shape is [N] and rank is 1.
   *
   * Supported tensor {@link OperandCode}:
   * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
   * * {@link ANEURALNETWORKS_TENSOR_INT32}
   * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
   *
   * Supported tensor rank: virtually unlimited
   *
   * Inputs:
   * * 0: The input tensor.
   *
   * Outputs:
   * * 0: The rank-1 shape tensor.
   */
  ANEURALNETWORKS_SHAPE_EX = 50026,

} OperationCodeEx; // extends OperationCode

typedef OperationCodeEx ANeuralNetworksOperationTypeEx;

/**
 * @brief Add an extended operation to a model.
 *
 * @param[in] model The model to be modified.
 * @param[in] type The type of extended operation.
 * @param[in] inputCount The number of entries in the inputs array.
 * @param[in] inputs An array of indexes identifying each operand.
 * @param[in] outputCount The number of entries in the outputs array.
 * @param[in] outputs An array of indexes identifying each operand.
 *
 * @note The operands specified by inputs and outputs must have been
 *       previously added by calls to {@link ANeuralNetworksModel_addOperand}.\n
 *       Attempting to modify a model once {@link ANeuralNetworksModel_finish} has been
 *       called will return an error.\n
 *       See {@link ANeuralNetworksModel} for information on multithreaded usage.
 *
 * @return ANEURALNETWORKS_NO_ERROR if successful.
 */
int ANeuralNetworksModel_addOperationEx(ANeuralNetworksModel *model,
                                        ANeuralNetworksOperationTypeEx type, uint32_t inputCount,
                                        const uint32_t *inputs, uint32_t outputCount,
                                        const uint32_t *outputs);

__END_DECLS

#endif // NN_RUNTIME_NEURAL_NETWORKS_EX_H