1 /* Copyright Statement: 2 * 3 * This software/firmware and related documentation ("MediaTek Software") are 4 * protected under relevant copyright laws. The information contained herein 5 * is confidential and proprietary to MediaTek Inc. and/or its licensors. 6 * Without the prior written permission of MediaTek inc. and/or its licensors, 7 * any reproduction, modification, use or disclosure of MediaTek Software, 8 * and information contained herein, in whole or in part, shall be strictly 9 * prohibited. 10 */ 11 /* MediaTek Inc. (C) 2020. All rights reserved. 12 * 13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES 14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") 15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON 16 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. 19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE 20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR 21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH 22 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY 23 * ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY 24 * THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK 25 * SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO 26 * RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN 27 * FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND 28 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER 29 * WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT 30 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER 31 * TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 32 * 33 * The following software/firmware and/or related documentation ("MediaTek 34 * Software") have been modified by MediaTek Inc. All revisions are subject to 35 * any receiver's applicable license agreements with MediaTek Inc. 36 */ 37 38 /** 39 * @file NeuronAdapter.h 40 */ 41 42 #pragma once 43 44 #ifdef __ANDROID__ 45 #pragma clang diagnostic push 46 #pragma clang diagnostic ignored "-Wnullability-extension" 47 #include <android/hardware_buffer.h> 48 #pragma clang diagnostic pop 49 #endif 50 51 #include <stddef.h> 52 #include <stdint.h> 53 #include <sys/cdefs.h> 54 55 __BEGIN_DECLS 56 57 /** 58 * NeuronModel is an opaque type that contains a description of the mathematical 59 * operations that constitute the model. 60 */ 61 typedef struct NeuronModel NeuronModel; 62 63 /** 64 * NeuronCompilation is an opaque type that can be used to compile a machine 65 * learning model. 66 */ 67 typedef struct NeuronCompilation NeuronCompilation; 68 69 /** 70 * NeuronExecution is an opaque type that can be used to apply a machine 71 * learning model to a set of inputs. 72 */ 73 typedef struct NeuronExecution NeuronExecution; 74 75 /** 76 * NeuronDevice is an opaque type that represents a device. 77 * 78 * This type is used to query basic properties and supported operations of the 79 * corresponding device, and control which device(s) a model is to be run on. 80 * 81 * Available since 4.1.0 82 */ 83 typedef struct NeuronDevice NeuronDevice; 84 85 /** 86 * This type is used to represent shared memory, memory mapped files, and 87 * similar memories. 88 * 89 * It is the application's responsibility to ensure that there are no uses of 90 * the memory after calling NeuronMemory_free. This includes the execution which 91 * references this memory because of a call to 92 * NeuronExecution_setInputFromMemory or NeuronExecution_setOutputFromMemory. 93 * 94 * Available since 4.1.0 95 */ 96 typedef struct NeuronMemory NeuronMemory; 97 98 /** 99 * NeuronEvent is an opaque type that represents an event 100 * that will be signaled once an execution completes. 101 * 102 * Available since 5.0.0 103 */ 104 typedef struct NeuronEvent NeuronEvent; 105 106 /** 107 * Result codes. 108 */ 109 typedef enum { 110 NEURON_NO_ERROR = 0, 111 NEURON_OUT_OF_MEMORY = 1, 112 NEURON_INCOMPLETE = 2, 113 NEURON_UNEXPECTED_NULL = 3, 114 NEURON_BAD_DATA = 4, 115 NEURON_OP_FAILED = 5, 116 NEURON_UNMAPPABLE = 6, 117 NEURON_BAD_STATE = 7, 118 NEURON_BAD_VERSION = 8, 119 120 // Available since 5.0.0 121 NEURON_OUTPUT_INSUFFICIENT_SIZE = 9, 122 NEURON_UNAVAILABLE_DEVICE = 10, 123 NEURON_MISSED_DEADLINE_TRANSIENT = 11, 124 NEURON_MISSED_DEADLINE_PERSISTENT = 12, 125 NEURON_RESOURCE_EXHAUSTED_TRANSIENT = 13, 126 NEURON_RESOURCE_EXHAUSTED_PERSISTENT = 14, 127 NEURON_DEAD_OBJECT = 15, 128 } NeuronAdapterResultCode; 129 130 /** 131 * Operand values with size in bytes that are smaller or equal to this will be 132 * immediately copied into the model. 133 */ 134 enum { NEURON_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES = 128 }; 135 136 /** 137 * Size of the cache token, in bytes, required from the application. 138 */ 139 enum { NEURON_BYTE_SIZE_OF_CACHE_TOKEN = 32 }; 140 141 /** 142 * Operand types. 143 * The type of operands that can be added to a model. 144 * 145 * Some notes on quantized tensors 146 * 147 * <p>NEURON_TENSOR_QUANT8_ASYMM 148 * <p>Attached to this tensor are two numbers that can be used to convert the 8 149 * bit integer to the real value and vice versa. These two numbers are: 150 * - scale: a 32 bit floating point value greater than zero. 151 * - zeroPoint: a 32 bit integer, in range [0, 255]. 152 * <p>The formula is: real_value = (integer_value - zero_value) * scale. 153 * 154 * <p>NEURON_TENSOR_QUANT16_SYMM 155 * <p>Attached to this tensor is a number representing real value scale that is 156 * used to convert the 16 bit number to a real value in the following way: 157 * realValue = integerValue * scale. scale is a 32 bit floating point with value 158 * greater than zero. 159 * 160 * <p>NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL 161 * <p>This tensor is associated with additional fields that can be used to 162 * convert the 8 bit signed integer to the real value and vice versa. These 163 * fields are: 164 * - channelDim: a 32 bit unsigned integer indicating channel dimension. 165 * - scales: an array of positive 32 bit floating point values. 166 * <p>The size of the scales array must be equal to dimensions[channelDim]. 167 * NeuronModel_setOperandSymmPerChannelQuantParams must be used to set the 168 * parameters for an Operand of this type. The channel dimension of this tensor 169 * must not be unknown (dimensions[channelDim] != 0). The formula is: 170 * realValue[..., C, ...] = integerValue[..., C, ...] * scales[C] where C is an 171 * index in the Channel dimension. 172 * 173 * <p>NEURON_TENSOR_QUANT16_ASYMM 174 * <p>Attached to this tensor are two numbers that can be used to convert the 16 175 * bit integer to the real value and vice versa. These two numbers are: 176 * - scale: a 32 bit floating point value greater than zero. 177 * - zeroPoint: a 32 bit integer, in range [0, 65535]. 178 * <p>The formula is: real_value = (integer_value - zeroPoint) * scale. 179 * 180 * <p>NEURON_TENSOR_QUANT8_SYMM 181 * <p>Attached to this tensor is a number representing real value scale that is 182 * used to convert the 8 bit number to a real value in the following way: 183 * realValue = integerValue * scale. scale is a 32 bit floating point with value 184 * greater than zero. 185 * 186 * <p>NEURON_TENSOR_QUANT8_ASYMM_SIGNED 187 * <P>Attached to this tensor are two numbers that can be used to convert the 8 188 * bit integer to the real value and vice versa. These two numbers are: 189 * - scale: a 32 bit floating point value greater than zero. 190 * - zeroPoint: a 32 bit integer, in range [-128, 127]. 191 * <p>The formula is: real_value = (integer_value - zeroPoint) * scale. 192 */ 193 enum { 194 /** A 32 bit floating point scalar value. */ 195 NEURON_FLOAT32 = 0, 196 /** A signed 32 bit integer scalar value. */ 197 NEURON_INT32 = 1, 198 /** An unsigned 32 bit integer scalar value. */ 199 NEURON_UINT32 = 2, 200 /** A tensor of 32 bit floating point values. */ 201 NEURON_TENSOR_FLOAT32 = 3, 202 /** A tensor of 32 bit integer values. */ 203 NEURON_TENSOR_INT32 = 4, 204 /** A tensor of 8 bit integers that represent real numbers. */ 205 NEURON_TENSOR_QUANT8_ASYMM = 5, 206 /** An 8 bit boolean scalar value. */ 207 NEURON_BOOL = 6, 208 /** A tensor of 16 bit signed integers that represent real numbers. */ 209 NEURON_TENSOR_QUANT16_SYMM = 7, 210 /** A tensor of IEEE 754 16 bit floating point values. */ 211 NEURON_TENSOR_FLOAT16 = 8, 212 /** A tensor of 8 bit boolean values. */ 213 NEURON_TENSOR_BOOL8 = 9, 214 /** An IEEE 754 16 bit floating point scalar value. */ 215 NEURON_FLOAT16 = 10, 216 /** A tensor of 8 bit signed integers that represent real numbers. */ 217 NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL = 11, 218 /** A tensor of 16 bit unsigned integers that represent real numbers. */ 219 NEURON_TENSOR_QUANT16_ASYMM = 12, 220 /** A tensor of 8 bit signed integers that represent real numbers. */ 221 NEURON_TENSOR_QUANT8_SYMM = 13, 222 /** A tensor of 8 bit signed integers that represent real numbers. */ 223 NEURON_TENSOR_QUANT8_ASYMM_SIGNED = 14, 224 /** A reference to a model. */ 225 NEURON_MODEL = 15, 226 /** Extended data type - tensor uint32 */ 227 NEURON_EXT_TENSOR_UINT32 = 9001, 228 /** Extended data type -A tensor of 8 bit unsigned integers that represent 229 real numbers. */ 230 NEURON_EXT_TENSOR_QUANT8_ASYMM_PER_CHANNEL = 9002, 231 /** Extended data type -A tensor of 4 bit unsigned integers that represent 232 real numbers. */ 233 NEURON_EXT_TENSOR_QUANT4_ASYMM = 9003, 234 /** Extended data type -A tensor of 4 bit signed integers that represent real 235 numbers. */ 236 NEURON_EXT_TENSOR_QUANT4_ASYMM_SIGNED = 9004, 237 /** Extended data type -A tensor of 4 bit signed integers that represent real 238 numbers. */ 239 NEURON_EXT_TENSOR_QUANT4_SYMM = 9005, 240 /** Extended data type -A tensor of 16 bit signed integers that represent real 241 numbers. */ 242 NEURON_EXT_TENSOR_QUANT16_ASYMM_SIGNED = 9006, 243 /** Extended data type -A raw tensor. */ 244 NEURON_EXT_TENSOR_RAW = 9007, 245 /** Extended data type -A tensor of 8 bit signed integers that represent real 246 numbers. */ 247 NEURON_EXT_TENSOR_QUANT8_ASYMM_SIGNED_PER_CHANNEL = 9008, 248 }; 249 250 /** 251 * NeuronOperandType describes the type of an operand. 252 * This structure is used to describe both scalars and tensors. 253 */ 254 typedef struct NeuronOperandType { 255 /** The data type, e.g NEURON_INT8. */ 256 int32_t type; 257 /** The number of dimensions. It should be 0 for scalars. */ 258 uint32_t dimensionCount; 259 /** The dimensions of the tensor. It should be nullptr for scalars. */ 260 const uint32_t* dimensions; 261 /** 262 * These two fields are only used for quantized tensors. 263 * They should be zero for scalars and non-fixed point tensors. 264 * The dequantized value of each entry is (value - zeroPoint) * scale. 265 */ 266 float scale; 267 /** Only used with scale for quantized tensors */ 268 int32_t zeroPoint; 269 } NeuronOperandType; 270 271 /** 272 * Parameters for NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL operand. 273 */ 274 typedef struct NeuronSymmPerChannelQuantParams { 275 /** The index of the channel dimension. */ 276 uint32_t channelDim; 277 /** The size of the scale array. Should be equal to dimension[channelDim] of 278 * the Operand. */ 279 uint32_t scaleCount; 280 /** The array of scaling values for each channel. Each value must be greater 281 * than zero. */ 282 const float* scales; 283 } NeuronSymmPerChannelQuantParams; 284 285 /** 286 * Parameters for NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL and 287 * NEURON_TENSOR_QUANT8_ASYMM_PER_CHANNEL operand. 288 */ 289 typedef struct NeuronPerChannelQuantParams { 290 /** The index of the channel dimension. */ 291 uint32_t channelDim; 292 /** The size of the scale array. Should be equal to dimension[channelDim] of 293 * the Operand. */ 294 uint32_t scaleCount; 295 /** The array of scaling values for each channel. Each value must be greater 296 * than zero. */ 297 const float* scales; 298 /** The size of the zeroPoints. Should be equal to dimension[channelDim] of 299 * the Operand. */ 300 uint32_t zeroPointCount; 301 /** The array of zero point values for each channel. */ 302 const int32_t* zeroPoints; 303 } NeuronPerChannelQuantParams; 304 305 /** 306 * Operation Types 307 * 308 * Supported operations are listed with available versions. See 309 * Neuron_getVersion for querying version number. 310 * 311 * Attempting to compile models with operations marked as not available 312 * will get a compilation failure. 313 * 314 * Refer to the operation support status of each hardware platform. 315 * Attempting to compile models with operations supported by this library but 316 * not supported by the underlying hardware platform will get a compilation 317 * failure too. 318 * 319 * Compatible NNAPI levels are also listed. 320 */ 321 typedef enum { 322 NEURON_ADD = 0, ///< Available since 4.1.0. NNAPI level 30. 323 NEURON_AVERAGE_POOL_2D = 1, ///< Available since 4.1.0. NNAPI level 30. 324 NEURON_CONCATENATION = 2, ///< Available since 4.1.0. NNAPI level 30. 325 NEURON_CONV_2D = 3, ///< Available since 4.1.0. NNAPI level 30. 326 NEURON_DEPTHWISE_CONV_2D = 4, ///< Available since 4.1.0. NNAPI level 30. 327 NEURON_DEPTH_TO_SPACE = 5, ///< Available since 4.1.0. NNAPI level 30. 328 NEURON_DEQUANTIZE = 6, ///< Available since 4.1.0. NNAPI level 30. 329 NEURON_EMBEDDING_LOOKUP = 7, ///< Not available. 330 NEURON_FLOOR = 8, ///< Available since 4.1.0. NNAPI level 30. 331 NEURON_FULLY_CONNECTED = 9, ///< Available since 4.1.0. NNAPI level 30. 332 NEURON_HASHTABLE_LOOKUP = 10, ///< Not available. 333 NEURON_L2_NORMALIZATION = 11, ///< Available since 4.1.0. NNAPI level 30. 334 NEURON_L2_POOL_2D = 12, ///< Available since 4.1.0. NNAPI level 30. 335 NEURON_LOCAL_RESPONSE_NORMALIZATION = 13, ///< Not available. 336 NEURON_LOGISTIC = 14, ///< Available since 4.1.0. NNAPI level 30. 337 NEURON_LSH_PROJECTION = 15, ///< Not available. 338 NEURON_LSTM = 16, ///< Not available. 339 NEURON_MAX_POOL_2D = 17, ///< Available since 4.1.0. NNAPI level 30. 340 NEURON_MUL = 18, ///< Available since 4.1.0. NNAPI level 30. 341 NEURON_RELU = 19, ///< Available since 4.1.0. NNAPI level 30. 342 NEURON_RELU1 = 20, ///< Available since 4.1.0. NNAPI level 30. 343 NEURON_RELU6 = 21, ///< Available since 4.1.0. NNAPI level 30. 344 NEURON_RESHAPE = 22, ///< Available since 4.1.0. NNAPI level 30. 345 NEURON_RESIZE_BILINEAR = 23, ///< Available since 4.1.0. NNAPI level 30. 346 NEURON_RNN = 24, ///< Not available. 347 NEURON_SOFTMAX = 25, ///< Available since 4.1.0. NNAPI level 30. 348 NEURON_SPACE_TO_DEPTH = 26, ///< Available since 4.1.0. NNAPI level 30. 349 NEURON_SVDF = 27, ///< Not available. 350 NEURON_TANH = 28, ///< Available since 4.1.0. NNAPI level 30. 351 NEURON_BATCH_TO_SPACE_ND = 29, ///< Available since 4.1.0. NNAPI level 30. 352 NEURON_DIV = 30, ///< Available since 4.1.0. NNAPI level 30. 353 NEURON_MEAN = 31, ///< Available since 4.1.0. NNAPI level 30. 354 NEURON_PAD = 32, ///< Available since 4.1.0. NNAPI level 30. 355 NEURON_SPACE_TO_BATCH_ND = 33, ///< Available since 4.1.0. NNAPI level 30. 356 NEURON_SQUEEZE = 34, ///< Available since 4.1.0. NNAPI level 30. 357 NEURON_STRIDED_SLICE = 35, ///< Available since 4.1.0. NNAPI level 30. 358 NEURON_SUB = 36, ///< Available since 4.1.0. NNAPI level 30. 359 NEURON_TRANSPOSE = 37, ///< Available since 4.1.0. NNAPI level 30. 360 NEURON_ABS = 38, ///< Available since 4.1.0. NNAPI level 30. 361 NEURON_ARGMAX = 39, ///< Available since 4.1.0. NNAPI level 30. 362 NEURON_ARGMIN = 40, ///< Available since 4.1.0. NNAPI level 30. 363 NEURON_AXIS_ALIGNED_BBOX_TRANSFORM = 364 41, ///< Available since 4.1.0. NNAPI level 30. 365 NEURON_BIDIRECTIONAL_SEQUENCE_LSTM = 42, ///< Not available. 366 NEURON_BIDIRECTIONAL_SEQUENCE_RNN = 43, ///< Not available. 367 NEURON_BOX_WITH_NMS_LIMIT = 44, ///< Available since 4.1.0. NNAPI level 30. 368 NEURON_CAST = 45, ///< Available since 4.1.0. NNAPI level 30. 369 NEURON_CHANNEL_SHUFFLE = 46, ///< Available since 4.1.0. NNAPI level 30. 370 NEURON_DETECTION_POSTPROCESSING = 47, ///< Not available. 371 NEURON_EQUAL = 48, ///< Available since 4.1.0. NNAPI level 30. 372 NEURON_EXP = 49, ///< Available since 4.1.0. NNAPI level 30. 373 NEURON_EXPAND_DIMS = 50, ///< Available since 4.1.0. NNAPI level 30. 374 NEURON_GATHER = 51, ///< Available since 4.1.0. NNAPI level 30. 375 NEURON_GENERATE_PROPOSALS = 52, ///< Not available. 376 NEURON_GREATER = 53, ///< Available since 4.1.0. NNAPI level 30. 377 NEURON_GREATER_EQUAL = 54, ///< Available since 4.1.0. NNAPI level 30. 378 NEURON_GROUPED_CONV_2D = 55, ///< Available since 4.1.0. NNAPI level 30. 379 NEURON_HEATMAP_MAX_KEYPOINT = 56, ///< Available since 4.1.0. NNAPI level 30. 380 NEURON_INSTANCE_NORMALIZATION = 381 57, ///< Available since 4.1.0. NNAPI level 30. 382 NEURON_LESS = 58, ///< Available since 4.1.0. NNAPI level 30. 383 NEURON_LESS_EQUAL = 59, ///< Available since 4.1.0. NNAPI level 30. 384 NEURON_LOG = 60, ///< Not available. 385 NEURON_LOGICAL_AND = 61, ///< Available since 4.1.0. NNAPI level 30. 386 NEURON_LOGICAL_NOT = 62, ///< Available since 4.1.0. NNAPI level 30. 387 NEURON_LOGICAL_OR = 63, ///< Available since 4.1.0. NNAPI level 30. 388 NEURON_LOG_SOFTMAX = 64, ///< Not available. 389 NEURON_MAXIMUM = 65, ///< Available since 4.1.0. NNAPI level 30. 390 NEURON_MINIMUM = 66, ///< Available since 4.1.0. NNAPI level 30. 391 NEURON_NEG = 67, ///< Available since 4.1.0. NNAPI level 30. 392 NEURON_NOT_EQUAL = 68, ///< Available since 4.1.0. NNAPI level 30. 393 NEURON_PAD_V2 = 69, ///< Available since 4.1.0. NNAPI level 30. 394 NEURON_POW = 70, ///< Available since 4.1.0. NNAPI level 30. 395 NEURON_PRELU = 71, ///< Available since 4.1.0. NNAPI level 30. 396 NEURON_QUANTIZE = 72, ///< Available since 4.1.0. NNAPI level 30. 397 NEURON_QUANTIZED_16BIT_LSTM = 73, ///< Available since 4.1.0. NNAPI level 30. 398 NEURON_RANDOM_MULTINOMIAL = 74, ///< Not available. 399 NEURON_REDUCE_ALL = 75, ///< Available since 4.1.0. NNAPI level 30. 400 NEURON_REDUCE_ANY = 76, ///< Available since 4.1.0. NNAPI level 30. 401 NEURON_REDUCE_MAX = 77, ///< Available since 4.1.0. NNAPI level 30. 402 NEURON_REDUCE_MIN = 78, ///< Available since 4.1.0. NNAPI level 30. 403 NEURON_REDUCE_PROD = 79, ///< Not available. 404 NEURON_REDUCE_SUM = 80, ///< Available since 4.1.0. NNAPI level 30. 405 NEURON_ROI_ALIGN = 81, ///< Available since 4.1.0. NNAPI level 30. 406 NEURON_ROI_POOLING = 82, ///< Not available. 407 NEURON_RSQRT = 83, ///< Available since 4.1.0. NNAPI level 30. 408 NEURON_SELECT = 84, ///< Available since 4.1.0. NNAPI level 30. 409 NEURON_SIN = 85, ///< Not available. 410 NEURON_SLICE = 86, ///< Available since 4.1.0. NNAPI level 30. 411 NEURON_SPLIT = 87, ///< Available since 4.1.0. NNAPI level 30. 412 NEURON_SQRT = 88, ///< Available since 4.1.0. NNAPI level 30. 413 NEURON_TILE = 89, ///< Available since 4.1.0. NNAPI level 30. 414 NEURON_TOPK_V2 = 90, ///< Available since 4.1.0. NNAPI level 30. 415 NEURON_TRANSPOSE_CONV_2D = 91, ///< Available since 4.1.0. NNAPI level 30. 416 NEURON_UNIDIRECTIONAL_SEQUENCE_LSTM = 92, ///< Not available. 417 NEURON_UNIDIRECTIONAL_SEQUENCE_RNN = 93, ///< Not available. 418 NEURON_RESIZE_NEAREST_NEIGHBOR = 419 94, ///< Available since 4.1.0. NNAPI level 30. 420 NEURON_QUANTIZED_LSTM = 95, ///< Not available. 421 NEURON_IF = 96, ///< Available since 4.1.0. NNAPI level 30. 422 NEURON_WHILE = 97, ///< Available since 4.1.0. NNAPI level 30. 423 NEURON_ELU = 98, ///< Not available. 424 NEURON_HARD_SWISH = 99, ///< Available since 4.1.0. NNAPI level 30. 425 NEURON_FILL = 100, ///< Available since 4.1.0. NNAPI level 30. 426 NEURON_RANK = 101, ///< Not available. 427 NEURON_BATCH_MATMUL = 102, ///< Available since 5.1.2. NNAPI FL6. 428 NEURON_PACK = 103, ///< Not available. 429 NEURON_MIRROR_PAD = 104, ///< Not available. 430 NEURON_MIRROR_REVERSE = 105, ///< Not available. 431 /** 432 * Decompress HyFBC to YUV420 frame, support both YUV420_8BITS and 433 * YUV420_10BITS formats. HyFBC (Hybrid Frame Buffer Compression) is a 434 * compressed format used by video decoder (VDEC). This format uses YUV420 to 435 * compress. 436 * 437 * For input part, need to set two inputs with different shape, representing Y 438 * and UV plane respectively. The same HyFBC data will be used for both 439 * inputs. Similarly, the output part also needs to be set to two, 440 * representing Y and UV plane respectively. 441 * 442 * The shape of the two inputs/ outputs (inputY, inputUV, outputY, outputUV) 443 * depends on the original images' shape ([batches, height, width, channels]). 444 * Both height and width shold follow 64 alignment rule. For example, if 445 * original height is 480, its 64 alignment should be 512. For Y plane, 446 * channel size should be 1; for UV plane, channel size should be 2. Besides, 447 * the height and width of UV plane should be half of Y's height and width. 448 * Example: 449 * 450 * original_img.shape = [1, 384, 640, 3] 451 * inputY.shape = [1, 384, 640, 1] 452 * inputUV.shape = [1, 192, 320, 2] 453 * outputY.shape = [1, 384, 640, 1] 454 * outputUV.shape = [1, 192, 320, 2] 455 * 456 * Supported tensor {@link OperandCode}: 457 * * {@link NEURON_EXT_TENSOR_RAW} (for inputY, inputUV) 458 * * {@link NEURON_TENSOR_QUANT8_ASYMM} (for outputY, outputUV) 459 * * {@link NEURON_TENSOR_QUANT16_ASYMM} (for outputY, outputUV) 460 * Note: 461 * If image mode is YUV420_8BITS, use NEURON_TENSOR_QUANT8_ASYMM; if mode is 462 * YUV420_10BITS, use NEURON_TENSOR_QUANT16_ASYMM. 463 * 464 * Tensor rank: both input and output require rank 4, with "NHWC" data layout. 465 * 466 * Inputs: 467 * * 0: inputY, a 4-D {@link NEURON_EXT_TENSOR_RAW} tensor. 468 * * 1: inputUV, a 4-D {@link NEURON_EXT_TENSOR_RAW} tensor. 469 * * 2: YHeaderAlignment, an {@link NEURON_INT32} scalar, specifying 470 * the header alignment in Hyfbc format. 471 * * 3: UVHeaderAlignment, an {@link NEURON_INT32} scalar, specifying 472 * the header alignment in Hyfbc format. 473 * * 4: xAlign, an {@link NEURON_INT32} scalar, specifying the frame 474 * width alignment of video decoder. 475 * * 5: yAlign, an {@link NEURON_INT32} scalar, specifying the frame 476 * height alignment of video decoder. 477 * * 6: xOffset, an {@link NEURON_INT32} scalar, specifying the frame 478 * width offset of video decoder. 479 * * 7: yOffset, an {@link NEURON_INT32} scalar, specifying the frame 480 * height offset of video decoder. 481 * * 8: mode, an {@link NEURON_INT32} scalar. Set to 0 for 482 * YUV420_8BITS. Set to 1 for YUV420_10BITS. Note that 8b, 10b here means the 483 * compressed bit width in Hyfbc frame, where the decompressed YUV420 is 8b 484 * for Hyfbc_8b, and YUV420 is 16b for Hyfbc_10b. 485 * * 9: outPitchN, an {@link NEURON_INT32} scalar, specifying the 486 * YUV420 N-axis pitch. Must be set to 1, because only a single batch is 487 * supported for HyfbcDecompress. 488 * * 10: outPitchH, an {@link NEURON_INT32} scalar, specifying the 489 * YUV420 H-axis pitch. Set to the original compressed image height with video 490 * codec alignment. 491 * * 11: outPitchW, an {@link NEURON_INT32} scalar, specifying the 492 * YUV420 W-axis pitch. Set to the original compressed image width with video 493 * codec alignment. 494 * * 12: outPitchC, an {@link NEURON_INT32} scalar, specifying the 495 * YUV420 C-axis pitch. Set to 1 for interleaved YUV420. 496 * 497 * Outputs: 498 * * 0: output Y, a 4-D tensor. Tensor type can be either {@link 499 * NEURON_TENSOR_QUANT8_ASYMM} or {@link 500 * NEURON_TENSOR_QUANT16_ASYMM}, depends on YUV420 bit mode. 501 * * 1: output UV, a 4-D tensor. Tensor type can be either {@link 502 * NEURON_TENSOR_QUANT8_ASYMM} or {@link 503 * NEURON_TENSOR_QUANT16_ASYMM}, depends on YUV420 bit mode. 504 * 505 * Available since NeuroPilot 7.0.0. 506 */ 507 NEURON_HYFBCTOYUV420 = 106, 508 /** 509 * Compress YUV420 to AFBC frame, support both YUV420_8BITS and 510 * YUV420_10BITS formats. AFBC (Arm Frame Buffer Compression) is a lossless 511 * compressed image format, created by ARM to reduce the size of images. 512 * 513 * For input part, need to set two inputs with different shape, representing Y 514 * and UV plane respectively. For output part, need to set one output for 515 * AFBC. 516 * 517 * The shape of the two inputs (inputY, inputUV) and output (AFBC) 518 * depends on the original images' shape ([batches, height, width, channels]). 519 * Both height and width shold follow 64 alignment rule. For example, if 520 * original height is 480, its 64 alignment should be 512. For Y plane, 521 * channel size should be 1; for UV plane, channel size should be 2. Besides, 522 * the height and width of UV plane should be half of Y's height and width. 523 * For AFBC output, its height shoud be 3/2 of Y's height, and its width 524 * equals to Y's width. Example: 525 * 526 * original_img.shape = [1, 384, 640, 3] 527 * inputY.shape = [1, 384, 640, 1] 528 * inputUV.shape = [1, 192, 320, 2] 529 * output.shape = [1, 576, 640, 1] 530 * 531 * Supported tensor {@link OperandCode}: 532 * * {@link NEURON_EXT_TENSOR_RAW} (for output) 533 * * {@link NEURON_TENSOR_QUANT8_ASYMM} (for inputY, inputUV) 534 * * {@link NEURON_TENSOR_QUANT16_ASYMM} (for inputY, inputUV) 535 * Note: 536 * If image mode is YUV420_8BITS, use NEURON_TENSOR_QUANT8_ASYMM; if mode is 537 * YUV420_10BITS, use NEURON_TENSOR_QUANT16_ASYMM. 538 * 539 * Tensor rank: both input and output require rank 4, with "NHWC" data layout. 540 * 541 * Inputs: 542 * * 0: inputY, a 4-D tensor. Tensor type can be either {@link 543 * NEURON_TENSOR_QUANT8_ASYMM} or {@link 544 * NEURON_TENSOR_QUANT16_ASYMM}, depends on YUV420 bit mode. 545 * * 1: inputUV, a 4-D tensor. Tensor type can be either {@link 546 * NEURON_TENSOR_QUANT8_ASYMM} or {@link 547 * NEURON_TENSOR_QUANT16_ASYMM}, depends on YUV420 bit mode. 548 * * 2: HeaderAlignment, an {@link NEURON_INT32} scalar, specifying 549 * the header alignment in AFBC format. 550 * * 3: xAlign, an {@link NEURON_INT32} scalar, specifying the frame 551 * width alignment of AFBC format. 552 * * 4: yAlign, an {@link NEURON_INT32} scalar, specifying the frame 553 * height alignment of AFBC format. 554 * * 5: xOffset, an {@link NEURON_INT32} scalar, specifying the frame 555 * width offset of AFBC format. 556 * * 6: yOffset, an {@link NEURON_INT32} scalar, specifying the frame 557 * height offset of AFBC format. 558 * * 7: mode, an {@link NEURON_INT32} scalar. Set to 0 for 559 * YUV420_8BITS. Set to 1 for YUV420_10BITS. Note that 8b, 10b here means the 560 * compressed bit width in AFBC frame, where the YUV420 must be 8b for 561 * AFBC_8b, and must be 16b for AFBC_10b. 562 * * 8: inPitchN, an {@link NEURON_INT32} scalar, specifying the 563 * YUV420 N-axis pitch. Must be set to 1, because only a single batch is 564 * supported for AfbcCompress. 565 * * 9: inPitchH, an {@link NEURON_INT32} scalar, specifying the 566 * YUV420 H-axis pitch. Set to the expected compressed image height. 567 * * 10: inPitchW, an {@link NEURON_INT32} scalar, specifying the 568 * YUV420 W-axis pitch. Set to the expected compressed image height. 569 * * 11: inPitchC, an {@link NEURON_INT32} scalar, specifying the 570 * YUV420 C-axis pitch. Set to 1 for interleaved YUV420. 571 * 572 * Outputs: 573 * * 0: output, a 4-D {@link NEURON_EXT_TENSOR_RAW} tensor. 574 * 575 * Available since NeuroPilot 7.0.0. 576 */ 577 NEURON_YUV420TOAFBC = 107, 578 NEURON_NUMBER_OF_OPERATIONS, 579 } NeuronOperationType; 580 581 /** 582 * Fused activation function types. 583 */ 584 typedef enum { 585 // NO fused activation function. 586 NEURON_FUSED_NONE = 0, 587 // Fused ReLU activation function. 588 NEURON_FUSED_RELU = 1, 589 // Fused ReLU1 activation function. 590 NEURON_FUSED_RELU1 = 2, 591 // Fused ReLU6 activation function. 592 NEURON_FUSED_RELU6 = 3, 593 } NeuronAdapterFuseCode; 594 595 /** 596 * Implicit padding algorithms. 597 */ 598 typedef enum { 599 /** 600 * SAME padding. 601 * Padding on both ends are the "same": 602 * padding_to_beginning = total_padding / 2 603 * padding_to_end = (total_padding + 1)/2. 604 * i.e., for even number of padding, padding to both ends are exactly 605 * the same; for odd number of padding, padding to the ending is bigger 606 * than the padding to the beginning by 1. 607 * 608 * total_padding is a function of input, stride and filter size. 609 * It could be computed as follows: 610 * out_size = (input + stride - 1) / stride; 611 * needed_input = (out_size - 1) * stride + filter_size 612 * total_padding = max(0, needed_input - input_size) 613 * The computation is the same for the horizontal and vertical directions. 614 */ 615 NEURON_PADDING_SAME = 1, 616 617 /** 618 * VALID padding. 619 * No padding. When the input size is not evenly divisible by 620 * the filter size, the input at the end that could not fill 621 * the whole filter tile will simply be ignored. 622 */ 623 NEURON_PADDING_VALID = 2, 624 } NeuronAdapterPaddingCode; 625 626 /** 627 * Execution preferences. 628 */ 629 typedef enum { 630 /* Prefer executing in a way that minimizes battery drain. */ 631 NEURON_PREFER_LOW_POWER = 0, 632 /* Prefer executing as fast as possible. (more power consumption)*/ 633 NEURON_PREFER_FAST_SINGLE_ANSWER = 1, 634 /* Prefer maximizing the throughput of successive frames */ 635 NEURON_PREFER_SUSTAINED_SPEED = 2, 636 /* Prefer executing with turbo boost. (most power consumption) */ 637 NEURON_PREFER_TURBO_BOOST = 3, 638 } NeuronAdapterPreferenceCode; 639 640 /** 641 * Relative execution priority. 642 */ 643 typedef enum { 644 NEURON_PRIORITY_LOW = 90, 645 NEURON_PRIORITY_MEDIUM = 100, 646 NEURON_PRIORITY_HIGH = 110, 647 NEURON_PRIORITY_DEFAULT = NEURON_PRIORITY_MEDIUM, 648 } NeuronAdapterPriorityCode; 649 650 /** 651 * Compiler optimization hint. 652 */ 653 typedef enum { 654 /** 655 * Normal optimization. 656 * Available since 4.3.1 657 */ 658 NEURON_OPTIMIZATION_NORMAL = 0, 659 /** 660 * Reduce latency by utilizing as many APU cores as possible. 661 * Available since 4.3.1 662 */ 663 NEURON_OPTIMIZATION_LOW_LATENCY = 1 << 0, 664 /** 665 * Reducing DRAM access as more as possible. 666 * Available since 4.4.0 667 */ 668 NEURON_OPTIMIZATION_DEEP_FUSION = 1 << 1, 669 /** 670 * Reduce latency by using as many APU cores as possible in batch-dimension. 671 * (For models with batch > 1) 672 * Available since 4.4.0 673 */ 674 NEURON_OPTIMIZATION_BATCH_PROCESSING = 1 << 2, 675 /** 676 * Default optimization setting. 677 * Available since 4.3.1 678 */ 679 NEURON_OPTIMIZATION_DEFAULT = NEURON_OPTIMIZATION_NORMAL, 680 } OptimizationCode; 681 682 /** 683 * CPU cache flush hint. 684 */ 685 typedef enum { 686 /** 687 * Sync input buffer and invalidate output buffer. 688 * Available since 5.0.1 689 */ 690 NEURON_CACHE_FLUSH_ENABLE_ALL = 0, 691 /** 692 * Disable sync input buffer. 693 * Available since 5.0.1 694 */ 695 NEURON_CACHE_FLUSH_DISABLE_SYNC_INPUT = 1 << 0, 696 /** 697 * Disable invalidate output buffer. 698 * Available since 5.0.1 699 */ 700 NEURON_CACHE_FLUSH_DISABLE_INVALIDATE_OUTPUT = 1 << 1, 701 /** 702 * Default cache flush setting. 703 * Available since 5.0.1 704 */ 705 NEURON_CACHE_FLUSH_DEFAULT = NEURON_CACHE_FLUSH_ENABLE_ALL, 706 } CacheFlushCode; 707 708 /** 709 * Compilation Type. 710 */ 711 typedef enum { 712 /* Normal Compilation Available since 7.0.0 */ 713 COMPILATION_TYPE_NORMAL = 0, 714 /* @deprecate */ 715 COMPILATION_TYPE_DEBUG_PLUS = 1, 716 /* Batched Execution: Set input/output from memory every time. 717 * Available since 7.0.0 718 */ 719 COMPILATION_TYPE_BATCHED = 2, 720 /* One compilation with multi-executions could be created. 721 * Available since 7.0.0 722 */ 723 COMPILATION_TYPE_MULTI_EXECUTIONS = 3, 724 /* Batched Execution: Set input/output from memory 1st time and memcpy next 725 * time. Available since 7.0.1 726 */ 727 COMPILATION_TYPE_EXECUTION_CONTROLLER = 4, 728 } CompilationType; 729 730 /** 731 * Supported Feature 732 */ 733 typedef enum { 734 NEURON_FEATURE_NONE = 0, 735 NEURON_THROUGHPUT_MODE = 1, 736 } NeuronFeatureType; 737 738 /** 739 * The structure to represent the neuron version. 740 */ 741 typedef struct { 742 uint8_t major; ///< major version 743 uint8_t minor; ///< minor version 744 uint8_t patch; ///< patch version 745 } NeuronRuntimeVersion; 746 747 /** 748 * Get the version of Neuron runtime library. 749 * 750 * @param version the version of Neuron runtime library. 751 * @return NEURON_NO_ERROR 752 */ 753 int Neuron_getVersion(NeuronRuntimeVersion* version); 754 755 /** 756 * Get the supported status of feature. 757 * 758 * Available since 7.0.0 759 * 760 * @param type input feature @NeuronFeatureType to check supported or not 761 * @param supported return the supported status 762 * @return NEURON_NO_ERROR if successful. 763 */ 764 int Neuron_getFeatureSupportedStatus(NeuronFeatureType type, bool* supported); 765 766 /** 767 * Get the size of L1 memory in APU. 768 * 769 * Available since 4.3.0 770 * 771 * @param sizeKb L1 memory size in KB 772 * @return NEURON_NO_ERROR if successful. 773 */ 774 int Neuron_getL1MemorySizeKb(uint32_t* sizeKb); 775 776 /** 777 * Creates a shared memory object from a file descriptor. 778 * 779 * For ion descriptor, application should create the ion memory and descriptor 780 * first and then use it in this function. 781 * 782 * Available since 4.1.0 Only supports ion fd. 783 * 784 * @param size The requested size in bytes. Must not be larger than the file 785 * size. 786 * @protect The desired memory protection for the mapping. It is either 787 * PROT_NONE or the bitwise OR of one or more of the following flags: PROT_READ, 788 * PROT_WRITE. 789 * @fd The requested file descriptor. The file descriptor has to be mmap-able. 790 * @offset The offset to the beginning of the file of the area to map. 791 * @memory The memory object to be created. Set to NULL if unsuccessful. 792 */ 793 int NeuronMemory_createFromFd( 794 size_t size, 795 int protect, 796 int fd, 797 size_t offset, 798 NeuronMemory** memory); 799 800 #ifdef __ANDROID__ 801 /** 802 * Creates a shared memory object from an AHardwareBuffer handle. 803 * 804 * We only support AHardwareBuffer with format AHARDWAREBUFFER_FORMAT_BLOB and 805 * it can only be used for Model inputs and outputs. 806 * 807 * The AHardwareBuffer with AHARDWAREBUFFER_FORMAT_BLOB format can be used the 808 * same way as shared memory created from a file handle. See NeuronMemory for 809 * description on how to use this shared memory. 810 * 811 * The provided AHardwareBuffer must outlive the NeuronMemory object. 812 * 813 * Available since 5.0.0 814 * 815 * @param ahwb The AHardwareBuffer handle. 816 * @param memory The memory object to be created. 817 * Set to NULL if unsuccessful. 818 * 819 * @return NEURON_NO_ERROR if the request completed normally. 820 * 821 */ 822 int NeuronMemory_createFromAHardwareBuffer( 823 const AHardwareBuffer* ahwb, 824 NeuronMemory** memory); 825 826 #else // __ANDROID__ 827 828 /** 829 * Not supported at non-android platform 830 * 831 * @return NEURON_BAD_STATE 832 */ 833 int NeuronMemory_createFromAHardwareBuffer(); 834 835 #endif 836 837 /** 838 * Delete a memory object. 839 * 840 * For ion memory, this function cleans up the internal resource associated with 841 * this memory. Applications should clean up the allocated ion memory after this 842 * function. 843 * 844 * Available since 4.1.0 845 */ 846 void NeuronMemory_free(NeuronMemory* memory); 847 848 /** 849 * Create an empty NeuronModel. The model should be constructed with calls to 850 * NeuronModel_addOperation and NeuronModel_addOperand. 851 * 852 * Available since 4.1.0 853 * 854 * @param model The NeuronModel to be created. Set to NULL if unsuccessful. 855 * @return NEURON_NO_ERROR if successful. 856 */ 857 int NeuronModel_create(NeuronModel** model); 858 859 /** 860 * Destroy a model. The model need not have been finished by a call to 861 * NeuronModel_finish. 862 * 863 * Available since 4.1.0 864 * 865 * @param model The model to be destroyed. 866 */ 867 void NeuronModel_free(NeuronModel* model); 868 869 /** 870 * Indicate that we have finished modifying a model. Required before calling 871 * NeuronCompilation_compile. 872 * 873 * Available since 4.1.0 874 * 875 * @param model The model to be finished. 876 * @return NEURON_NO_ERROR if successful. 877 */ 878 int NeuronModel_finish(NeuronModel* model); 879 880 /** 881 * Add an operand to a model. The order in which the operands are added is 882 * important. The first one added to a model will have the index value 0, the 883 * second 1, etc. These indexes are used as operand identifiers in 884 * NeuronModel_addOperation. 885 * 886 * Available since 4.1.0 887 * 888 * @param model The model to be modified. 889 * @param type The NeuronOperandType that describes the shape of the operand. 890 * Neither the NeuronOperandType nor the dimensions it points to need to outlive 891 * the call to NeuronModel_addOperand. 892 * @return NEURON_NO_ERROR if successful. 893 */ 894 int NeuronModel_addOperand(NeuronModel* model, const NeuronOperandType* type); 895 896 /** 897 * Sets an operand to a constant value. 898 * Values of length smaller or equal to 899 * NEURON_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES are immediately copied into the 900 * model. For values of length greater than 901 * NEURON_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES, a pointer to the buffer is 902 * stored within the model. The application must not change the content of this 903 * region until all executions using this model have completed. As the data may 904 * be copied during processing, modifying the data after this call yields 905 * undefined results. 906 * 907 * Attempting to modify a model once NeuronModel_finish has been called will 908 * return an error. 909 * 910 * A special notice on the buffer lifetime when the length is greater than 911 * NEURON_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES. The provided buffer must 912 * outlive the compilation of this model. I.e. user must keep the buffer 913 * unchanged until NeuronCompilation_finish of this model. This is an internal 914 * optimization comparing to NNAPI. In NNAPI, NN runtime will copy the buffer to 915 * a shared memory between NN runtime and NNAPI HIDL service during 916 * ANNModel_finish, and it will be copied again to the compiled result during 917 * ANNCompilation_finish. In Neuron Adapter, there will be only one copying 918 * during NeuronCompilaiton_finish, so it is required to keep the buffer alive 919 * until NeuronCompilaiton_finish returned. 920 * 921 * Available since 4.1.0 922 * 923 * @param model The model to be modified. 924 * @param index The index of the model operand we're setting. 925 * @param buffer A pointer to the data to use. 926 * @param length The size in bytes of the data value. 927 * 928 * @return NEURON_NO_ERROR if successful. 929 */ 930 int NeuronModel_setOperandValue( 931 NeuronModel* model, 932 int32_t index, 933 const void* buffer, 934 size_t length); 935 /** 936 * Sets an operand to a value that is a reference to another NeuronModel. 937 * 938 * The referenced model must already have been finished by a call to 939 * NeuronModel_finish. 940 * 941 * The NeuronModel_relaxComputationFloat32toFloat16 setting of referenced models 942 * is overridden by that setting of the main model of a compilation. 943 * 944 * The referenced model must outlive the model referring to it. 945 * 946 * Attempting to modify a model once NeuronModel_finish has been called will 947 * return an error. 948 * 949 * Available since 4.1.0 950 * 951 * @param model The model to be modified. 952 * @param index The index of the model operand we're setting. 953 * @param value The model to be referenced. 954 * 955 * @return NEURON_NO_ERROR if successful. 956 */ 957 int NeuronModel_setOperandValueFromModel( 958 NeuronModel* model, 959 int32_t index, 960 const NeuronModel* value); 961 962 /** 963 * Sets an operand's per channel quantization parameters 964 * Sets parameters required by a tensor of type 965 * NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL This function must be called for every 966 * tensor of type NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL before calling 967 * NeuronModel_finish 968 * 969 * Available since 4.1.0 970 * 971 * @param model The model to be modified. 972 * @param index The index of the model operand we're setting. 973 * @param channelQuant The per channel quantization parameters for the operand. 974 * No memory in this struct needs to outlive the call to this function. 975 * 976 * @return NEURON_NO_ERROR if successful. 977 */ 978 int NeuronModel_setOperandSymmPerChannelQuantParams( 979 NeuronModel* model, 980 int32_t index, 981 const NeuronSymmPerChannelQuantParams* channelQuant); 982 983 /** 984 * Sets an operand's per channel quantization parameters 985 * Sets parameters required by a tensor of type 986 * NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL or 987 * NEURON_TENSOR_QUANT8_ASYMM_PER_CHANNEL. 988 * This function must be called for every tensor of type 989 * NEURON_TENSOR_QUANT8_SYMM_PER_CHANNEL or 990 * NEURON_TENSOR_QUANT8_ASYMM_PER_CHANNEL before calling NeuronModel_finish. 991 * 992 * Available since 6.0.0 993 * 994 * @param model The model to be modified. 995 * @param index The index of the model operand we're setting. 996 * @param channelQuant The per channel quantization parameters(include 997 * per-channel offset) for the operand. No memory in this struct needs to 998 * outlive the call to this function. 999 * 1000 * @return NEURON_NO_ERROR if successful. 1001 */ 1002 int NeuronModel_setOperandPerChannelQuantParams( 1003 NeuronModel* model, 1004 int32_t index, 1005 const NeuronPerChannelQuantParams* channelQuant); 1006 1007 /** 1008 * Add an operation to a model. 1009 * The operands specified by inputs and outputs must have been previously added 1010 * by calls to NeuronModel_addOperand. 1011 * 1012 * Available since 4.1.0 1013 * 1014 * @param model The model to be modified. 1015 * @param type The NeuronOperationType of the operation. 1016 * @param inputCount The number of entries in the inputs array. 1017 * @param inputs An array of indexes identifying each operand. 1018 * @param outputCount The number of entries in the outputs array. 1019 * @param outputs An array of indexes identifying each operand. 1020 * 1021 * @return NEURON_NO_ERROR if successful. 1022 */ 1023 int NeuronModel_addOperation( 1024 NeuronModel* model, 1025 NeuronOperationType type, 1026 uint32_t inputCount, 1027 const uint32_t* inputs, 1028 uint32_t outputCount, 1029 const uint32_t* outputs); 1030 1031 /** 1032 * Add an operation extension to a model. 1033 * The operands specified by inputs and outputs must have been previously added 1034 * by calls to NeuronModel_addOperand. User needs to specify the operation 1035 * extension name and the desired device which will execute the operation 1036 * extension. 1037 * 1038 * Available since 4.1.0 1039 * 1040 * @param model The model to be modified. 1041 * @param name The name of the operation extension. 1042 * @param vendor The name of the vendor which will implement the operation 1043 * extension. 1044 * @param device The device which will execute the operation extension. 1045 * @param inputCount The number of entries in the inputs array. 1046 * @param inputs An array of indexes identifying each operand. 1047 * @param outputCount The number of entries in the outputs array. 1048 * @param outputs An array of indexes identifying each operand. 1049 * 1050 * @return NEURON_NO_ERROR if successful. 1051 */ 1052 int NeuronModel_addOperationExtension( 1053 NeuronModel* model, 1054 const char* name, 1055 const char* vendor, 1056 const NeuronDevice* device, 1057 uint32_t inputCount, 1058 const uint32_t* inputs, 1059 uint32_t outputCount, 1060 const uint32_t* outputs); 1061 1062 /** 1063 * Specfifies which operands will be the model's inputs and outputs. 1064 * An operand cannot be used for both input and output. Doing so will return an 1065 * error. 1066 * 1067 * The operands specified by inputs and outputs must have been 1068 * previously added by calls to NeuronModel_addOperand. 1069 * 1070 * Attempting to modify a model once NeuronModel_finish has been 1071 * called will return an error. 1072 * 1073 * Available since 4.1.0 1074 * 1075 * @param model The model to be modified. 1076 * @param inputCount The number of entries in the inputs array. 1077 * @param inputs An array of indexes identifying the input operands. 1078 * @param outputCount The number of entries in the outputs array. 1079 * @param outputs An array of indexes identifying the output operands. 1080 * 1081 * @return NEURON_NO_ERROR if successful. 1082 */ 1083 int NeuronModel_identifyInputsAndOutputs( 1084 NeuronModel* model, 1085 uint32_t inputCount, 1086 const uint32_t* inputs, 1087 uint32_t outputCount, 1088 const uint32_t* outputs); 1089 1090 /** 1091 * Gets the supported operations in a model. 1092 * This function must be called after calling NeuronModel_finish 1093 * 1094 * Available since 4.1.0 1095 * 1096 * @param model The model to be queried. 1097 * @param supported The boolean array to be filled. True means supported. The 1098 * size of the boolean array must be at least as large as the number of 1099 * operations in the model. The order of elements in the supported array matches 1100 * the order in which the corresponding operations were added to the model. 1101 * @param operationCount number of operations in the model 1102 * 1103 * @return NEURON_NO_ERROR if successful. 1104 */ 1105 int NeuronModel_getSupportedOperations( 1106 NeuronModel* model, 1107 bool* supported, 1108 uint32_t operationCount); 1109 1110 /** 1111 * Get the supported operations for a specified set of devices. 1112 * If multiple devices are selected, the supported operation list is a union of 1113 * supported operations of all selected devices. 1114 * 1115 * Available since 4.1.0 1116 * 1117 * @param model The model to be queried. 1118 * @param devices Selected devices 1119 * @param numDevices Number of selected devices 1120 * @param supportedOps The boolean array to be filled. True means supported. The 1121 * size of the boolean array must be as least as large as the number of 1122 * operations in the model. The order of elements in the supportedOps array 1123 * matches the order in which the corresponding operations were added to the 1124 * model. 1125 * 1126 * @return NEURON_NO_ERROR if successful. 1127 */ 1128 int NeuronModel_getSupportedOperationsForDevices( 1129 const NeuronModel* model, 1130 const NeuronDevice* const* devices, 1131 uint32_t numDevices, 1132 bool* supportedOps); 1133 1134 /** 1135 * Specifies whether NEURON_TENSOR_FLOAT32 is allowed to be calculated with 1136 * range and/or precision as low as that of the IEEE 754 16-bit floating-point 1137 * format. By default, NEURON_TENSOR_FLOAT32 must be calculated using at least 1138 * the range and precision of the IEEE 754 32-bit floating-point format. 1139 * 1140 * Available since 4.1.0 1141 * 1142 * @param model The model to be modified. 1143 * @param allow 'true' indicates NEURON_TENSOR_FLOAT32 may be calculated with 1144 * range and/or precision as low as that of the IEEE 754 16-bit floating point 1145 * format. 'false' indicates NEURON_TENSOR_FLOAT32 must be calculated using at 1146 * least the range and precision of the IEEE 754 32-bit floating point format. 1147 * 1148 * @return NEURON_NO_ERROR if successful. 1149 */ 1150 int NeuronModel_relaxComputationFloat32toFloat16( 1151 NeuronModel* model, 1152 bool allow); 1153 1154 /** 1155 * Hint compiler to suppress the input data conversion, the users have to 1156 * convert the input data into platform-expected format before inference. 1157 * 1158 * Available since 4.2.0 1159 * 1160 * @param model The model to be modified. 1161 * @param suppress True to suppress the input data conversion. 1162 * @return NEURON_NO_ERROR if successful. 1163 */ 1164 int NeuronModel_suppressInputConversion(NeuronModel* model, bool suppress); 1165 1166 /** 1167 * Hint compiler to suppress the output data conversion, the users have to 1168 * convert the output data from platform-generated format before inference. 1169 * 1170 * Available since 4.2.0 1171 * 1172 * @param model The model to be modified. 1173 * @param suppress True to suppress the output data conversion. 1174 * @return NEURON_NO_ERROR if successful. 1175 */ 1176 int NeuronModel_suppressOutputConversion(NeuronModel* model, bool suppress); 1177 1178 /** 1179 * Restore the compiled network using user provided buffer. 1180 * 1181 * The restored NeuronCompilaton could be used in creating executing instance. 1182 * The restored NeuronModel cannot be recompiled. 1183 * 1184 * Available since 4.3.0 1185 * 1186 * @param model Restored model. 1187 * @param compilation Restored compilation 1188 * @param buffer User provided buffer to restore the compiled network. 1189 * @param size Size of the user provided buffer in bytes. 1190 * @return NEURON_NO_ERROR if compiled network is successfully copied to the 1191 * user allocated buffer. NEURON_BAD_DATA if it fails to load the compiled 1192 * network, this could either be the version is not matched or the data is 1193 * corrupted. 1194 */ 1195 int NeuronModel_restoreFromCompiledNetwork( 1196 NeuronModel** model, 1197 NeuronCompilation** compilation, 1198 const void* buffer, 1199 const size_t size); 1200 1201 /** 1202 * Restore the compiled network using user provided buffer. 1203 * Support multiple compilation type; choices are: COMPILATION_TYPE_BATCHED, 1204 * COMPILATION_TYPE_EXECUTION_CONTROLLER, COMPILATION_TYPE_EXECUTION_CONTROLLER, 1205 * and COMPILATION_TYPE_NORMAL. 1206 * 1207 * There are two ways to use Batched Compilation: 1208 * 1) load from DLA. 1209 * 2) create batched compilation directly. 1210 * To load DLA, one should call NeuronCompilation_create and 1211 * NeuronModel_restoreFromCompiledNetworkV2. To create directly, one should call 1212 * NeuronCompilation_createForBatch. 1213 * 1214 * The restored NeuronCompilaton could be used in creating executing instance. 1215 * The restored NeuronModel cannot be recompiled. 1216 * 1217 * Available since 7.0.0 1218 * 1219 * @param model Restored model. 1220 * @param compilation Restored compilation 1221 * @param buffer User provided buffer to restore the compiled network. 1222 * @param size Size of the user provided buffer in bytes. 1223 * @param type Type of the compilation needed to be restored. 1224 * @return NEURON_NO_ERROR if compiled network is successfully copied to the 1225 * user allocated buffer. NEURON_BAD_DATA if it fails to load the compiled 1226 * network, this could either be the version is not matched or the data is 1227 * corrupted. 1228 */ 1229 int NeuronModel_restoreFromCompiledNetworkV2( 1230 NeuronModel** model, 1231 NeuronCompilation** compilation, 1232 const void* buffer, 1233 const size_t size, 1234 const CompilationType& type); 1235 1236 /** 1237 * Set a string into model that can be used for recognition for user. 1238 * It's only used for debug, the string can be dumped into log and make users 1239 * check the model behavior easily. 1240 * 1241 * Available since 7.0.0 1242 * 1243 * @param model The model to be modified. 1244 * @param name The string, user can free buffer 'name' after calling this API. 1245 * @return NEURON_NO_ERROR if the string is set success. NEURON_UNEXPECTED_NULL 1246 * if the input param is nullptr. 1247 */ 1248 int NeuronModel_setName(NeuronModel* model, const char* name); 1249 1250 /** 1251 * Create a NeuronCompilation to compile the given model. 1252 * 1253 * This function only creates the object. Compilation is only performed once 1254 * NeuronCompilation_finish is invoked. NeuronCompilation_finish should be 1255 * called once all desired properties have been set on the compilation. 1256 * NeuronModel_free should be called once the compilation is no longer needed. 1257 * The provided model must outlive the compilation. The model must already have 1258 * been finished by a call to NeuronModel_finish. 1259 * 1260 * Available since 4.1.0 1261 * 1262 * @param model The NeuronModel to be compiled. 1263 * @param compilation The newly created object or NULL if unsuccessful. 1264 * 1265 * @return NEURON_NO_ERROR if successful 1266 */ 1267 int NeuronCompilation_create( 1268 NeuronModel* model, 1269 NeuronCompilation** compilation); 1270 1271 /** 1272 * Create a NeuronCompilation with different purpose to compile the given model. 1273 * 1274 * This function only creates the object. Compilation is only performed once 1275 * NeuronCompilation_finish is invoked. NeuronCompilation_finish should be 1276 * called once all desired properties have been set on the compilation. 1277 * NeuronModel_free should be called once the compilation is no longer needed. 1278 * The provided model must outlive the compilation. The model must already have 1279 * been finished by a call to NeuronModel_finish. 1280 * 1281 * Available since 7.0.1 1282 * 1283 * @param model The NeuronModel to be compiled. 1284 * @param type Type of the compilation needed to be created. 1285 * @param options The options which used to create with compilation. 1286 * @param compilation The newly created object or NULL if unsuccessful. 1287 * 1288 * @return NEURON_NO_ERROR if successful 1289 */ 1290 int NeuronCompilation_createV2( 1291 NeuronModel* model, 1292 CompilationType type, 1293 const char* options, 1294 NeuronCompilation** compilation); 1295 1296 /** 1297 * Destroy a compilation. 1298 * 1299 * Available since 4.1.0 1300 * 1301 * @param compilation The compilation to be destroyed. 1302 */ 1303 void NeuronCompilation_free(NeuronCompilation* compilation); 1304 1305 /** 1306 * Compilation is finished once NeuronCompilation_finish is invoked. Required 1307 * before calling NeuronExecution_create. This function must only be called once 1308 * for a given compilation. 1309 * 1310 * Available since 4.1.0 1311 * 1312 * @param compilation The compilation to be finished. 1313 * 1314 * @return NEURON_NO_ERROR if successful. 1315 */ 1316 int NeuronCompilation_finish(NeuronCompilation* compilation); 1317 1318 /** 1319 * Gets the supported operations in a model with specific optimized configures. 1320 * This function must be called before calling NeuronCompilation_finish. 1321 * 1322 * Available since 7.0.0 1323 * 1324 * @param compilation The compilation to be queried. 1325 * @param operationCount number of operations in the model 1326 * @param supported The boolean array to be filled. True means supported. The 1327 * size of the boolean array must be at least as large as the number of 1328 * operations in the model. The order of elements in the supported array matches 1329 * the order in which the corresponding operations were added to the model. 1330 * 1331 * @return NEURON_NO_ERROR if successful. 1332 */ 1333 int NeuronCompilation_getSupportedOperations( 1334 NeuronCompilation* compilation, 1335 uint32_t operationCount, 1336 bool* supported); 1337 1338 /** 1339 * Provides optional caching information for faster re-compilation. 1340 * 1341 * Available since 4.1.0 1342 * 1343 * @param compilation The compilation to be cached. 1344 * @param cacheDir The cache directory for storing and retrieving caching data. 1345 * The user should choose a directory local to the application, and is 1346 * responsible for managing the cache entries. 1347 * @param token The token provided by the user to specify a model must be of 1348 * length NEURON_BYTE_SIZE_OF_CACHE_TOKEN. The user should ensure that the token 1349 * is unique to a model within the application. Neuron cannot detect token 1350 * collisions; a collision will result in a failed execution or in a successful 1351 * execution that produces incorrect output values. 1352 * 1353 * @return NEURON_NO_ERROR if successful. 1354 */ 1355 int NeuronCompilation_setCaching( 1356 NeuronCompilation* compilation, 1357 const char* cacheDir, 1358 const uint8_t* token); 1359 1360 /** 1361 * Hint compiler with the size of L1 memory, this value should not be larger 1362 * than real platform's settings. The user can get the platform's L1 memory size 1363 * in KB by calling Neuron_getL1MemorySizeKb. 1364 * 1365 * Available since 4.3.0 1366 * 1367 * @param compilation The compilation to be modified. 1368 * @param sizeKb L1 memory size in KB. 1369 * 1370 * @return NEURON_NO_ERROR if successful. 1371 */ 1372 int NeuronCompilation_setL1MemorySizeKb( 1373 NeuronCompilation* compilation, 1374 uint32_t sizeKb); 1375 1376 /** 1377 * Create a NeuronCompilation to compile the given model for a specified set of 1378 * devices. The user must handle all compilation and execution failures from the 1379 * specified set of devices. This is in contrast to a use of 1380 * NeuronCompilation_create, where neuron will attempt to recover from such 1381 * failures. 1382 * 1383 * Available since 4.1.0 1384 * 1385 * @param model The NeuronModel to be compiled. 1386 * @param devices The set of devices. Must not contain duplicates. 1387 * @param numDevices The number of devices in the set. 1388 * @param compilation The newly created object or NULL if unsuccessful. 1389 * 1390 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the model is 1391 * invalid. 1392 */ 1393 int NeuronCompilation_createForDevices( 1394 NeuronModel* model, 1395 const NeuronDevice* const* devices, 1396 uint32_t numDevices, 1397 NeuronCompilation** compilation); 1398 1399 /** 1400 * Create a NeuronCompilation. Which can divide one graph into several subgraph 1401 * and use the information to debug. 1402 * 1403 * Only be used in debug purpose, no guarantees performance and thread safe. 1404 * 1405 * Available since 5.0.0 1406 * 1407 * @param model The NeuronModel to be compiled. 1408 * @param compilation The newly created object or NULL if unsuccessful. 1409 * 1410 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the model is 1411 * invalid. 1412 */ 1413 int NeuronCompilation_createForDebug( 1414 NeuronModel* model, 1415 NeuronCompilation** compilation); 1416 1417 /** 1418 * Sets the execution preference associated with this compilation. 1419 * 1420 * Default value of preference is PREFER_SINGLE_FAST_ANSWER 1421 * 1422 * Available since 4.1.0 1423 * 1424 * @param compilation The compilation to be modified. 1425 * @param preference Either NEURON_PREFER_LOW_POWER, 1426 * NEURON_PREFER_SINGLE_FAST_ANSWER, or NEURON_PREFER_SUSTAINED_SPEED. 1427 * 1428 * @return NEURON_NO_ERROR if successful. 1429 */ 1430 int NeuronCompilation_setPreference( 1431 NeuronCompilation* compilation, 1432 int32_t preference); 1433 1434 /** 1435 * Sets the execution priority associated with this compilation. 1436 * 1437 * Execution priorities are relative to other executions created by the same 1438 * application (specifically same uid) for the same device. Specifically, 1439 * priorities of executions from one application will not affect executions from 1440 * another application. 1441 * 1442 * Higher priority executions may use more compute resources than lower priority 1443 * executions, and may preempt or starve lower priority executions. 1444 * 1445 * Available since 4.1.0 1446 * 1447 * @param compilation The compilation to be modified. 1448 * @param priority The relative priority of the execution compared to other 1449 * executions created by the application. Must be one of NEURON_PRIORITY_*. 1450 * 1451 * @return NEURON_NO_ERROR if successful. 1452 */ 1453 int NeuronCompilation_setPriority(NeuronCompilation* compilation, int priority); 1454 1455 /** 1456 * Get the padded dimensional information of the specified input operand of the 1457 * compilation. This function must be called after calling 1458 * NeuronCompilation_finish. If NeuronModel_suppressInputConversion was not 1459 * applied to the model to be compiled, the returned dimensions are the padded 1460 * dimension after NeuronCompilation_finish to satisfy the optimization 1461 * requirement from the underlying hardware accelerators. 1462 * If NeuronModel_suppressInputConversion was applied to the model to be 1463 * compiled, the returned dimensions are the same as the original dimensions 1464 * given from user. 1465 * 1466 * Available since 4.2.0 1467 * 1468 * @param compilation The compilation to be queried. 1469 * @param index The index of the input operand we are querying. It is an index 1470 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1471 * index associated with NeuronModel_addOperand. 1472 * @param dimensions The dimension array to be filled. The size of the array 1473 * must be exactly as large as the rank of the input operand to be queried in 1474 * the model. 1475 * @return NEURON_NO_ERROR if successful. 1476 */ 1477 int NeuronCompilation_getInputPaddedDimensions( 1478 NeuronCompilation* compilation, 1479 int32_t index, 1480 uint32_t* dimensions); 1481 1482 /** 1483 * Get the padded dimensional information of the specified output operand of the 1484 * compilation. This function must be called after calling 1485 * NeuronCompilation_finish. If NeuronModel_suppressOutputConversion was not 1486 * applied to the model to be compiled, the returned dimensions are the padded 1487 * dimension after NeuronCompilation_finish to satisfy the optimization 1488 * requirement from the underlying hardware accelerators. 1489 * If NeuronModel_suppressOutputConversion was applied to the model to be 1490 * compiled, the returned dimensions are the same as the original dimensions 1491 * given from user. 1492 * 1493 * Available since 4.2.0 1494 * 1495 * @param compilation The compilation to be queried. 1496 * @param index The index of the output operand we are querying. It is an index 1497 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1498 * index associated with NeuronModel_addOperand. 1499 * @param dimensions The dimension array to be filled. The size of the array 1500 * must be exactly as large as the rank of the output operand to be queried in 1501 * the model. 1502 * @return NEURON_NO_ERROR if successful. 1503 */ 1504 int NeuronCompilation_getOutputPaddedDimensions( 1505 NeuronCompilation* compilation, 1506 int32_t index, 1507 uint32_t* dimensions); 1508 1509 /** 1510 * Get the expected buffer size (bytes) of the specified input operand of the 1511 * compilation. If NeuronModel_suppressInputConversion was not applied to the 1512 * model to be compiled, the returned size are the padded size after 1513 * NeuronCompilation_finish to satisfy the optimization requirement from the 1514 * underlying hardware accelerators. If NeuronModel_suppressInputConversion was 1515 * applied to the model to be compiled, the returned size are the same as the 1516 * original size given from user. 1517 * 1518 * Available since 4.2.0 1519 * 1520 * @param compilation The compilation to be queried. 1521 * @param index The index of the input operand we are querying. It is an index 1522 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1523 * index associated with NeuronModel_addOperand. 1524 * @param size the expected buffer size in bytes. 1525 * @return NEURON_NO_ERROR if successful. 1526 */ 1527 int NeuronCompilation_getInputPaddedSize( 1528 NeuronCompilation* compilation, 1529 int32_t index, 1530 size_t* size); 1531 1532 /** 1533 * Get the expected buffer size (bytes) of the specified output operand of the 1534 * compilation. If NeuronModel_suppressOutputConversion was not applied to the 1535 * model to be compiled, the returned size are the padded size after 1536 * NeuronCompilation_finish to satisfy the optimization requirement from the 1537 * underlying hardware accelerators. If NeuronModel_suppressOutputConversion was 1538 * applied to the model to be compiled, the returned size are the same as the 1539 * original size given from user. 1540 * 1541 * Available since 4.2.0 1542 * 1543 * @param compilation The compilation to be queried. 1544 * @param index The index of the output operand we are querying. It is an index 1545 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1546 * index associated with NeuronModel_addOperand. 1547 * @param size the expected buffer size in bytes. 1548 * @return NEURON_NO_ERROR if successful. 1549 */ 1550 int NeuronCompilation_getOutputPaddedSize( 1551 NeuronCompilation* compilation, 1552 int32_t index, 1553 size_t* size); 1554 1555 /** 1556 * Get the compiled network size of the compilation. 1557 * 1558 * This must be called after NeuronCompilation_finished and before 1559 * NeuronExecution_create. It is not allowed to call this with a compilation 1560 * restored from cache. 1561 * 1562 * Available since 4.3.0 1563 * 1564 * @param compilation The compilation to be queried. 1565 * @param size The compiled network size in bytes. 1566 * @return NEURON_NO_ERROR if successful. 1567 */ 1568 int NeuronCompilation_getCompiledNetworkSize( 1569 NeuronCompilation* compilation, 1570 size_t* size); 1571 1572 /** 1573 * Store the compiled network. 1574 * 1575 * Users have to allocate the buffer with the specified size before calling this 1576 * function. 1577 * 1578 * This must be called after NeuronCompilation_finished and before 1579 * NeuronExecution_create. It is not allowed to call this with a compilation 1580 * restored from cache. 1581 * 1582 * Available since 4.3.0 1583 * 1584 * @param compilation The compilation to be queried. 1585 * @param buffer User allocated buffer to store the compiled network. 1586 * @param size Size of the user allocated buffer in bytes. 1587 * @return NEURON_NO_ERROR if compiled network is successfully copied to the 1588 * user allocated buffer. 1589 */ 1590 int NeuronCompilation_storeCompiledNetwork( 1591 NeuronCompilation* compilation, 1592 void* buffer, 1593 const size_t size); 1594 /** 1595 * Hint the compiler to apply the optimization strategy according to the user 1596 * specified parameters. 1597 * 1598 * Available since 4.3.0 1599 * 1600 * @param compilation The compilation to be modified. 1601 * @param optimizationCode User specified optimization strategy. Must be one of 1602 * NEURON_OPTIMIZATION_* or the inclusive OR value of multiple 1603 * NEURON_OPTIMIZATION_*. 1604 * 1605 * @return NEURON_NO_ERROR if successful. 1606 */ 1607 int NeuronCompilation_setOptimizationHint( 1608 NeuronCompilation* compilation, 1609 uint32_t optimizationCode); 1610 1611 /** 1612 * Hint the compiler to apply the optimization strategy according to the user 1613 * specified arguments in a null-terminated string. 1614 * 1615 * Available since 4.6.0 1616 * 1617 * @param compilation The compilation to be modified. 1618 * @param optimizationString A null-terminated string to represent the user 1619 * specified optimization strategy. 1620 * @return NEURON_NO_ERROR if successful. 1621 */ 1622 int NeuronCompilation_setOptimizationString( 1623 NeuronCompilation* compilation, 1624 const char* optimizationString); 1625 1626 /** 1627 * Only allow users' optimization string(from 1628 * NeuronCompilation_setOptimizationString), the system won't set any compiler 1629 * options for them. 1630 * 1631 * Available since 6.0.5 1632 * 1633 * @param compilation The compilation to be modified. 1634 * @param allow Allow only use user's setting or not. 1635 * strategy. 1636 * @return NEURON_NO_ERROR if successful. 1637 */ 1638 int NeuronCompilation_setOnlyAllowOptimizationString( 1639 NeuronCompilation* compilation, 1640 bool allow); 1641 1642 /** 1643 * Get the compiler hints which are used to apply the optimization strategy 1644 * according to the user specified arguments in a null-terminated string. 1645 * 1646 * Available since 6.0.5 1647 * 1648 * @param compilation The compilation to be modified. 1649 * @param optimizationString A null-terminated string to represent the user 1650 * specified optimization strategy. 1651 * @return NEURON_NO_ERROR if successful. 1652 */ 1653 int NeuronCompilation_getOptimizationString( 1654 NeuronCompilation* compilation, 1655 const char** optimizationString); 1656 1657 /** 1658 * Hint compiler to trim the model IO alignment. 1659 * 1660 * Available since 4.4.8 1661 * 1662 * @param compilation The compilation to be modified. 1663 * @param enable 'true' for trimming model IO alignment. 1664 * 1665 * @return NEURON_NO_ERROR if successful. 1666 */ 1667 int NeuronCompilation_setTrimIOAlignment( 1668 NeuronCompilation* compilation, 1669 bool enable); 1670 1671 /** 1672 * Hint compiler to use software dilated convolution 1673 * 1674 * Available since 4.4.8 1675 * 1676 * @param compilation The compilation to be modified. 1677 * @param enable 'true' indicates a hint to compiler to use software dilated 1678 * convolution 1679 * 1680 * @return NEURON_NO_ERROR if successful. 1681 */ 1682 int NeuronCompilation_setSWDilatedConv( 1683 NeuronCompilation* compilation, 1684 bool enable); 1685 1686 /** 1687 * Create a new execution instance by calling the NeuronExecution_create 1688 * function. The provided compilation must outlive the execution. 1689 * 1690 * Available since 4.1.0 1691 * 1692 * @param compilation The NeuronCompilation to be evaluated. 1693 * @param execution The newly created object or NULL if unsuccessful. 1694 * 1695 * @return NEURON_NO_ERROR if successful 1696 */ 1697 int NeuronExecution_create( 1698 NeuronCompilation* compilation, 1699 NeuronExecution** execution); 1700 1701 /** 1702 * Destroy an execution. 1703 * 1704 * Available since 4.1.0 1705 * 1706 * @param execution The execution to be destroyed. 1707 */ 1708 void NeuronExecution_free(NeuronExecution* execution); 1709 1710 /** 1711 * Associate a user buffer with an input of the model of the NeuronExecution. 1712 * The provided buffer must outlive the execution. 1713 * 1714 * Available since 4.1.0 1715 * 1716 * @param execution The execution to be modified. 1717 * @param index The index of the input argument we are setting. It is an index 1718 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1719 * index associated with NeuronModel_addOperand. 1720 * @param type The NeuronOperandType of the operand. Currently NeuronAdapter 1721 * only takes NULL. 1722 * @param buffer The buffer containing the data. 1723 * @param length The length in bytes of the buffer. 1724 * 1725 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the name is not 1726 * recognized or the buffer is too small for the input. 1727 */ 1728 int NeuronExecution_setInput( 1729 NeuronExecution* execution, 1730 int32_t index, 1731 const NeuronOperandType* type, 1732 const void* buffer, 1733 size_t length); 1734 1735 /** 1736 * Associate a user buffer with an output of the model of the NeuronExecution. 1737 * The provided buffer must outlive the execution. 1738 * 1739 * Available since 4.1.0 1740 * 1741 * @param execution The execution to be modified. 1742 * @param index The index of the output argument we are setting. It is an index 1743 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1744 * index associated with NeuronModel_addOperand. 1745 * @param type The NeuronOperandType of the operand. Currently NeuronAdapter 1746 * only takes NULL. 1747 * @param buffer The buffer where the data is to be written. 1748 * @param length The length in bytes of the buffer. 1749 * 1750 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the name is not 1751 * recognized or the buffer is too small for the output. 1752 */ 1753 int NeuronExecution_setOutput( 1754 NeuronExecution* execution, 1755 int32_t index, 1756 const NeuronOperandType* type, 1757 void* buffer, 1758 size_t length); 1759 1760 /** 1761 * Associate part of a memory object with an input of the model of the 1762 * NeuronExecution. 1763 * 1764 * The provided memory must outlive the execution and should not be changed 1765 * during computation. 1766 * 1767 * Available since 4.1.0 1768 * 1769 * @param execution The execution to be modified. 1770 * @param index The index of the input argument we are setting. It is an index 1771 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1772 * index associated with Neuronodel_addOperand. 1773 * @param type The NeuronOperandType of the operand. Currently NueronAdapter 1774 * only takes NULL. 1775 * @param memory The memory containing the data. 1776 * @param offset This specifies the location of the data within the memory. The 1777 * offset is in bytes from the start of memory. 1778 * @param length The size in bytes of the data value. 1779 * 1780 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the name is not 1781 * recognized or the buffer is too small for the input. 1782 */ 1783 int NeuronExecution_setInputFromMemory( 1784 NeuronExecution* execution, 1785 uint32_t index, 1786 const NeuronOperandType* type, 1787 const NeuronMemory* memory, 1788 size_t offset, 1789 size_t length); 1790 1791 /** 1792 * Associate part of a memory object with an output of the model of the 1793 * NeuronExecution. 1794 * 1795 * The provided memory must outlive the execution and should not be changed 1796 * during computation. 1797 * 1798 * Available since 4.1.0 1799 * 1800 * @param execution The execution to be modified. 1801 * @param index The index of the output argument we are setting. It is an index 1802 * into the lists passed to NeuronModel_identifyInputsAndOutputs. It is not the 1803 * index associated with Neuronodel_addOperand. 1804 * @param type The NeuronOperandType of the operand. Currently NueronAdapter 1805 * only takes NULL. 1806 * @param memory The memory containing the data. 1807 * @param offset This specifies the location of the data within the memory. The 1808 * offset is in bytes from the start of memory. 1809 * @param length The size in bytes of the data value. 1810 * 1811 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the name is not 1812 * recognized or the buffer is too small for the input. 1813 */ 1814 int NeuronExecution_setOutputFromMemory( 1815 NeuronExecution* execution, 1816 uint32_t index, 1817 const NeuronOperandType* type, 1818 const NeuronMemory* memory, 1819 size_t offset, 1820 size_t length); 1821 1822 /** 1823 * Schedule synchronous evaluation of the execution. 1824 * Returns once the execution has completed and the outputs are ready to be 1825 * consumed. 1826 * 1827 * Available since 4.1.0 1828 * 1829 * @param execution The execution to be scheduled and executed. 1830 * 1831 * @return NEURON_NO_ERROR if the execution completed normally. NEURON_BAD_STATE 1832 * if the inference fails. Add two return code since 5.0.0 1833 * (NEURON_MISSED_DEADLINE_TRANSIENT if inference timeout, and 1834 * NEURON_OUTPUT_INSUFFICIENT_SIZE if given outsize is not sufficient for real 1835 * output) 1836 * 1837 */ 1838 int NeuronExecution_compute(NeuronExecution* execution); 1839 1840 /** 1841 * Schedule asynchronous evaluation of the execution with dependencies. 1842 * 1843 * The execution will wait for all the depending events to be signaled before 1844 * starting the evaluation. Once the execution has completed and the outputs 1845 * are ready to be consumed, the returned event will be signaled. Depending on 1846 * which devices are handling the execution, the event could be backed by a sync 1847 * fence. Use NeuronEvent_wait to wait for that event. 1848 * 1849 * NeuronEvent_wait must be called to recurperate the resources used by the 1850 * execution. 1851 * 1852 * If parts of the execution are scheduled on devices that do not support fenced 1853 * execution, the function call may wait for such parts to finish before 1854 * returning. 1855 * 1856 * The function will return an error if any of the events in dependencies is 1857 * already in a bad state. After the execution is scheduled, if any of the 1858 * events in dependencies does not complete normally, the execution will fail, 1859 * and NeuronEvent_wait on the returned event will return an error. 1860 * 1861 * The function will return an error if any of the execution outputs has a 1862 * tensor operand type that is not fully specified. 1863 * 1864 * @param execution The execution to be scheduled and executed. 1865 * @param dependencies A set of depending events. The actual evaluation will not 1866 * start until all the events are signaled. 1867 * @param num_dependencies The number of events in the dependencies set. 1868 * @param duration currently not used 1869 * @param event The event that will be signaled on completion. event is set to 1870 * NULL if there's an error. 1871 * 1872 * @return NEURON_NO_ERROR if the evaluation is successfully scheduled. 1873 * 1874 * Available since 5.0.0 1875 */ 1876 int NeuronExecution_startComputeWithDependencies( 1877 NeuronExecution* execution, 1878 const NeuronEvent* const* dependencies, 1879 uint32_t num_dependencies, 1880 uint64_t duration, 1881 NeuronEvent** event); 1882 1883 /** 1884 * Set the maximum duration of WHILE loops in the specified execution. 1885 * 1886 * @param execution The execution to be modified. 1887 * @param duration The maximum amount of time in nanoseconds. 1888 * @return NEURON_NO_ERROR if successful. 1889 * 1890 * Available since 5.0.0 1891 */ 1892 int NeuronExecution_setLoopTimeout( 1893 NeuronExecution* execution, 1894 uint64_t duration); 1895 1896 /** 1897 * Get the default timeout value for WHILE loops. 1898 * 1899 * @return The default timeout value in nanoseconds. 1900 * 1901 * Available since 5.0.0 1902 */ 1903 uint64_t Neuron_getDefaultLoopTimeout(); 1904 1905 /** 1906 * Get the maximum timeout value for WHILE loops. 1907 * 1908 * @return The maximum timeout value in nanoseconds. 1909 * 1910 * Available since 5.0.0 1911 */ 1912 uint64_t Neuron_getMaximumLoopTimeout(); 1913 1914 /** 1915 * Sets the execution boost hint associated with this execution. Required before 1916 * calling NeuronExecution_compute. 1917 * 1918 * Execution boost is the hint for the device frequency, ranged between 0 1919 * (lowest) to 100 (highest). For the compilation with preference set as 1920 * NEURON_PREFER_SUSTAINED_SPEED, scheduler guarantees that the executing boost 1921 * value would equal to the boost value hint. 1922 * 1923 * On the other hand, for the compilation with preference set as 1924 * NEURON_PREFER_LOW_POWER, scheduler would try to save power by configuring the 1925 * executing boost value with some value that is not higher than the boost value 1926 * hint. 1927 * 1928 * Available since 4.1.0 1929 * 1930 * @param execution The execution to be modified. 1931 * @param boostValue The hint for the device frequency, ranged between 0 1932 * (lowest) to 100 (highest). 1933 * 1934 * @return NEURON_NO_ERROR if successful. 1935 */ 1936 int NeuronExecution_setBoostHint( 1937 NeuronExecution* execution, 1938 uint8_t boostValue); 1939 1940 /** 1941 * Sets the execution CPU cache flush hint associated with this execution. 1942 * Required before calling NeuronExecution_setInputFromMemory and 1943 * NeuronExecution_setOutputFromMemory. 1944 * 1945 * Default value of preference is NEURON_CACHE_FLUSH_ENABLE_ALL 1946 * 1947 * Available since 5.0.1 1948 * 1949 * @param execution The execution to be modified. 1950 * @param hint It is either NEURON_CACHE_FLUSH_ENABLE_ALL or the bitwise OR 1951 * of one or more of the following flags: NEURON_CACHE_FLUSH_DISABLE_SYNC_INPUT, 1952 * NEURON_CACHE_FLUSH_DISABLE_INVALIDATE_OUTPUT. 1953 * 1954 * @return NEURON_NO_ERROR if successful. 1955 */ 1956 int NeuronExecution_setCacheFlushHint( 1957 NeuronExecution* execution, 1958 uint8_t flushHint); 1959 1960 /** 1961 * Get the dimensional information of the specified output operand of the model 1962 * of the latest computation evaluated on {@link NeuronExecution}. 1963 * 1964 * This function may only be invoked when the execution is in the completed 1965 * state. 1966 * 1967 * Available since 5.0.0 1968 * 1969 * @param execution The execution to be queried. 1970 * @param index The index of the output argument we are querying. It is 1971 * an index into the lists passed to {@link 1972 * NeuronModel_identifyInputsAndOutputs}. 1973 * @param rank The rank of the output operand. 1974 * 1975 * @return NEURON_NO_ERROR if successful. 1976 */ 1977 int NeuronExecution_getOutputOperandRank( 1978 NeuronExecution* execution, 1979 int32_t index, 1980 uint32_t* rank); 1981 1982 /** 1983 * Get the dimensional information of the specified output operand of the model 1984 * of the latest computation evaluated on {@link NeuronExecution}. The target 1985 * output operand cannot be a scalar. 1986 * 1987 * This function may only be invoked when the execution is in the completed 1988 * state. 1989 * 1990 * Available since 5.0.0 1991 * 1992 * @param execution The execution to be queried. 1993 * @param index The index of the output argument we are querying. It is 1994 * an index into the lists passed to {@link 1995 * NeuronModel_identifyInputsAndOutputs}. 1996 * @param dimensions The dimension array to be filled. The size of the array 1997 * must be exactly as large as the rank of the output operand to be queried in 1998 * the model. 1999 * 2000 * @return NEURON_NO_ERROR if successful. 2001 */ 2002 int NeuronExecution_getOutputOperandDimensions( 2003 NeuronExecution* execution, 2004 int32_t index, 2005 uint32_t* dimensions); 2006 2007 /** 2008 * Create a NeuronCompilation which can create executions with shared static 2009 * memory. 2010 * 2011 * This function only creates the object. Compilation is only performed once 2012 * NeuronCompilation_finish is invoked. NeuronCompilation_finish should be 2013 * called once all desired properties have been set on the compilation. 2014 * NeuronModel_free should be called once the compilation is no longer needed. 2015 * The provided model must outlive the compilation. The model must already have 2016 * been finished by a call to NeuronModel_finish. 2017 * 2018 * Available since 7.0.0 2019 * 2020 * @param model The NeuronModel to be compiled. 2021 * @param compilation The newly created object or NULL if unsuccessful. 2022 * 2023 * @return NEURON_NO_ERROR if successful 2024 */ 2025 int NeuronCompilation_createForBatch( 2026 NeuronModel* model, 2027 NeuronCompilation** compilation); 2028 2029 /** 2030 * Set the size of runner pool, and create same number of runners. 2031 * 2032 * The execution must created by the following steps: 2033 * NeuronCompilation_createForBatch, NeuronCompilation_finish, 2034 * NeuronExecution_create. 2035 * 2036 * The execution created from this compilation has to use 2037 * NeuronExecution_setRunnerPoolSize to create thread pool and then set a series 2038 * of inputs & outputs into the execution. The execution will inference with the 2039 * series of inputs. 2040 * 2041 * Available since 7.0.0 2042 * 2043 * @param execution The NeuronExecution to be utilized. 2044 * @param numRunners The number of runner need to be created. 2045 * 2046 * @return NEURON_NO_ERROR if successful 2047 * @return NEURON_BAD_STATE if the compilation is not created via 2048 * NeuronCompilation_createForBatch. 2049 */ 2050 int NeuronExecution_setRunnerPoolSize( 2051 NeuronExecution* execution, 2052 uint8_t numRunners); 2053 2054 /** 2055 * Notify the execution that all inputs / outputs have been set. 2056 * Should be called after NeuronExecution_setInputFromMemory and 2057 * NeuronExecution_setOutputFromMemory. 2058 * 2059 * The execution must created by the following steps: 2060 * NeuronCompilation_createForBatch, NeuronCompilation_finish, 2061 * NeuronExecution_create. 2062 * 2063 * Available since 7.0.0 2064 * 2065 * @param execution The NeuronExecution to be utilized. 2066 * 2067 * @return NEURON_NO_ERROR if successful 2068 * @return NEURON_BAD_STATE if the compilation is not created via 2069 * NeuronCompilation_createForBatch. 2070 */ 2071 int NeuronExecution_setBatchDone(NeuronExecution* execution); 2072 2073 /** 2074 * Notify the execution that all inputs / outputs have been set. 2075 * Should be called after NeuronExecution_setInputFromMemory and 2076 * NeuronExecution_setOutputFromMemory. 2077 * 2078 * The execution must created by the following steps: 2079 * 1. NeuronCompilation_createV2 with COMPILATION_TYPE_EXECUTION_CONTROLLER 2080 * 2. NeuronCompilation_finish 2081 * 3. NeuronExecution_create. 2082 * or 2083 * 1. NeuronModel_restoreFromCompiledNetworkV2 with 2084 * COMPILATION_TYPE_EXECUTION_CONTROLLER 2085 * 2. NeuronExecution_create. 2086 * 2087 * Available since 7.0.1 2088 * 2089 * @param execution The NeuronExecution to be utilized. 2090 * @param idx The index of runner to set the previous inputs and outputs. 2091 * 2092 * @return NEURON_NO_ERROR if successful 2093 * @return NEURON_BAD_STATE if the compilation is not created via 2094 * COMPILATION_TYPE_EXECUTION_CONTROLLER. 2095 */ 2096 int NeuronExecution_setIODone(NeuronExecution* execution, int idx); 2097 2098 /** 2099 * Create a NeuronCompilation which can create executions with shared static 2100 * memory. 2101 * 2102 * This function only creates the object. Compilation is only performed once 2103 * NeuronCompilation_finish is invoked. NeuronCompilation_finish should be 2104 * called once all desired properties have been set on the compilation. 2105 * NeuronModel_free should be called once the compilation is no longer needed. 2106 * The provided model must outlive the compilation. The model must already have 2107 * been finished by a call to NeuronModel_finish. 2108 * 2109 * The executions created from this compilation can be executed at the same 2110 * time. 2111 * 2112 * Available since 7.0.0 2113 * 2114 * @param model The NeuronModel to be compiled. 2115 * @param compilation The newly created object or NULL if unsuccessful. 2116 * 2117 * @return NEURON_NO_ERROR if successful 2118 */ 2119 int NeuronCompilation_createForMultiExecutions( 2120 NeuronModel* model, 2121 NeuronCompilation** compilation); 2122 2123 /** 2124 * Set report path for debug plus. 2125 * 2126 * Only be used in debug purpose, the execution should be created by 2127 * NeuronCompilation_createForDebug compilation. 2128 * 2129 * Available since 5.0.0 2130 * 2131 * @param model The model need to be debug. 2132 * @param path The path of execution report. 2133 * 2134 * @return NEURON_NO_ERROR if successful, NEURON_BAD_DATA if the path is empty. 2135 */ 2136 int NeuronDebug_setReportPath(NeuronModel* model, const char* path); 2137 2138 /** 2139 * Get the number of available devices. 2140 * 2141 * Available since 4.1.0 2142 * @param numDevices The number of devices returned. 2143 * 2144 * @return NEURON_NO_ERROR if successful. 2145 */ 2146 int Neuron_getDeviceCount(uint32_t* numDevices); 2147 2148 /** 2149 * Get the representation of the specified device. 2150 * 2151 * Available since 4.1.0 2152 * 2153 * @param devIndex The index of the specified device. Must be less than the 2154 * number of available devices. 2155 * @param device The representation of the specified device. The same 2156 * representation will always be returned for the specified device. 2157 * 2158 * @return NEURONNO_ERROR if successful. 2159 */ 2160 int Neuron_getDevice(uint32_t devIndex, NeuronDevice** device); 2161 2162 /** 2163 * Get the name of the specified device. 2164 * 2165 * Available since 4.1.0 2166 * 2167 * @param device The representation of the specified device. 2168 * @param name The returned name of the specified device. The name will remain 2169 * valid for the duration of the application. 2170 * 2171 * @return NEURON_NO_ERROR if successful. 2172 */ 2173 int NeuronDevice_getName(const NeuronDevice* device, const char** name); 2174 2175 /** 2176 * Get the description of the specified device. 2177 * 2178 * Available since 5.0.0 2179 * 2180 * @param device The representation of the specified device. 2181 * @param description The returned description of the specified device. The 2182 * description will remain valid for the duration of the application. 2183 * 2184 * @return NEURON_NO_ERROR if successful. 2185 */ 2186 int NeuronDevice_getDescription( 2187 const NeuronDevice* device, 2188 const char** description); 2189 2190 /* 2191 * Destroys the event. 2192 * 2193 * See NeuronExecution for information on multithreaded usage. 2194 * 2195 * Available since 5.0.0 2196 * 2197 * @param event The event object to be destroyed. Passing NULL is acceptable and 2198 * results in no operation. 2199 */ 2200 void NeuronEvent_free(NeuronEvent* event); 2201 2202 /* 2203 * Force destroys the event without calling NeuronEvent_wait(). 2204 * If user wants do wait before destroying the event, they should use 2205 * NeuronEvent_free. 2206 * 2207 * See NeuronExecution for information on multithreaded usage. 2208 * 2209 * Available since 6.0.0 2210 * 2211 * @param event The event object to be destroyed. Passing NULL is acceptable and 2212 * results in no operation. 2213 */ 2214 void NeuronEvent_freeForce(NeuronEvent* event); 2215 2216 /** 2217 * Waits until the execution completes. 2218 * 2219 * More than one thread can wait on an event. When the execution completes, 2220 * all threads will be released. 2221 * 2222 * SeeNeuronExecution for information on multithreaded usage. 2223 * 2224 * Available since 5.0.0 2225 * 2226 * @param event The event that will be signaled on completion. 2227 * @return NEURON_NO_ERROR if the execution completed normally. 2228 * NEURON_UNMAPPABLE if the execution input or output memory cannot 2229 * be properly mapped. 2230 */ 2231 int NeuronEvent_wait(NeuronEvent* event); 2232 2233 /** 2234 * Create a NeuronEventfrom a sync_fence file descriptor. 2235 * 2236 * The newly created NeuronEvent does not take ownership of the provided 2237 * sync_fence_fd, it will instead dup the provided sync_fence_fd and own the 2238 * duplicate. 2239 * 2240 * @param sync_fence_fd The sync_fence file descriptor. 2241 * @param event The newly created object or NULL if unsuccessful. 2242 * 2243 * @return NEURON_NO_ERROR if successful. 2244 * 2245 * Available since 5.0.0 2246 */ 2247 int NeuronEvent_createFromSyncFenceFd(int sync_fence_fd, NeuronEvent** event); 2248 2249 /** 2250 * Get sync_fence file descriptor from the event. 2251 * 2252 * If the NeuronEvent is not backed by a sync fence, the sync_fence_fd 2253 * will be set to -1, and NEURON_BAD_DATA will be returned. 2254 * 2255 * See NeuronEvent_createFromSyncFenceFd and 2256 * NeuronExecution_startComputeWithDependencies to see how to create an event 2257 * backed by a sync fence. 2258 * 2259 * The user takes ownership of the returned fd, and must close the returned file 2260 * descriptor when it is no longer needed. 2261 * 2262 * @param event An event that is backed by a sync fence. 2263 * @param sync_fence_fd The sync_fence file descriptor. The file descriptor will 2264 * be set to -1 if there is an error. 2265 * 2266 * @return NEURON_NO_ERROR if successful. 2267 * 2268 * Available since 5.0.0 2269 */ 2270 int NeuronEvent_getSyncFenceFd(const NeuronEvent* event, int* sync_fence_fd); 2271 2272 /** 2273 * Queries whether an extension is supported by the driver implementation of the 2274 * specified device. 2275 * 2276 * @param extension The extension name. 2277 * @param isExtensionSupported The boolean value indicating whether the 2278 * extension is supported. 2279 * 2280 * @return NEURON_NO_ERROR if successful. 2281 * 2282 * Available since 5.0.0 2283 */ 2284 // Note: Remove "device" 2285 int NeuronDevice_getExtensionSupport( 2286 const char* extensionName, 2287 bool* isExtensionSupported); 2288 2289 /** 2290 * Creates an operand type from an extension name and an extension operand code. 2291 * 2292 * See {@link NeuronModel} for information on multithreaded usage. 2293 * 2294 * Available since 5.0.0 2295 * 2296 * @param model The model to contain the operand. 2297 * @param extensionName The extension name. 2298 * @param operandCodeWithinExtension The extension operand code. 2299 * @param type The operand type. 2300 * 2301 * @return NEURON_NO_ERROR if successful. 2302 */ 2303 int NeuronModel_getExtensionOperandType( 2304 NeuronModel* model, 2305 const char* extensionName, 2306 uint16_t operandCodeWithinExtension, 2307 int32_t* type); 2308 2309 /** 2310 * Creates an operation type from an extension name and an extension operation 2311 * code. 2312 * 2313 * See {@link NeuronModel} for information on multithreaded usage. 2314 * 2315 * Available since 5.0.0 2316 * 2317 * @param model The model to contain the operation. 2318 * @param extensionName The extension name. 2319 * @param operationCodeWithinExtension The extension operation code. 2320 * @param type The operation type. 2321 * 2322 * @return NEURON_NO_ERROR if successful. 2323 */ 2324 int NeuronModel_getExtensionOperationType( 2325 NeuronModel* model, 2326 const char* extensionName, 2327 uint16_t operationCodeWithinExtension, 2328 int32_t* type); 2329 2330 /** 2331 * Sets extension operand parameters. 2332 * 2333 * Available since 5.0.0 2334 * 2335 * @param model The model to be modified. 2336 * @param index The index of the model operand we're setting. 2337 * @param data A pointer to the extension operand data. 2338 * The data does not have to outlive the call to this function. 2339 * @param length The size in bytes of the data value. 2340 * 2341 * @return NEURON_NO_ERROR if successful. 2342 */ 2343 int NeuronModel_setOperandExtensionData( 2344 NeuronModel* model, 2345 int32_t index, 2346 const void* data, 2347 size_t length); 2348 2349 /** 2350 * Gets the execution preference associated with this compilation. 2351 * This function must be called after calling NeuronCompilation_finish. 2352 * 2353 * Available since 6.0.0 2354 * 2355 * @param compilation The compilation to be queried. 2356 * @param preference The execution preference will be one of NEURON_PREFER_*. 2357 * Ignore preference value if this function doesn't return NEURON_NO_ERROR. 2358 * 2359 * @return NEURON_NO_ERROR if successful. 2360 */ 2361 int NeuronCompilation_getPreference( 2362 NeuronCompilation* compilation, 2363 int* preference); 2364 2365 /** 2366 * Gets the execution priority associated with this compilation. 2367 * This function must be called after calling NeuronCompilation_finish. 2368 * 2369 * Available since 6.0.0 2370 * 2371 * @param compilation The compilation to be queried. 2372 * @param priority The priority will be one of NEURON_PRIORITY_*. Ignore 2373 * priority value if this function doesn't return NEURON_NO_ERROR. 2374 * 2375 * @return NEURON_NO_ERROR if successful. 2376 */ 2377 int NeuronCompilation_getPriority( 2378 NeuronCompilation* compilation, 2379 int* priority); 2380 2381 int NeuronCompilation_createWithOptions( 2382 NeuronModel* model, 2383 NeuronCompilation** compilation, 2384 const char* options); 2385 __END_DECLS 2386