2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright (C) 2017 The Android Open Source Project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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
24 #ifndef NN_RUNTIME_NEURAL_NETWORKS_EX_H
25 #define NN_RUNTIME_NEURAL_NETWORKS_EX_H
27 #include <sys/cdefs.h>
32 * @brief Extended operation types
35 /** extends operation. */
40 * ANEURALNETWORKS_CAST_EX operation is DEPRECATED
41 * Use ANEURALNETWORKS_CAST instead
44 ANEURALNETWORKS_CAST_EX = 50000,
49 * ANEURALNETWORKS_GATHER_EX operation is DEPRECATED
50 * Use ANEURALNETWORKS_GATHER instead
53 ANEURALNETWORKS_GATHER_EX = 50001, /**< Gather slices according to indexes and axis */
58 * ANEURALNETWORKS_TOPK_V2_EX operation is DEPRECATED
59 * Use ANEURALNETWORKS_TOPK_V2 instead
62 ANEURALNETWORKS_TOPK_V2_EX = 50002,
67 * ANEURALNETWORKS_REDUCE_MAX_EX operation is DEPRECATED
68 * Use ANEURALNETWORKS_REDUCE_MAX instead
71 ANEURALNETWORKS_REDUCE_MAX_EX = 50003,
76 * ANEURALNETWORKS_SPLIT_EX operation is DEPRECATED
77 * Use ANEURALNETWORKS_SPLIT instead
80 ANEURALNETWORKS_SPLIT_EX = 50004, /**< Splits a tensor into sub tensors */
85 * ANEURALNETWORKS_RSQRT_EX operation is DEPRECATED
86 * Use ANEURALNETWORKS_RSQRT instead
89 ANEURALNETWORKS_RSQRT_EX = 50005,
92 * Computes element-wise squared difference on the input tensors.
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
98 * Two dimensions are compatible when:
99 * 1. they are equal, or
100 * 2. one of them is 1
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
106 * Supported tensor {@link OperandCode}:
107 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
109 * Supported tensor rank: up to 4
112 * * 0: An n-D tensor, specifying the first input.
113 * * 1: A tensor of the same {@link OperandCode}, and compatible dimensions
117 * * 0: The output tensor, of the same {@link OperandCode} as input0.
119 ANEURALNETWORKS_SQUARED_DIFFERENCE_EX = 50006,
124 * ANEURALNETWORKS_NEG_EX operation is DEPRECATED
125 * Use ANEURALNETWORKS_NEG instead
128 ANEURALNETWORKS_NEG_EX = 50007,
133 * ANEURALNETWORKS_EXP_EX operation is DEPRECATED
134 * Use ANEURALNETWORKS_EXP instead
137 ANEURALNETWORKS_EXP_EX = 50008,
142 * ANEURALNETWORKS_REDUCE_SUM_EX operation is DEPRECATED
143 * Use ANEURALNETWORKS_REDUCE_SUM instead
146 ANEURALNETWORKS_REDUCE_SUM_EX = 50009,
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.
153 * Supported tensor {@link OperandCode}:
154 * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
155 * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
157 * Supported tensor rank: only 4
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.
171 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
173 ANEURALNETWORKS_TRANSPOSE_CONV_EX = 50010,
178 * ANEURALNETWORKS_EQUAL_EX operation is DEPRECATED
179 * Use ANEURALNETWORKS_EQUAL instead
182 ANEURALNETWORKS_EQUAL_EX = 50011,
187 * ANEURALNETWORKS_ABS_EX operation is DEPRECATED
188 * Use ANEURALNETWORKS_ABS instead
191 ANEURALNETWORKS_ABS_EX = 50012,
193 * Packs a list of rank-R tensors into one rank- (R+1) tensor along the axis dimension.
195 * The input tensors must have identical {@link OperandCode} and the same
198 * Supported tensor {@link OperandCode}:
199 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
200 * * {@link ANEURALNETWORKS_TENSOR_INT32}
201 * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
203 * Supported tensor rank: up to 3
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
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.
220 ANEURALNETWORKS_PACK_EX = 50013,
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
226 * Supported tensor {@link OperandCode}:
227 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
228 * * {@link ANEURALNETWORKS_TENSOR_INT32}
229 * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
231 * Supported tensor rank: up to 4
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
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.
245 ANEURALNETWORKS_UNPACK_EX = 50014,
250 * ANEURALNETWORKS_ARGMAX_EX operation is DEPRECATED
251 * Use ANEURALNETWORKS_ARGMAX instead
254 ANEURALNETWORKS_ARGMAX_EX = 50015,
259 * ANEURALNETWORKS_SQRT_EX operation is DEPRECATED
260 * Use ANEURALNETWORKS_SQRT instead
263 ANEURALNETWORKS_SQRT_EX = 50016,
268 * ANEURALNETWORKS_NOT_EQUAL_EX operation is DEPRECATED
269 * Use ANEURALNETWORKS_NOT_EQUAL instead
272 ANEURALNETWORKS_NOT_EQUAL_EX = 50017,
277 * ANEURALNETWORKS_LOGICAL_NOT_EX operation is DEPRECATED
278 * Use ANEURALNETWORKS_LOGICAL_NOT instead
281 ANEURALNETWORKS_LOGICAL_NOT_EX = 50018,
286 * ANEURALNETWORKS_LOGICAL_AND_EX operation is DEPRECATED
287 * Use ANEURALNETWORKS_LOGICAL_AND instead
290 ANEURALNETWORKS_LOGICAL_AND_EX = 50019,
295 * ANEURALNETWORKS_LOGICAL_OR_EX operation is DEPRECATED
296 * Use ANEURALNETWORKS_LOGICAL_OR instead
299 ANEURALNETWORKS_LOGICAL_OR_EX = 50020,
304 * ANEURALNETWORKS_REDUCE_MIN_EX operation is DEPRECATED
305 * Use ANEURALNETWORKS_REDUCE_MIN instead
308 ANEURALNETWORKS_REDUCE_MIN_EX = 50021,
313 * ANEURALNETWORKS_PRELU_EX operation is DEPRECATED
314 * Use ANEURALNETWORKS_PRELU instead
317 ANEURALNETWORKS_PRELU_EX = 50022,
320 * Returns a one-hot tensor.
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.
327 * If the input indices is rank N, the output will have rank N+1. The new axis is created at
329 * If indices is a scalar the output shape will be a vector of length depth.
331 * Supported tensor {@link OperandCode}:
332 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
333 * * {@link ANEURALNETWORKS_TENSOR_INT32}
335 * Supported tensor rank: up to 4
337 * Supported tensor type {@link OperandCode} for on_value and off_value:
338 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
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).
349 * * 0: The one-hot tensor.
351 ANEURALNETWORKS_ONE_HOT_EX = 50023,
356 * ANEURALNETWORKS_GREATER_EQUAL_EX operation is DEPRECATED
357 * Use ANEURALNETWORKS_GREATER_EQUAL instead
360 ANEURALNETWORKS_GREATER_EQUAL_EX = 50024,
365 * ANEURALNETWORKS_LESS_EX operation is DEPRECATED
366 * Use ANEURALNETWORKS_LESS instead
369 ANEURALNETWORKS_LESS_EX = 50025,
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.
376 * Supported tensor {@link OperandCode}:
377 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
378 * * {@link ANEURALNETWORKS_TENSOR_INT32}
379 * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
381 * Supported tensor rank: virtually unlimited
384 * * 0: The input tensor.
387 * * 0: The rank-1 shape tensor.
389 ANEURALNETWORKS_SHAPE_EX = 50026,
392 * Computes element-wise round() on the input tensor.
394 * Supported tensor {@link OperandCode}:
395 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
397 * Supported tensor rank: up to 4
403 * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
406 ANEURALNETWORKS_ROUND_EX = 50027,
409 * Reverses specific dimensions of a tensor.
411 * Supported tensor {@link OperandCode}:
412 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
414 * Supported tensor rank: up to 4
417 * * 0: A tensor to reverse.
418 * * 1: A 1-D tensor of {@link ANEURALNETWORKS_TENSOR_INT32}. The dimensions to reverse
421 * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
424 ANEURALNETWORKS_REVERSE_EX = 50028,
426 ANEURALNETWORKS_FILL_EX = 50029,
428 ANEURALNETWORKS_SELECT_V2_EX = 50030,
431 * Make the output tensor same shape to the input tensor and fill zero for all elements.
433 * Supported tensor {@link OperandCode}:
434 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
436 * Supported tensor rank: up to 4
442 * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
445 ANEURALNETWORKS_ZEROS_LIKE_EX = 50031,
448 * Computes cosine of x element-wise
450 * Supported tensor {@link OperandCode}:
451 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
453 * Supported tensor rank: up to 4
459 * * 0: The output tensor, of the same {@link OperandCode} and dimensions as
462 ANEURALNETWORKS_COS_EX = 50032,
465 * Creates a sequence of numbers
466 * that begins at 'start' and extends by increments of 'delta' up to but not including 'limit'.
468 * Supported tensor {@link OperandCode}:
469 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
471 * Supported tensor rank: up to 4
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'
479 * * 0: An 1-D output tensor
481 ANEURALNETWORKS_RANGE_EX = 50033,
483 ANEURALNETWORKS_FUSED_BATCH_NORM_V3_EX = 50034,
485 ANEURALNETWORKS_BATCH_MATMUL_EX = 50035,
488 * Copy a tensor setting everything outside a central band in each innermost matrix.
490 * Supported tensor {@link OperandCode}:
491 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
493 * Supported tensor rank: up to 4
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.
503 * * 0: An output tensor. The extracted banded tensor with the same shape as input.
505 ANEURALNETWORKS_MATRIX_BAND_PART_EX = 50036,
508 * Tensor contraction over specified indices and outer product
510 * Supported tensor {@link OperandCode}:
511 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
513 * Supported tensor rank: up to 4
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
522 * * 0: An output tensor.
524 ANEURALNETWORKS_EINSUM_EX = 50037,
526 ANEURALNETWORKS_BROADCAST_TO_EX = 50038,
528 /** Adds two tensors, element-wise.
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.
533 * Two dimensions are compatible when:
534 * 1. they are equal, or
535 * 2. one of them is 1
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.
542 * input1.dimension = {4, 1, 2}
543 * input2.dimension = {5, 4, 3, 1}
544 * output.dimension = {5, 4, 3, 2}
546 * Supported tensor types:
547 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32}
548 * * {@link ANEURALNETWORKS_TENSOR_QUANT8_ASYMM}
550 * Supported tensor rank: up to 4
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.
559 * * 0: The sum, a tensor of the same type as input0.
561 ANEURALNETWORKS_ADDV2_EX = 50039,
563 ANEURALNETWORKS_STATELESS_RANDOM_UNIFORM_EX = 50040,
565 /** Splits a tensor value into a list of sub tensors.
567 * Supported tensor {@link OperandCode}:
568 * * {@link ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32}
570 * Supported tensor rank: up to 4
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
578 * * 0: Tensor objects resulting from splitting value.
580 ANEURALNETWORKS_SPLIT_V_EX = 50041
582 } OperationCodeEx; // extends OperationCode
584 typedef OperationCodeEx ANeuralNetworksOperationTypeEx;
587 * @brief Add an extended operation to a model.
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.
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.
602 * @return ANEURALNETWORKS_NO_ERROR if successful.
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);
611 #endif // NN_RUNTIME_NEURAL_NETWORKS_EX_H