ailia_tflite  1.2.2.0
ailia_tflite.h
Go to the documentation of this file.
1 
14 #if !defined(INCLUDED_AILIA_TFLITE)
15 #define INCLUDED_AILIA_TFLITE
16 
17 #include <stdint.h>
18 #include <stddef.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23  /****************************************************************
24  * ailia TFLite runtime のインスタンス
25  **/
26 
27  struct AILIATFLiteInstance;
28 
29  /****************************************************************
30  * サブコア制御用の変数を指定する構造体
31  **/
32 
33  struct AILIATFLiteSubCoreControlVariables;
34 
35  /****************************************************************
36  * Tensorのデータ タイプ
37  **/
38 
48  #define AILIA_TFLITE_TENSOR_TYPE_FLOAT32 (0)
58  #define AILIA_TFLITE_TENSOR_TYPE_FLOAT16 (1)
68  #define AILIA_TFLITE_TENSOR_TYPE_INT32 (2)
78  #define AILIA_TFLITE_TENSOR_TYPE_UINT8 (3)
88  #define AILIA_TFLITE_TENSOR_TYPE_INT64 (4)
98  #define AILIA_TFLITE_TENSOR_TYPE_STRING (5)
108  #define AILIA_TFLITE_TENSOR_TYPE_BOOL (6)
118  #define AILIA_TFLITE_TENSOR_TYPE_INT16 (7)
128  #define AILIA_TFLITE_TENSOR_TYPE_COMPLEX64 (8)
138  #define AILIA_TFLITE_TENSOR_TYPE_INT8 (9)
139  typedef int8_t AILIATFLiteTensorType;
140 
141  /****************************************************************
142  * ステータスコード
143  **/
144 
154  #define AILIA_TFLITE_STATUS_SUCCESS ( 0)
164  #define AILIA_TFLITE_STATUS_INVALID_ARGUMENT ( -1)
174  #define AILIA_TFLITE_STATUS_OUT_OF_RANGE ( -2)
184  #define AILIA_TFLITE_STATUS_MEMORY_INSUFFICIENT ( -3)
194  #define AILIA_TFLITE_STATUS_BROKEN_MODEL ( -4)
204  #define AILIA_TFLITE_STATUS_INVALID_PARAMETER ( -5)
214  #define AILIA_TFLITE_STATUS_PARAMETER_NOT_FOUND ( -6)
224  #define AILIA_TFLITE_STATUS_UNSUPPORTED_OPCODE ( -7)
234  #define AILIA_TFLITE_STATUS_LICENSE_NOT_FOUND ( -8)
244  #define AILIA_TFLITE_STATUS_LICENSE_BROKEN ( -9)
254  #define AILIA_TFLITE_STATUS_LICENSE_EXPIRED ( -10)
264  #define AILIA_TFLITE_STATUS_INVALID_STATE ( -11)
274  #define AILIA_TFLITE_STATUS_OTHER_ERROR (-128)
275  typedef int32_t AILIATFLiteStatus;
276 
277  /****************************************************************
278  * バックエンドAPI
279  **/
280 
290  #define AILIA_TFLITE_ENV_REFERENCE (0)
300  #define AILIA_TFLITE_ENV_NNAPI (1)
310  #define AILIA_TFLITE_ENV_MMALIB (2)
320  #define AILIA_TFLITE_ENV_MMALIB_COMPATIBLE (3)
321  typedef int32_t AILIATFLiteEnvironment;
331  #define AILIA_TFLITE_ENV_QNN (4)
332 
333  /****************************************************************
334  * メモリモード
335  **/
336 
346  #define AILIA_TFLITE_MEMORY_MODE_DEFAULT (0)
356  #define AILIA_TFLITE_MEMORY_MODE_REDUCE_INTERSTAGE (1)
357  typedef int32_t AILIATFLiteMemoryMode;
358 
359  /****************************************************************
360  * プロファイルモード
361  **/
362 
372  #define AILIA_TFLITE_PROFILE_MODE_DISABLE (0)
373 
383  #define AILIA_TFLITE_PROFILE_MODE_ENABLE (1)
384 
394  #define AILIA_TFLITE_PROFILE_MODE_TRACE (2)
395 
405  #define AILIA_TFLITE_PROFILE_MODE_MEMORY (4)
406 
407  /****************************************************************
408  * フラグ
409  **/
410 
420  #define AILIA_TFLITE_FLAG_NONE (0)
421 
431  #define AILIA_TFLITE_FLAG_INPUT_AND_OUTPUT_TENSORS_USE_SCRATCH (1)
432 
433  typedef int32_t AILIATFLiteFlags;
434 
435  /****************************************************************
436  * CPU拡張命令情報
437  **/
438 
448  #define AILIA_TFLITE_CPU_FEATURES_NONE (0x00000000)
458  #define AILIA_TFLITE_CPU_FEATURES_NEON (0x00000001)
468  #define AILIA_TFLITE_CPU_FEATURES_SSE2 (0x00000002)
478  #define AILIA_TFLITE_CPU_FEATURES_SSE4_2 (0x00000004)
488  #define AILIA_TFLITE_CPU_FEATURES_AVX (0x00000008)
498  #define AILIA_TFLITE_CPU_FEATURES_AVX2 (0x00000010)
508  #define AILIA_TFLITE_CPU_FEATURES_VNNI (0x00000020)
518  #define AILIA_TFLITE_CPU_FEATURES_AVX512 (0x00000040)
528  #define AILIA_TFLITE_CPU_FEATURES_I8MM (0x00000080)
529 
539  #define AILIA_TFLITE_SUB_CORE_COUNT_MAX (8)
540 
541  typedef int32_t AILIATFLiteCpuFeatures;
542 
543  /****************************************************************
544  * 推論環境列挙API
545  **/
546 
563  ailiaTFLiteGetEnvironmentCount(size_t *env_count);
564 
586 
587  /****************************************************************
588  * インスタンス生成・破棄API
589  **/
590 
633  ailiaTFLiteCreate(struct AILIATFLiteInstance **instance, const void * tflite, const size_t tflite_length, void *(*pmalloc)(size_t, const void *, void *), void *(*pmemcpy)(void *, const void *, size_t, void *), void (*pfree)(void *, void *), void *phandle, AILIATFLiteEnvironment env_id, AILIATFLiteMemoryMode memory_mode, AILIATFLiteFlags flags);
634 
644  void
645  ailiaTFLiteDestroy(struct AILIATFLiteInstance *instance);
646 
647  /****************************************************************
648  * CPU命令設定系API
649  **/
650 
677  ailiaTFLiteGetCpuFeatures(struct AILIATFLiteInstance * instance, int32_t *cpu_features);
678 
703  ailiaTFLiteSetCpuFeatures(struct AILIATFLiteInstance * instance, int32_t cpu_features);
704 
705  /****************************************************************
706  * 確保系API
707  **/
708 
729  ailiaTFLiteAllocateTensors(struct AILIATFLiteInstance * instance);
730 
731  /****************************************************************
732  * Tensor設定系API
733  **/
734 
775  ailiaTFLiteResizeInputTensor(struct AILIATFLiteInstance * instance, const int32_t input_index, const int32_t* shape, const int32_t dim);
776 
777  /****************************************************************
778  * Tensor取得系API
779  **/
780 
799  ailiaTFLiteGetNumberOfInputs(const struct AILIATFLiteInstance *instance, int32_t* num_of_input_tensor);
800 
829  ailiaTFLiteGetInputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t* tensor_index, const int32_t input_index);
830 
849  ailiaTFLiteGetNumberOfOutputs(const struct AILIATFLiteInstance *instance, int32_t* num_of_output_tensor);
850 
879  ailiaTFLiteGetOutputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t* tensor_index, const int32_t output_index);
880 
903  ailiaTFLiteGetTensorDimension(const struct AILIATFLiteInstance *instance, int32_t* tensor_dim, const int32_t tensor_index);
904 
933  ailiaTFLiteGetTensorShape(const struct AILIATFLiteInstance *instance, int32_t *shape, const int32_t tensor_index);
934 
967  ailiaTFLiteGetTensorShapeSignature(const struct AILIATFLiteInstance *instance, int32_t *shape, const int32_t tensor_index);
968 
991  ailiaTFLiteGetTensorType(const struct AILIATFLiteInstance *instance, AILIATFLiteTensorType* tensor_type, const int32_t tensor_index);
992 
1023  ailiaTFLiteGetTensorBuffer(struct AILIATFLiteInstance *instance, void** buffer, const int32_t tensor_index);
1024 
1053  ailiaTFLiteGetTensorName(const struct AILIATFLiteInstance *instance, const char** name, const int32_t tensor_index);
1054 
1083  ailiaTFLiteGetTensorQuantizationCount(const struct AILIATFLiteInstance *instance, int32_t* count, const int32_t tensor_index);
1084 
1121  ailiaTFLiteGetTensorQuantizationScale(const struct AILIATFLiteInstance *instance, float *scale, const int32_t tensor_index);
1122 
1153  ailiaTFLiteGetTensorQuantizationZeroPoint(const struct AILIATFLiteInstance *instance, int64_t *zero_point, const int32_t tensor_index);
1154 
1179  ailiaTFLiteGetTensorQuantizationQuantizedDimension(const struct AILIATFLiteInstance *instance, int32_t* axis, const int32_t tensor_index);
1180 
1181  /****************************************************************
1182  * Tensor推論系API
1183  **/
1184 
1201  ailiaTFLitePredict(struct AILIATFLiteInstance *instance);
1202 
1203  /****************************************************************
1204  * ノード情報取得API
1205  **/
1206 
1225  ailiaTFLiteGetNodeCount(const struct AILIATFLiteInstance *instance, int32_t *count);
1226 
1255  ailiaTFLiteGetNodeOperator(const struct AILIATFLiteInstance *instance, int32_t *op, const int32_t node_index);
1256 
1279  ailiaTFLiteGetNodeInputCount(const struct AILIATFLiteInstance *instance, int32_t *count, const int32_t node_index);
1280 
1305  ailiaTFLiteGetNodeInputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t node_index, const int32_t input_index);
1306 
1329  ailiaTFLiteGetNodeOutputCount(const struct AILIATFLiteInstance *instance, int32_t *count, const int32_t node_index);
1330 
1355  ailiaTFLiteGetNodeOutputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t node_index, const int32_t output_index);
1356 
1381  ailiaTFLiteGetNodeOption(const struct AILIATFLiteInstance *instance, void *value, const int32_t node_index, const char *key);
1382 
1407  ailiaTFLiteGetOperatorName(const char **name, const int32_t op);
1408 
1409  /****************************************************************
1410  * プロファイルAPI
1411  **/
1412 
1441  ailiaTFLiteSetProfileMode(struct AILIATFLiteInstance *instance, int mode);
1442 
1461  ailiaTFLiteGetSummaryLength(struct AILIATFLiteInstance *instance, size_t *buffer_size);
1462 
1483  ailiaTFLiteGetSummary(struct AILIATFLiteInstance *instance, char *buffer, size_t buffer_size);
1484 
1485  /****************************************************************
1486  * エラー詳細取得API
1487  **/
1488 
1507  ailiaTFLiteGetErrorDetail(struct AILIATFLiteInstance *instance, char **buffer);
1508 
1509  /****************************************************************
1510  * バージョン情報取得API
1511  **/
1512 
1528  const char* ailiaTFLiteGetVersion(void);
1529 
1530  /****************************************************************
1531  * スクラッチバッファ設定API
1532  **/
1533 
1572  ailiaTFLiteSetScratchBuffer(struct AILIATFLiteInstance *instance, void *int_buffer, size_t int_buffer_size, void *mid_buffer, size_t mid_buffer_size, void *ext_buffer, size_t ext_buffer_size);
1573 
1596  ailiaTFLiteGetScratchBufferUsage(struct AILIATFLiteInstance *instance, size_t *int_buffer_size, size_t *mid_buffer_size, size_t *ext_buffer_size);
1597 
1598  /****************************************************************
1599  * MKL設定API
1600  **/
1601 
1626  ailiaTFLiteMklSetNumThreads(const int32_t num_threads);
1627 
1655 
1669  ailiaTFLiteSetSynchronizeFunctions(struct AILIATFLiteInstance* instance,
1670  int (*pmain_after_command_store)(void*), int (*pmain_before_state_load)(void*));
1671 
1696  alilaTFLiteSetSubCoreControlVariables(struct AILIATFLiteInstance* instance, const struct AILIATFLiteSubCoreControlVariables* control_variables, int32_t sub_core_count);
1697 
1698 #ifdef __cplusplus
1699 }
1700 #endif
1701 #endif /* !defined(INCLUDED_AILIA_TFLITE) */
AILIATFLiteStatus ailiaTFLiteCreate(struct AILIATFLiteInstance **instance, const void *tflite, const size_t tflite_length, void *(*pmalloc)(size_t, const void *, void *), void *(*pmemcpy)(void *, const void *, size_t, void *), void(*pfree)(void *, void *), void *phandle, AILIATFLiteEnvironment env_id, AILIATFLiteMemoryMode memory_mode, AILIATFLiteFlags flags)
Create ailia TFLite runtime instances.
AILIATFLiteStatus ailiaTFLiteGetNodeOperator(const struct AILIATFLiteInstance *instance, int32_t *op, const int32_t node_index)
Get node_index number Operator.
int32_t AILIATFLiteFlags
Definition: ailia_tflite.h:433
AILIATFLiteStatus ailiaTFLiteGetEnvironmentCount(size_t *env_count)
Get the number of available calculation environments.
void ailiaTFLiteDestroy(struct AILIATFLiteInstance *instance)
Discard the instance of ailia TFLite runtime.
AILIATFLiteStatus ailiaTFLiteResizeInputTensor(struct AILIATFLiteInstance *instance, const int32_t input_index, const int32_t *shape, const int32_t dim)
Change the shape of Tensor of the specified input index.
AILIATFLiteStatus ailiaTFLiteGetSummaryLength(struct AILIATFLiteInstance *instance, size_t *buffer_size)
Get the size of the buffer required for network Summary.
AILIATFLiteStatus ailiaTFLiteGetNodeInputCount(const struct AILIATFLiteInstance *instance, int32_t *count, const int32_t node_index)
Node_index gets the number of node input.
AILIATFLiteStatus ailiaTFLiteGetNodeCount(const struct AILIATFLiteInstance *instance, int32_t *count)
Get the number of node.
AILIATFLiteStatus ailiaTFLiteGetNodeOutputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t node_index, const int32_t output_index)
Node_index Acquire the index of Tensor in the Output_index number of node.
AILIATFLiteStatus ailiaTFLiteGetInputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t input_index)
Get Tensor's index from index in Tensor.
AILIATFLiteStatus ailiaTFLiteGetErrorDetail(struct AILIATFLiteInstance *instance, char **buffer)
Returns the error details.
AILIATFLiteStatus ailiaTFLiteGetTensorQuantizationZeroPoint(const struct AILIATFLiteInstance *instance, int64_t *zero_point, const int32_t tensor_index)
Get the zero point of the quantified parameter of the index number TENSOR.
AILIATFLiteStatus ailiaTFLiteSetSynchronizeFunctions(struct AILIATFLiteInstance *instance, int(*pmain_after_command_store)(void *), int(*pmain_before_state_load)(void *))
const char * ailiaTFLiteGetVersion(void)
Get the version of the library.
AILIATFLiteStatus alilaTFLiteSetSubCoreControlVariables(struct AILIATFLiteInstance *instance, const struct AILIATFLiteSubCoreControlVariables *control_variables, int32_t sub_core_count)
When using multi-core systems, set the variables used to communicate with each subcore.
AILIATFLiteStatus ailiaTFLiteGetTensorName(const struct AILIATFLiteInstance *instance, const char **name, const int32_t tensor_index)
Get the name of the index number Tensor.
AILIATFLiteStatus ailiaTFLiteGetTensorQuantizationQuantizedDimension(const struct AILIATFLiteInstance *instance, int32_t *axis, const int32_t tensor_index)
Get the axis of the integrated TENSOR quantization parameter.
AILIATFLiteStatus ailiaTFLiteGetOutputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t output_index)
Obtain Tensor's index from index of output Tensor.
AILIATFLiteStatus ailiaTFLiteGetTensorDimension(const struct AILIATFLiteInstance *instance, int32_t *tensor_dim, const int32_t tensor_index)
Get the dimension of index number Tensor.
AILIATFLiteStatus ailiaTFLiteGetTensorShapeSignature(const struct AILIATFLiteInstance *instance, int32_t *shape, const int32_t tensor_index)
Get the undecided dimensional form of Tensor of index number.
AILIATFLiteStatus ailiaTFLiteGetNodeOption(const struct AILIATFLiteInstance *instance, void *value, const int32_t node_index, const char *key)
Node_index gets the Node option.
AILIATFLiteStatus ailiaTFLiteGetTensorQuantizationScale(const struct AILIATFLiteInstance *instance, float *scale, const int32_t tensor_index)
Get the scale of the quantified parameter of the index number TENSOR.
AILIATFLiteStatus ailiaTFLiteGetNumberOfInputs(const struct AILIATFLiteInstance *instance, int32_t *num_of_input_tensor)
Get the number of TENSOR in the TFLITE model.
int32_t AILIATFLiteMemoryMode
Definition: ailia_tflite.h:357
AILIATFLiteStatus ailiaTFLiteGetSummary(struct AILIATFLiteInstance *instance, char *buffer, size_t buffer_size)
Displays the name and shape of each node.
AILIATFLiteStatus ailiaTFLiteMklDisableFastMM(void)
Disable the mkl fastmm.
AILIATFLiteStatus ailiaTFLiteGetNodeOutputCount(const struct AILIATFLiteInstance *instance, int32_t *count, const int32_t node_index)
Node_index gets the number of node output.
AILIATFLiteStatus ailiaTFLiteGetCpuFeatures(struct AILIATFLiteInstance *instance, int32_t *cpu_features)
Get the CPU instruction to use.
AILIATFLiteStatus ailiaTFLiteGetTensorType(const struct AILIATFLiteInstance *instance, AILIATFLiteTensorType *tensor_type, const int32_t tensor_index)
Get the Data type of TENSOR in Index.
AILIATFLiteStatus ailiaTFLitePredict(struct AILIATFLiteInstance *instance)
Do inference.
AILIATFLiteStatus ailiaTFLiteGetEnvironment(AILIATFLiteEnvironment *env)
Get a list of calculation environments.
AILIATFLiteStatus ailiaTFLiteGetTensorQuantizationCount(const struct AILIATFLiteInstance *instance, int32_t *count, const int32_t tensor_index)
Get the number of quantified parameters of index number Tensor.
AILIATFLiteStatus ailiaTFLiteGetNumberOfOutputs(const struct AILIATFLiteInstance *instance, int32_t *num_of_output_tensor)
Get the number of TENSOR of the TFLITE model.
AILIATFLiteStatus ailiaTFLiteGetScratchBufferUsage(struct AILIATFLiteInstance *instance, size_t *int_buffer_size, size_t *mid_buffer_size, size_t *ext_buffer_size)
Get the maximum usage of the scratch buffer.
AILIATFLiteStatus ailiaTFLiteGetOperatorName(const char **name, const int32_t op)
Get the Operator name.
AILIATFLiteStatus ailiaTFLiteSetCpuFeatures(struct AILIATFLiteInstance *instance, int32_t cpu_features)
Set the CPU instruction to use.
AILIATFLiteStatus ailiaTFLiteAllocateTensors(struct AILIATFLiteInstance *instance)
Ensure the internal buffer of ailia TFLite runtime.
AILIATFLiteStatus ailiaTFLiteMklSetNumThreads(const int32_t num_threads)
Set the number of threads used by MKL.
int32_t AILIATFLiteEnvironment
Definition: ailia_tflite.h:321
int8_t AILIATFLiteTensorType
Definition: ailia_tflite.h:139
AILIATFLiteStatus ailiaTFLiteGetNodeInputTensorIndex(const struct AILIATFLiteInstance *instance, int32_t *tensor_index, const int32_t node_index, const int32_t input_index)
Node_index Acquires the index of Tensor in the input input of node.
AILIATFLiteStatus ailiaTFLiteGetTensorBuffer(struct AILIATFLiteInstance *instance, void **buffer, const int32_t tensor_index)
Obtain a storage buffer in Tensor's data.
AILIATFLiteStatus ailiaTFLiteSetProfileMode(struct AILIATFLiteInstance *instance, int mode)
Set the profile mode.
AILIATFLiteStatus ailiaTFLiteSetScratchBuffer(struct AILIATFLiteInstance *instance, void *int_buffer, size_t int_buffer_size, void *mid_buffer, size_t mid_buffer_size, void *ext_buffer, size_t ext_buffer_size)
Set a scratch buffer.
int32_t AILIATFLiteCpuFeatures
Definition: ailia_tflite.h:541
AILIATFLiteStatus ailiaTFLiteGetTensorShape(const struct AILIATFLiteInstance *instance, int32_t *shape, const int32_t tensor_index)
Get the shape of the index number Tensor.
int32_t AILIATFLiteStatus
Definition: ailia_tflite.h:275