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