2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.hardware.neuralnetworks@1.0;
22 * The type of an operand in a model.
24 * Types prefaced with TENSOR_* must be used for tensor data (i.e., tensors
25 * with at least one dimension). Types not prefaced by TENSOR_* represent
26 * scalar values and must have no dimensions.
28 enum OperandType : int32_t {
30 * The following entries are used to declare scalars.
37 * The following entries are used to declare tensors.
43 * A tensor of 8 bit integers that represent real numbers.
45 * Attached to this tensor are two numbers that can be used to convert the
46 * 8 bit integer to the real value and vice versa. These two numbers are:
47 * - scale: a 32 bit floating point value
48 * - zero_value: a 32 bit integer
51 * real_value = (integer_value - zero_value) * scale.
53 TENSOR_QUANT8_ASYMM = 5,
56 * The following entries are OEM specific operand types.
59 TENSOR_OEM_BYTE = 10001,
65 * The type of an operation in a model.
67 enum OperationType : int32_t {
69 * Adds two tensors, elment-wise.
71 * Takes two input tensors of identical type and compatible dimensions. The output
72 * is the sum of both input tensors, optionally modified by an activation function.
74 * Two dimensions are compatible when:
75 * 1. they are equal, or
78 * The size of the output is the maximum size along each dimension of the input operands.
79 * It starts with the trailing dimensions, and works its way forward.
82 * input1.dimension = {4, 1, 2}
83 * input2.dimension = {5, 4, 3, 1}
84 * output.dimension = {5, 4, 3, 2}
86 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
87 * Supported tensor rank: up to 4
91 * 1: A tensor of the same type, and compatible dimensions as input0.
92 * 2: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
93 * Specifies the activation to invoke on the result of each addition.
96 * 0: The sum, a tensor of the same type as input0.
101 * Performs a 2-D average pooling operation.
103 * The output dimensions are functions of the filter dimensions, stride, and padding.
105 * The values in output Tensor is computed as:
106 * output[batch, row, col, channel] =
107 * sum_{i, j}(input[batch, row + i, col + j, channel]) / sum(1)
109 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
110 * {@link OperandType::TENSOR_QUANT8_ASYMM}
111 * Supported tensor rank: 4, with "NHWC" data layout.
114 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
115 * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
116 * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
117 * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
118 * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
119 * 5: An INT32 value, specifying the output stride in the ‘width’ dimension.
120 * 6: An INT32 value, specifying the output stride in the ‘height’ dimension.
121 * 7: An INT32 value, specifying the filter width.
122 * 8: An INT32 value, specifying the filter height.
123 * 9: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
124 * Specifies the activation to invoke on the result of each addition.
127 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
132 * Concatenates the input tensors along the given dimension.
134 * The input tensors must have identical type and the same dimensions except the
135 * dimension along the concatenation axis.
137 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
138 * {@link OperandType::TENSOR_QUANT8_ASYMM}
139 * Supported tensor rank: up to 4
142 * 0 ~ n: The list on n input tensors, of shape [D0, D1, ..., Daxis(i), ..., Dm]
143 * n+1: An INT32 value, specifying the concatenation axis.
144 * n+2: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
145 * Specifies the activation to invoke on the result of each addition.
148 * 0: The output, a tensor of the same type as the input tensors.
149 The output shape is [D0, D1, ..., sum(Daxis(i)), ..., Dm].
154 * Performs an 2-D convolution operation.
156 * The CONV_2D op sweeps a 2-D filter that can mix channels together over a batch of
157 * images, applying the filter to each window of each image of the appropriate size.
159 * The output dimensions are functions of the filter dimensions, stride, and padding.
161 * The values in output Tensor is computed as:
162 * output[batch, row, col, channel] =
164 * input[batch, row + i, col + j, k] *
165 * filter[channel, row + i, col + j, k] +
169 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
170 * {@link OperandType::TENSOR_QUANT8_ASYMM}
171 * Supported tensor rank: 4, with "NHWC" data layout.
174 * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
175 * 1: A 4-D tensor, of shape [depth_out, filter_height, filter_width, depth_in],
176 * specifying the filter.
177 * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
178 * For input tensor of {@link OperandType::TENSOR_FLOAT32} type, the bias should
179 * also be of {@link OperandType::TENSOR_FLOAT32}.
180 * For input tensor of {@link OperandType::TENSOR_QUANT8_ASYMM} type, the bias
181 * should be of {@link OperandType::TENSOR_INT32}.
182 * 3: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
183 * 4: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
184 * 5: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
185 * 6: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
186 * 7: An INT32 value, specifying the output stride in the ‘width’ dimension.
187 * 8: An INT32 value, specifying the output stride in the ‘height’ dimension.
188 * 9: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
189 * Specifies the activation to invoke on the result of each addition.
192 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
197 * Performs an depthwise 2-D convolution operation.
199 * Given an input tensor of shape [batches, height, width, depth_in] and a filter
200 * tensor of shape [depth_out, filter_height, filter_width, depth_in] containing
201 * in_channels convolutional filters of depth 1, DEPTHWISE_CONV applies a different
202 * filter to each input channel (expanding from 1 channel to channel_multiplier channels
203 * for each), then concatenates the results together.
205 * The output has depth_out = depth_in * depth_multiplier channels.
206 * The output dimensions are functions of the filter dimensions, stride, and padding.
208 * The values in output Tensor is computed as:
209 * output[b, i, j, k * channel_multiplier + q] =
211 * input[b, strides[1] * i + di, strides[2] * j + dj, k] *
212 * filter[di, dj, k, q]
215 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
216 * {@link OperandType::TENSOR_QUANT8_ASYMM}
217 * Supported tensor rank: 4, with "NHWC" data layout.
220 * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
221 * 1: A 4-D tensor, of shape [1, filter_height, filter_width, depth_out],
222 * specifying the filter.
223 * 2: A 1-D tensor, of shape [depth_out], specifying the bias.
224 * For input tensor of {@link OperandType::TENSOR_FLOAT32} type, the bias should
225 * also be of {@link OperandType::TENSOR_FLOAT32}.
226 * For input tensor of {@link OperandType::TENSOR_QUANT8_ASYMM} type, the bias
227 * should be of {@link OperandType::TENSOR_INT32}.
228 * 3: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
229 * 4: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
230 * 5: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
231 * 6: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
232 * 7: An INT32 value, specifying the output stride in the ‘width’ dimension.
233 * 8: An INT32 value, specifying the output stride in the ‘height’ dimension.
234 * 9: An INT32 value, specifying the depthwise multiplier.
235 * 10: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
236 * Specifies the activation to invoke on the result of each addition.
239 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out].
241 DEPTHWISE_CONV_2D = 4,
244 * Rearranges data from depth into blocks of spatial data.
246 * More specifically, this op outputs a copy of the input tensor where values from
247 * the depth dimension are moved in spatial blocks to the height and width dimensions.
248 * The value block_size indicates the input block size and how the data is moved.
250 * Chunks of data of size block_size * block_size from depth are rearranged into
251 * non-overlapping blocks of size block_size x block_size.
253 * The width of the output tensor is input_depth * block_size, whereas the height is
254 * input_height * block_size.
255 * The depth of the input tensor must be divisible by block_size * block_size
257 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
258 * {@link OperandType::TENSOR_QUANT8_ASYMM}
259 * Supported tensor rank: 4, with "NHWC" data layout.
262 * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
263 * 1: An INT32 value, specifying the block_size. block_size must be >=1 and
264 * block_size * block_size must be a divisor of the input depth.
267 * 0: The output 4-D tensor, of shape [batch, height*block_size, width*block_size,
268 * depth/(block_size*block_size)].
273 * Dequantizes the input tensor.
276 * output = (input - zero_value) * scale.
278 * Supported tensor types: {@link OperandType::TENSOR_QUANT8_ASYMM}
279 * Supported tensor rank: up to 4
282 * 0: A tensor of type {@link OperandType::TENSOR_QUANT8_ASYMM}.
285 * 0: The output tensor of same shape as input0, but with type
286 {@link OperandType::TENSOR_FLOAT32}.
291 * Looks up items from a given tensor.
293 * Each item in the output is a raw copy of the corresponding item in
294 * the input “values”. If the the given “lookup” indices are out of bounds,
295 * the op will fail and an error will be reported.
298 * * 0: Values. An n-D tensor of any type X (where n >= 2). E.g., if n is 2,
299 * then the shape would be [lookup_dimension, values_dimension], where
300 * “lookup_dimension” corresponds to the indexing dimension in the lookup
301 * table, and “values_dimension” to the contents.
302 * * 1: Lookups. An 1-D tensor of type T, of shape [lookup_size], where
303 * “lookup_size” is the number of elements to look for, and each entry
304 * corresponds to the first dimension of the “values” tensor.
307 * * 0: A n-D tensor of type X and the same rank and shape as the “values”
308 * tensor, except for the first dimension which has size “lookup_size”.
310 EMBEDDING_LOOKUP = 7,
313 * Computes element-wise floor() on the input tensor.
315 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
316 * Supported tensor rank: up to 4
322 * 0: The output, a tensor of the same type and dimensions as input0.
327 * Denotes a fully (densely) connected layer, which connects all elements in the input
328 * tensor with each element in the output tensor.
330 * This layer implements the operation:
331 * outputs = activation(inputs * weights’ + bias)
333 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
334 * {@link OperandType::TENSOR_QUANT8_ASYMM}
335 * Supported tensor rank: up to 4.
338 * 0: A tensor, specifying the input. If rank is greater than 2, then it gets flattened to
339 * a 2-D Tensor. The 2-D Tensor is handled as if dimensions corresponded to shape
340 * [batch_size, input_size], where “batch_size” corresponds to the batching dimension,
341 * and “input_size” is the size of the input.
342 * 1: A 2-D tensor, specifying the weights, of shape [num_units, input_size], where “num_units”
343 * corresponds to the number of output nodes.
344 * 2: A 1-D tensor, of shape [num_units], specifying the bias.
345 * For input tensor of {@link OperandType::TENSOR_FLOAT32} type, the bias should
346 * also be of {@link OperandType::TENSOR_FLOAT32}.
347 * For input tensor of {@link OperandType::TENSOR_QUANT8_ASYMM} type, the bias
348 * should be of {@link OperandType::TENSOR_INT32}.
349 * 3: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
350 * Specifies the activation to invoke on the result of each addition.
353 * 0: The output tensor, of shape [batch_size, num_units].
358 * Looks up values of a hash table with given keys.
361 * * 0: Lookups. A 1-D int32 tensor with shape [ k ].
362 * * 1: Keys. A 1-D int32 tensor with shape [ n ], *MUST* be sorted in
364 * * 2: Values. A tensor with shape [ n … ].
367 * * 0: Output. A tensor with shape [ k …].
368 * * 1: Hits. A uint8 tensor with shape [ k ] indicates whether the lookup
371 HASHTABLE_LOOKUP = 10,
374 * Applies L2 normalization along a the depth dimension.
376 * The values in output Tensor is computed as:
377 * output[batch, row, col, channel] =
378 * input[batch, row, col, channel] /
379 * sqrt(sum_{c} pow(input[batch, row, col, c], 2))
381 * For x with more dimensions, independently normalizes each 1-D slice along dimension dim.
383 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
384 * Supported tensor rank: 4, with "NHWC" data layout.
387 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
390 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
392 L2_NORMALIZATION = 11,
395 * Performs an 2-D L2 pooling operation.
397 * The output dimensions are functions of the filter dimensions, stride, and padding.
399 * The values in output Tensor is computed as:
400 * output[batch, row, col, channel] =
401 * sqrt(sum_{i, j} pow(input[batch, row + i, col + j, channel], 2) / sum(1))
403 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
404 * Supported tensor rank: 4, with "NHWC" data layout.
407 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
408 * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
409 * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
410 * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
411 * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
412 * 5: An INT32 value, specifying the output stride in the ‘width’ dimension.
413 * 6: An INT32 value, specifying the output stride in the ‘height’ dimension.
414 * 7: An INT32 value, specifying the filter width.
415 * 8: An INT32 value, specifying the filter height.
416 * 9: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
417 * Specifies the activation to invoke on the result of each addition.
420 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
425 * Applies Local Response Normalization along the depth dimension.
427 * The 4-D input tensor is treated as a 3-D array of 1-D vectors (along the last
428 * dimension), and each vector is normalized independently. Within a given vector,
429 * each component is divided by the weighted, squared sum of inputs within depth_radius.
432 * sqr_sum[a, b, c, d] =
433 * sum(pow(input[a, b, c, d - depth_radius : d + depth_radius + 1], 2)
434 * output = input / pow((bias + alpha * sqr_sum), beta)
436 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
437 * Supported tensor rank: 4, with "NHWC" data layout.
440 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
441 * 1: An INT32 value, specifying the radius of the normalization window.
442 * 2: A FLOAT32 value, specifying the bias, must not be zero.
443 * 3: A FLOAT32 value, specifying the scale factor, alpha.
444 * 4: A FLOAT32 value, specifying the exponent, beta.
447 * 0: The output tensor of same shape as input0.
449 LOCAL_RESPONSE_NORMALIZATION = 13,
452 * Computes sigmoid activation on the input tensor element-wise.
455 * output = 1 / (1 + exp(-input))
457 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
458 * {@link OperandType::TENSOR_QUANT8_ASYMM}
459 * Supported tensor rank: up to 4.
462 * 0: A tensor, specifying the input.
465 * 0: The output tensor of same shape as input0.
470 * Projects an input to a bit vector via locality senstive hashing.
473 * * 0: Hash functions. Dim.size == 2, DataType: Float.
474 * Tensor[0].Dim[0]: Number of hash functions.
475 * Tensor[0].Dim[1]: Number of seeds per hash functions.
476 * Tensor[0].Dim[1] <= 32 in sparse case.
478 * * 1: Input. Dim.size >= 1, no restriction on DataType.
479 * * 2: Weight. Optional. Dim.size == 1, DataType: Float.
480 * If not set, each input element is considered to have the same weight of
482 * Tensor[1].Dim[0] == Tensor[2].Dim[0]
484 * Sparse: Value LSHProjectionType_SPARSE(=1).
485 * Computed bit vector is considered to be sparse.
486 * Each output element is an int32 made up of multiple bits computed from
489 * Dense: Value LSHProjectionType_DENSE(=2).
490 * Computed bit vector is considered to be dense. Each output element
491 * represents a bit and can take the value of either 0 or 1.
494 * * 0: If the projection type is sparse:
495 * Output.Dim == { Tensor[0].Dim[0] }
496 * A tensor of int32 that represents hash signatures.
497 * If the projection type is Dense:
498 * Output.Dim == { Tensor[0].Dim[0] * Tensor[0].Dim[1] }
499 * A flattened tensor that represents projected bit vectors.
504 * Long short-term memory unit (LSTM) recurrent network layer.
506 * The default non-peephole implementation is based on:
507 * http://deeplearning.cs.cmu.edu/pdfs/Hochreiter97_lstm.pdf
508 * S. Hochreiter and J. Schmidhuber. "Long Short-Term Memory". Neural
509 * Computation, 9(8):1735-1780, 1997.
511 * The peephole implementation is based on:
512 * https://research.google.com/pubs/archive/43905.pdf
513 * Hasim Sak, Andrew Senior, and Francoise Beaufays. "Long short-term memory
514 * recurrent neural network architectures for large scale acoustic modeling."
517 * The coupling of input and forget gate (CIFG) is based on:
518 * http://arxiv.org/pdf/1503.04069.pdf
519 * Greff et al. "LSTM: A Search Space Odyssey"
521 * The class has the following independently optional inputs:
522 * * If input gate (if CIFG): “input_to_forget_weights”,
523 * “recurrent_to_input_weights”, “cell_to_input_weights”, “input_gate_bias”.
524 * * If no peephole connections: “cell_to_input_weights”,
525 * “cell_to_forget_weights”, “cell_to_output_weights”.
526 * * If no projection layer: “projection_weights” and “projection_bias”.
527 * * If no projection bias: “projection_bias”.
529 * Supported tensor types:
530 * * {@link OperandType::TENSOR_FLOAT32}
534 * A 2-D tensor of type T, of shape [batch_size, input_size], where
535 * “batch_size” corresponds to the batching dimension, and “input_size”
536 * is the size of the input.
537 * * 1: input_to_input_weights.
538 * A 2-D tensor of type T, of shape [num_units, input_size], where
539 * “num_units” corresponds to the number of cell units.
540 * * 2: input_to_forget_weights.
541 * A 2-D tensor of type T, of shape [num_units, input_size].
542 * * 3: input_to_cell_weights.
543 * A 2-D tensor of type T, of shape [num_units, input_size].
544 * * 4: input_to_output_weights.
545 * A 2-D tensor of type T, of shape [num_units, input_size].
546 * * 5: recurrent_to_input_weights.
547 * A 2-D tensor of type T, of shape [num_units, output_size], where
548 * “output_size” corresponds to either the number of cell units (i.e.,
549 * “num_units”), or the second dimension of the “projection_weights”, if
551 * * 6: recurrent_to_forget_weights.
552 * A 2-D tensor of type T, of shape [num_units, output_size].
553 * * 7: recurrent_to_cell_weights.
554 * A 2-D tensor of type T, of shape [num_units, output_size].
555 * * 8: recurrent_to_output_weights.
556 * A 2-D tensor of type T, of shape [num_units, output_size].
557 * * 9: cell_to_input_weights.
558 * A 1-D tensor of type T, of shape [num_units].
559 * * 10:cell_to_forget_weights.
560 * A 1-D tensor of type T, of shape [num_units].
561 * * 11:cell_to_output_weights.
562 * A 1-D tensor of type T, of shape [num_units].
563 * * 12:input_gate_bias.
564 * A 1-D tensor of type T, of shape [num_units].
565 * * 13:forget_gate_bias.
566 * A 1-D tensor of type T, of shape [num_units].
568 * A 1-D tensor of type T, of shape [num_units].
569 * * 15:output_gate_bias.
570 * A 1-D tensor of type T, of shape [num_units].
571 * * 16:projection_weights.
572 * A 2-D tensor of type T, of shape [output_size, num_units].
573 * * 17:projection_bias.
574 * A 1-D tensor of type T, of shape [output_size].
577 * * 18:fused_activation_function.
578 * An (optional) ActivationFunctionType indicating the activation
580 * If “NONE” is specified then it results in a linear activation.
582 * A clipping threshold for the cell state, such that values are bound
583 * within [-cell_clip, cell_clip]. If set to 0.0 then clipping is
586 * A clipping threshold for the output from the projection layer, such
587 * that values are bound within [-proj_clip, proj_clip]. If set to 0.0
588 * then clipping is disabled.
591 * * 0: scratch_buffer.
592 * A 3-D tensor of type T, of shape [batch_size, num_cell, 4].
594 * A 2-D tensor of type T, of shape [batch_size, output_size].
596 * A 2-D tensor of type T, of shape [batch_size, num_units].
598 * A 2-D tensor of type T, of shape [batch_size, output_size]. This is
599 * effectively the same as the current “output_state” value.
604 * Performs an 2-D max pooling operation.
606 * The output dimensions are functions of the filter dimensions, stride, and padding.
608 * The values in output Tensor is computed as:
609 * output[batch, row, col, channel] =
610 * max_{i, j} (input[batch, row + i, col + j, channel])
612 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
613 * {@link OperandType::TENSOR_QUANT8_ASYMM}
614 * Supported tensor rank: 4, with "NHWC" data layout.
617 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
618 * 1: An INT32 value, specifying the padding on the left, in the ‘width’ dimension.
619 * 2: An INT32 value, specifying the padding on the right,in the ‘width’ dimension.
620 * 3: An INT32 value, specifying the padding on the top, in the ‘height’ dimension.
621 * 4: An INT32 value, specifying the padding on the bottom, in the ‘height’ dimension.
622 * 5: An INT32 value, specifying the output stride in the ‘width’ dimension.
623 * 6: An INT32 value, specifying the output stride in the ‘height’ dimension.
624 * 7: An INT32 value, specifying the filter width.
625 * 8: An INT32 value, specifying the filter height.
626 * 9: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
627 * Specifies the activation to invoke on the result of each addition.
630 * 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth].
635 * Multiplies two tensors, elment-wise.
637 * Takes two input tensors of identical type and compatible dimensions. The output
638 * is the product of both input tensors, optionally modified by an activation function.
640 * Two dimensions are compatible when:
641 * 1. they are equal, or
642 * 2. one of them is 1
644 * The size of the resulting output is the maximum size along each dimension of the
645 * input operands. It starts with the trailing dimensions, and works its way forward.
647 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
648 * Supported tensor rank: up to 4
652 * 1: A tensor of the same type, and compatible dimensions as input0.
653 * 2: An INT32 value, and has to be one of the {@link FusedActivationFunc} values.
654 * Specifies the activation to invoke on the result of each addition.
657 * 0: The product, a tensor of the same type as input0.
662 * Computes rectified linear activation on the input tensor element-wise.
665 * output = max(0, input)
667 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
668 * {@link OperandType::TENSOR_QUANT8_ASYMM}
669 * Supported tensor rank: up to 4.
672 * 0: A tensor, specifying the input.
675 * 0: The output tensor of same shape as input0.
680 * Computes rectified linear 1 activation on the input tensor element-wise.
683 * output = min(1.f, max(-1.f, input))
685 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
686 * {@link OperandType::TENSOR_QUANT8_ASYMM}
687 * Supported tensor rank: up to 4.
690 * 0: A tensor, specifying the input.
693 * 0: The output tensor of same shape as input0.
698 * Computes rectified linear 6 activation on the input tensor element-wise.
701 * output = min(6, max(0, input))
703 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
704 * {@link OperandType::TENSOR_QUANT8_ASYMM}
705 * Supported tensor rank: up to 4.
708 * 0: A tensor, specifying the input.
711 * 0: The output tensor of same shape as input0.
718 * Given tensor, this operation returns a tensor that has the same values as tensor,
719 * but with a newly specified shape.
721 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
722 * {@link OperandType::TENSOR_QUANT8_ASYMM}
723 * Supported tensor rank: up to 4.
726 * 0: A tensor, specifying the tensor to be reshaped.
727 * 1: A 1-D tensor of type {@link OperandType::TENSOR_INT32}, defining the shape
728 * of the output tensor. The number of elements implied by shape must be the same
729 * as the number of elements in the input tensor.
732 * 0: The output tensor, of shape specified by the input shape.
737 * Resizes images to given size using the bilinear interpretation.
739 * Resized images will be distorted if their original aspect ratio is not the same as input.
741 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
742 * Supported tensor rank: 4, with "NHWC" data layout.
745 * 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input.
746 * 1: An INT32 value, specifying the output width of the output tensor.
747 * 2: An INT32 value, specifying the output height of the output tensor.
750 * 0: The output 4-D tensor, of shape [batches, new_height, new_width, depth].
752 RESIZE_BILINEAR = 23,
755 * A basic recurrent neural network layer.
757 * This layer implements the operation:
758 * outputs = state = activation(inputs * input_weights + state * recurrent_weights + bias)
761 * * “input_weights” is a weight matrix that multiplies the inputs;
762 * * “recurrent_weights” is a weight matrix that multiplies the current
763 * “state” which itself is the output from the previous time step
765 * * “bias” is a bias vector (added to each output vector in the batch);
766 * * “activation” is the function passed as the “fused_activation_function”
767 * argument (if not “NONE”).
769 * Supported tensor types:
770 * * {@link OperandType::TENSOR_FLOAT32}
774 * A 2-D tensor of type T, of shape [batch_size, input_size], where
775 * “batch_size” corresponds to the batching dimension, and “input_size” is
776 * the size of the input.
778 * A 2-D tensor of type T, of shape [num_units, input_size], where
779 * “num_units” corresponds to the number of units.
780 * * 2: recurrent_weights.
781 * A 2-D tensor of type T, of shape [num_units, num_units], with columns
782 * corresponding to the weights from each unit.
784 * A 1-D tensor of type T, of shape [num_units].
786 * For FLOAT32 input tensor, bias must also be FLOAT32.
787 * For UINT8 input tensor, bias must be INT32.
790 * * 4: fused_activation_function.
791 * An (optional) ActivationFunctionType indicating the activation
792 * function. If “NONE” is specified then it results in a linear
796 * A 2-D tensor of type T, of shape [batch_size, num_units].
800 * A 2-D tensor of type T, of shape [batch_size, num_units]. This is
801 * effectively the same as the current state value.
806 * Computes the softmax activation on the input tensor element-wise, per batch, by
807 * normalizing the input vector so the maximum coefficient is zero.
811 * exp((input[batch, i] - max(input[batch, :])) * beta) /
812 * sum_{k}{exp((input[batch, k] - max(input[batch, :])) * beta)}
814 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
815 * {@link OperandType::TENSOR_QUANT8_ASYMM}
816 * Supported tensor rank: 2 or 4.
819 * 0: A 2-D or 4-D tensor, specifying the tensor to be reshaped.
820 * 1: A FLOAT32 value, specifying the scaling factor for the exponent, beta.
823 * 0: The output tensor of same shape as input0.
828 * Rearranges blocks of spatial data, into depth.
830 * More specifically, this op outputs a copy of the input tensor where values from
831 * the height and width dimensions are moved to the depth dimension.
832 * The value block_size indicates the input block size and how the data is moved.
834 * Chunks of data of size block_size * block_size from depth are rearranged into
835 * non-overlapping blocks of size block_size x block_size.
837 * The depth of the output tensor is input_depth * block_size * block_size.
838 * The input tensor's height and width must be divisible by block_size.
840 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
841 * {@link OperandType::TENSOR_QUANT8_ASYMM}
842 * Supported tensor rank: 4, with "NHWC" data layout.
845 * 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
846 * 1: An INT32 value, specifying the block_size. block_size must be >=1 and
847 * block_size must be a divisor of both the input height and width.
850 * 0: The output 4-D tensor, of shape [batch, height/block_size, width/block_size,
851 * depth*block_size*block_size].
856 * SVDF op is a kind of stateful layer derived from the notion that a
857 * densely connected layer that's processing a sequence of input frames can
858 * be approximated by using a singular value decomposition of each of its
859 * nodes. The implementation is based on:
861 * https://research.google.com/pubs/archive/43813.pdf
863 * P. Nakkiran, R. Alvarez, R. Prabhavalkar, C. Parada.
864 * “Compressing Deep Neural Networks using a Rank-Constrained Topology”.
867 * It processes the incoming input using a 2-stage filtering mechanism:
868 * * stage 1 performs filtering on the "features" dimension, whose outputs get
869 * pushed into a memory of fixed-size memory_size.
870 * * stage 2 performs filtering on the "time" dimension of the memory_size
871 * memoized outputs of stage 1.
873 * Specifically, for rank 1, this layer implements the operation:
875 * memory = push(conv1d(inputs, weights_feature, feature_dim, "VALID"));
876 * outputs = activation(memory * weights_time + bias);
879 * * “weights_feature” is a weights matrix that processes the inputs (by
880 * convolving the input with every “feature filter”), and whose outputs get
881 * pushed, stacked in order, into the fixed-size “memory” (the oldest entry
883 * * “weights_time” is a weights matrix that processes the “memory” (by a
884 * batched matrix multiplication on the num_units);
885 * * “bias” is an optional bias vector (added to each output vector in the
887 * * “activation” is the function passed as the “fused_activation_function”
888 * argument (if not “NONE”).
890 * Each rank adds a dimension to the weights matrices by means of stacking
893 * Supported tensor types:
894 * * {@link OperandType::TENSOR_FLOAT32}
898 * A 2-D tensor of type T, of shape [batch_size, input_size], where
899 * “batch_size” corresponds to the batching dimension, and “input_size” is
900 * the size of the input.
901 * * 1: weights_feature.
902 * A 2-D tensor of type T, of shape [num_units, input_size], where
903 * “num_units” corresponds to the number of units.
905 * A 2-D tensor of type T, of shape [num_units, memory_size], where
906 * “memory_size” corresponds to the fixed-size of the memory.
908 * A optional 1-D tensor of type T, of shape [num_units].
910 * For FLOAT32 input tensor, bias must also be FLOAT32.
911 * For UINT8 input tensor, bias must be INT32.
915 * The rank of the SVD approximation.
916 * * 5: fused_activation_function.
917 * An (optional) ActivationFunctionType indicating the activation function.
918 * If “NONE” is specified then it results in a linear activation.
922 * A 2-D tensor of type T, of shape [batch_size, (memory_size - 1) * num_units * rank].
924 * A 2-D tensor of type T, of shape [batch_size, num_units].
929 * Computes hyperbolic tangent of input tensor element-wise.
932 * output = tanh(input)
934 * Supported tensor types: {@link OperandType::TENSOR_FLOAT32}
935 * Supported tensor rank: up to 4.
938 * 0: A tensor, specifying the input.
941 * 0: The output tensor of same shape as input0.
946 * OEM specific operation.
948 * This operation is OEM specific. It should only be used for OEM applications.
950 OEM_OPERATION = 10000,
954 * Fused activation function types.
956 enum FusedActivationFunc : int32_t {
964 * How an operand is used.
966 enum OperandLifeTime : int32_t {
968 * The operand is internal to the model. It's created by an operation
969 * and consumed by other operations.
974 * The operand is an input of the model. An operand can't be both
975 * input and output of a model.
980 * The operand is an output of the model.
985 * The operand is a constant found in Model.operandValues.
990 * The operand is a constant that was specified via a Memory object.
995 * The operand does not have a value. This is valid only for optional arguments
1002 * Status of a device.
1004 enum DeviceStatus : int32_t {
1012 * Performance information for the reference workload.
1014 * Used by a driver to report its performance characteristics.
1016 struct PerformanceInfo {
1018 * Execution time in nanoseconds.
1023 * Power usage in picoJoules.
1029 * The capabilities of a driver.
1031 struct Capabilities {
1033 * Driver performance when operating on float32 data.
1035 PerformanceInfo float32Performance;
1038 * Driver performance when operating on asymmetric 8-bit quantized data.
1040 PerformanceInfo quantized8Performance;
1044 * Describes the location of a data object.
1046 struct DataLocation {
1048 * The index of the memory pool where this location is found.
1053 * Offset in bytes from the start of the pool.
1058 * The length of the data in bytes.
1064 * Describes one operand of the model's graph.
1068 * Data type of the operand.
1073 * Dimensions of the operand.
1075 vec<uint32_t> dimensions;
1078 * The number of operations that use this operand as input.
1080 uint32_t numberOfConsumers;
1083 * Quantized scale of the operand.
1085 * Only applicable if the operand is of type TENSOR_QUANT8_ASYMM or
1091 * Quantized zero-point offset of the operand.
1093 * Only applicable if the operand is of type TENSOR_QUANT8_ASYMM.
1098 * How the operand is used.
1100 OperandLifeTime lifetime;
1103 * Where to find the data for this operand.
1104 * If the lifetime is TEMPORARY_VARIABLE, MODEL_INPUT, MODEL_OUTPUT, or NO_VALUE:
1105 * - All the fields will be 0.
1106 * If the lifetime is CONSTANT_COPY:
1107 * - location.poolIndex is 0.
1108 * - location.offset is the offset in bytes into Model.operandValues.
1109 * - location.length is set.
1110 * If the lifetime is CONSTANT_REFERENCE:
1111 * - location.poolIndex is set.
1112 * - location.offset is the offset in bytes into the specified pool.
1113 * - location.length is set.
1115 DataLocation location;
1119 * Describes one operation of the model's graph.
1123 * The operation type.
1128 * Describes the table that contains the indexes of the inputs of the
1129 * operation. The offset is the index in the operandIndexes table.
1131 vec<uint32_t> inputs;
1134 * Describes the table that contains the indexes of the outputs of the
1135 * operation. The offset is the index in the operandIndexes table.
1137 vec<uint32_t> outputs;
1141 * A Neural Network Model.
1143 * This includes not only the execution graph, but also constant data such as
1144 * weights or scalars added at construction time. The only information that
1145 * might not be known is the shape of the input tensors.
1149 * All operands included in the model.
1151 vec<Operand> operands;
1154 * All operations included in the model.
1156 * The operations are sorted into execution order.
1158 vec<Operation> operations;
1161 * Input indexes of the model.
1163 * Each value corresponds to the index of the operand in "operands".
1165 vec<uint32_t> inputIndexes;
1168 * Output indexes of the model.
1170 * Each value corresponds to the index of the operand in "operands".
1172 vec<uint32_t> outputIndexes;
1175 * A byte buffer containing operand data that were copied into the model.
1177 * An operand's value must be located here if and only if Operand::lifetime
1178 * equals OperandLifeTime::CONSTANT_COPY.
1180 vec<uint8_t> operandValues;
1183 * A collection of shared memory pools containing operand data that were
1184 * registered by the model.
1186 * An operand's value must be located here if and only if Operand::lifetime
1187 * equals OperandLifeTime::CONSTANT_REFERENCE.
1193 * Metadata information specifying the location of the input or output data and
1194 * any updates to the input or output operand.
1196 struct RequestArgument {
1198 * If true, the argument does not have a value. This can be used for operations
1199 * that take optional arguments. If true, the fields of location are set to 0 and
1200 * the dimensions vector is left empty.
1205 * The location within one of the memory pools passed in the Request.
1207 DataLocation location;
1210 * Updated dimension information.
1212 * If dimensions.size() > 0, dimension information was provided along with the
1213 * argument. This can be the case for models that accept inputs of varying size.
1214 * This can't change the rank, just the value of the dimensions that were
1215 * unspecified in the model.
1217 vec<uint32_t> dimensions;
1221 * Inputs to be sent to and outputs to be retrieved from a prepared model.
1223 * A Request serves two primary tasks:
1224 * 1) Provides the input and output data to be used when executing the model.
1225 * 2) Specifies any updates to the input operand metadata that were left
1226 * unspecified at model preparation time.
1230 * Input data and information to be used in the execution of a prepared
1233 * The index of the input corresponds to the index in Model.inputIndexes.
1234 * E.g., input[i] corresponds to Model.inputIndexes[i].
1236 vec<RequestArgument> inputs;
1239 * Output data and information to be used in the execution of a prepared
1242 * The index of the output corresponds to the index in Model.outputIndexes.
1243 * E.g., output[i] corresponds to Model.outputIndexes[i].
1245 vec<RequestArgument> outputs;
1248 * A collection of shared memory pools containing operand data for both the
1249 * inputs and the outputs to a model.
1255 * Return status of a function.
1257 enum ErrorStatus : int32_t {
1261 OUTPUT_INSUFFICIENT_SIZE,