ailia  1.5.0.0
ailia.h
Go to the documentation of this file.
1 
15 #ifndef INCLUDED_AILIA
16 #define INCLUDED_AILIA
17 #include <wchar.h>
18 
19 /* 呼び出し規約 */
20 
21 #if defined(_M_JS)
22 #include <emscripten.h>
23 #define AILIA_API EMSCRIPTEN_KEEPALIVE
24 #elif defined(_WIN64) || defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) || defined(__APPLE__) || \
25  defined(__ANDROID__) || defined(ANDROID) || defined(__linux__) || defined(NN_NINTENDO_SDK)
26 #define AILIA_API
27 #else
28 #define AILIA_API __stdcall
29 #endif
30 
31 #include "ailia_call.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 /****************************************************************
37  * ライブラリ状態定義
38  **/
39 
49 #define AILIA_STATUS_SUCCESS (0)
61 #define AILIA_STATUS_INVALID_ARGUMENT (-1)
73 #define AILIA_STATUS_ERROR_FILE_API (-2)
85 #define AILIA_STATUS_INVALID_VERSION (-3)
97 #define AILIA_STATUS_BROKEN (-4)
109 #define AILIA_STATUS_MEMORY_INSUFFICIENT (-5)
121 #define AILIA_STATUS_THREAD_ERROR (-6)
133 #define AILIA_STATUS_INVALID_STATE (-7)
147 #define AILIA_STATUS_UNSUPPORTED_NET (-9)
151 #define AILIA_STATUS_UNSUPPORT_NET (-9)
165 #define AILIA_STATUS_INVALID_LAYER (-10)
177 #define AILIA_STATUS_INVALID_PARAMINFO (-11)
190 #define AILIA_STATUS_NOT_FOUND (-12)
204 #define AILIA_STATUS_GPU_UNSUPPORTED_LAYER (-13)
208 #define AILIA_STATUS_GPU_UNSUPPORT_LAYER (-13)
220 #define AILIA_STATUS_GPU_ERROR (-14)
234 #define AILIA_STATUS_UNIMPLEMENTED (-15)
248 #define AILIA_STATUS_PERMISSION_DENIED (-16)
260 #define AILIA_STATUS_EXPIRED (-17)
274 #define AILIA_STATUS_UNSETTLED_SHAPE (-18)
287 #define AILIA_STATUS_DATA_HIDDEN (-19)
288 #define AILIA_STATUS_DATA_REMOVED AILIA_STATUS_DATA_HIDDEN
301 #define AILIA_STATUS_LICENSE_NOT_FOUND (-20)
315 #define AILIA_STATUS_LICENSE_BROKEN (-21)
330 #define AILIA_STATUS_LICENSE_EXPIRED (-22)
343 #define AILIA_STATUS_NDIMENSION_SHAPE (-23)
357 #define AILIA_STATUS_OTHER_ERROR (-128)
358 
359 /****************************************************************
360  * ネットワークオブジェクトのインスタンス
361  **/
362 
363 struct AILIANetwork;
364 
365 /****************************************************************
366  * 形状情報
367  **/
368 
369 #define AILIA_SHAPE_VERSION (1)
370 
371 typedef struct _AILIAShape {
379  unsigned int x;
387  unsigned int y;
395  unsigned int z;
403  unsigned int w;
411  unsigned int dim;
413 
414 /****************************************************************
415  * スレッド数
416  **/
417 
418 #define AILIA_MULTITHREAD_AUTO (0)
419 
420 /****************************************************************
421  * 推論実行環境自動設定
422  **/
423 
424 #define AILIA_ENVIRONMENT_ID_AUTO (-1)
425 
426 /****************************************************************
427  * 推論時の内部データ(Blob)の型
428  * ailiaGetBlobDataType で取得可能
429  **/
430 
431 #define AILIA_DATATYPE_UNDEFINED 0
432 #define AILIA_DATATYPE_FLOAT 1
433 #define AILIA_DATATYPE_UINT8 2
434 #define AILIA_DATATYPE_INT8 3
435 #define AILIA_DATATYPE_UINT16 4
436 #define AILIA_DATATYPE_INT16 5
437 #define AILIA_DATATYPE_INT32 6
438 #define AILIA_DATATYPE_INT64 7
439 #define AILIA_DATATYPE_BOOL 9
440 #define AILIA_DATATYPE_FLOAT16 10
441 #define AILIA_DATATYPE_DOUBLE 11
442 #define AILIA_DATATYPE_UINT32 12
443 #define AILIA_DATATYPE_UINT64 13
444 #define AILIA_DATATYPE_BFLOAT16 16
445 
446 /****************************************************************
447  * 推論API
448  **/
449 
478 int AILIA_API ailiaCreate(struct AILIANetwork** net, int env_id, int num_thread);
479 
499 int AILIA_API ailiaOpenStreamFileA(struct AILIANetwork* net, const char* path);
500 int AILIA_API ailiaOpenStreamFileW(struct AILIANetwork* net, const wchar_t* path);
501 
525 int AILIA_API ailiaOpenStreamEx(struct AILIANetwork* net, const void* fopen_args, ailiaFileCallback callback, int version);
526 
548 int AILIA_API ailiaOpenStreamMem(struct AILIANetwork* net, const void* buf, unsigned int buf_size);
549 
569 int AILIA_API ailiaOpenWeightFileA(struct AILIANetwork* net, const char* path);
570 int AILIA_API ailiaOpenWeightFileW(struct AILIANetwork* net, const wchar_t* path);
571 
595 int AILIA_API ailiaOpenWeightEx(struct AILIANetwork* net, const void* fopen_args, ailiaFileCallback callback, int version);
596 
618 int AILIA_API ailiaOpenWeightMem(struct AILIANetwork* net, const void* buf, unsigned int buf_size);
619 
629 void AILIA_API ailiaDestroy(struct AILIANetwork* net);
630 
662 int AILIA_API ailiaSetInputShape(struct AILIANetwork* net, const AILIAShape* shape, unsigned int version);
663 
691 int AILIA_API ailiaSetInputShapeND(struct AILIANetwork* net, const unsigned int* shape, unsigned int dim);
692 
721 int AILIA_API ailiaGetInputShape(struct AILIANetwork* net, AILIAShape* shape, unsigned int version);
722 
742 int AILIA_API ailiaGetInputDim(struct AILIANetwork* net, unsigned int* dim);
743 
769 int AILIA_API ailiaGetInputShapeND(struct AILIANetwork* net, unsigned int* shape, unsigned int dim);
770 
795 int AILIA_API ailiaGetOutputShape(struct AILIANetwork* net, AILIAShape* shape, unsigned int version);
796 
816 int AILIA_API ailiaGetOutputDim(struct AILIANetwork* net, unsigned int* dim);
817 
839 int AILIA_API ailiaGetOutputShapeND(struct AILIANetwork* net, unsigned int* shape, unsigned int dim);
840 
868 int AILIA_API
869 ailiaPredict(struct AILIANetwork* net, void* dest, unsigned int dest_size, const void* src, unsigned int src_size);
870 
871 /****************************************************************
872  * 状態取得API
873  **/
874 
899 int AILIA_API ailiaGetBlobCount(struct AILIANetwork* net, unsigned int* blob_count);
900 
928 int AILIA_API ailiaGetBlobShape(struct AILIANetwork* net, AILIAShape* shape, unsigned int blob_idx, unsigned int version);
929 
951 int AILIA_API ailiaGetBlobDim(struct AILIANetwork* net, unsigned int* dim, unsigned int blob_idx);
952 
976 int AILIA_API ailiaGetBlobShapeND(struct AILIANetwork* net, unsigned int* shape, unsigned int dim, unsigned int blob_idx);
977 
1002 int AILIA_API ailiaGetBlobData(struct AILIANetwork* net, void* dest, unsigned int dest_size, unsigned int blob_idx);
1003 
1025 int AILIA_API ailiaGetBlobDataType(struct AILIANetwork* net, int* type, unsigned int blob_idx);
1026 
1051 int AILIA_API ailiaFindBlobIndexByName(struct AILIANetwork* net, unsigned int* blob_idx, const char* name);
1052 
1077 int AILIA_API ailiaGetBlobNameLengthByIndex(struct AILIANetwork* net, const unsigned int blob_idx, unsigned int* buffer_size);
1078 
1105 int AILIA_API ailiaFindBlobNameByIndex(struct AILIANetwork* net, char* buffer, const unsigned int buffer_size, const unsigned int blob_idx);
1106 
1126 int AILIA_API ailiaGetSummaryLength(struct AILIANetwork* net, unsigned int* buffer_size);
1127 
1151 int AILIA_API ailiaSummary(struct AILIANetwork* net, char* const buffer, const unsigned int buffer_size);
1152 
1153 /****************************************************************
1154  * 複数入力指定・推論API
1155  **/
1156 
1181 int AILIA_API ailiaGetInputBlobCount(struct AILIANetwork* net, unsigned int* input_blob_count);
1182 
1206 int AILIA_API ailiaGetBlobIndexByInputIndex(struct AILIANetwork* net, unsigned int* blob_idx, unsigned int input_blob_idx);
1207 
1236 int AILIA_API ailiaSetInputBlobData(struct AILIANetwork* net, const void* src, unsigned int src_size, unsigned int blob_idx);
1237 
1269 int AILIA_API ailiaSetInputBlobShape(struct AILIANetwork* net, const AILIAShape* shape, unsigned int blob_idx, unsigned int version);
1270 
1300 int AILIA_API ailiaSetInputBlobShapeND(struct AILIANetwork* net, const unsigned* shape, const unsigned dim, unsigned int blob_idx);
1301 
1333 int AILIA_API ailiaCopyBlobData(struct AILIANetwork* dst_net, unsigned int dst_blob_idx, struct AILIANetwork* src_net, unsigned int src_blob_idx);
1334 
1356 int AILIA_API ailiaUpdate(struct AILIANetwork* net);
1357 
1377 int AILIA_API ailiaGetOutputBlobCount(struct AILIANetwork* net, unsigned int* output_blob_count);
1378 
1400 int AILIA_API ailiaGetBlobIndexByOutputIndex(struct AILIANetwork* net, unsigned int* blob_idx, unsigned int output_blob_idx);
1401 
1402 /****************************************************************
1403  * リソース解放 API
1404  **/
1405 
1426 
1427 /****************************************************************
1428  * 推論実行環境取得・指定API
1429  **/
1430 
1431 #define AILIA_ENVIRONMENT_VERSION (2)
1432 
1433 #define AILIA_ENVIRONMENT_TYPE_CPU (0)
1434 #define AILIA_ENVIRONMENT_TYPE_BLAS (1)
1435 #define AILIA_ENVIRONMENT_TYPE_GPU (2)
1436 #define AILIA_ENVIRONMENT_TYPE_REMOTE (3)
1437 
1438 #define AILIA_ENVIRONMENT_BACKEND_NONE (0)
1439 #define AILIA_ENVIRONMENT_BACKEND_CUDA (2)
1440 #define AILIA_ENVIRONMENT_BACKEND_MPS (3)
1441 #define AILIA_ENVIRONMENT_BACKEND_VULKAN (6)
1442 
1443 #define AILIA_ENVIRONMENT_PROPERTY_NORMAL (0)
1451 #define AILIA_ENVIRONMENT_PROPERTY_LOWPOWER (1)
1459 #define AILIA_ENVIRONMENT_PROPERTY_FP16 (2)
1460 
1461 typedef struct _AILIAEnvironment {
1469  int id;
1477  int type;
1485  const char* name;
1493  int backend;
1501  int props;
1503 
1529 int AILIA_API ailiaSetTemporaryCachePathA(const char* cache_dir);
1530 int AILIA_API ailiaSetTemporaryCachePathW(const wchar_t* cache_dir);
1531 
1545 int AILIA_API ailiaGetEnvironmentCount(unsigned int* env_count);
1546 
1564 int AILIA_API ailiaGetEnvironment(AILIAEnvironment** env, unsigned int env_idx, unsigned int version);
1565 
1583 int AILIA_API ailiaGetSelectedEnvironment(struct AILIANetwork* net, AILIAEnvironment** env, unsigned int version);
1584 
1585 /****************************************************************
1586  * メモリモードAPI
1587  **/
1588 
1596 #define AILIA_MEMORY_NO_OPTIMIZATION (0)
1604 #define AILIA_MEMORY_REDUCE_CONSTANT (1)
1612 #define AILIA_MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER (2)
1620 #define AILIA_MEMORY_REDUCE_INTERSTAGE (4)
1630 #define AILIA_MEMORY_REUSE_INTERSTAGE (8)
1652 #define AILIA_MEMORY_REDUCE_CONSTANT_WITH_FILE_MAPPED (16)
1653 
1654 #define AILIA_MEMORY_OPTIMAIZE_DEFAULT (AILIA_MEMORY_REDUCE_CONSTANT)
1655 
1685 int AILIA_API ailiaSetMemoryMode(struct AILIANetwork* net, unsigned int mode);
1686 
1687 /****************************************************************
1688  * 最適化制御API
1689  **/
1690 
1712 int AILIA_API ailiaDisableLayerFusion(struct AILIANetwork* net);
1713 
1714 /****************************************************************
1715  * プロファイルモードAPI
1716  **/
1717 
1725 #define AILIA_PROFILE_DISABLE (0x00)
1734 #define AILIA_PROFILE_AVERAGE (0x01)
1735 
1759 int AILIA_API ailiaSetProfileMode(struct AILIANetwork* net, unsigned int mode);
1760 
1761 /****************************************************************
1762  * 情報取得API
1763  **/
1764 
1786 const char* AILIA_API ailiaGetStatusString(int status_code);
1787 
1809 const char* AILIA_API ailiaGetErrorDetail(struct AILIANetwork* net);
1810 
1826 const char* AILIA_API ailiaGetVersion(void);
1827 
1828 #ifdef UNICODE
1829 #define ailiaOpenStreamFile ailiaOpenStreamFileW
1830 #define ailiaOpenWeightFile ailiaOpenWeightFileW
1831 #define ailiaSetTemporaryCachePath ailiaSetTemporaryCachePathW
1832 #else
1833 #define ailiaOpenStreamFile ailiaOpenStreamFileA
1834 #define ailiaOpenWeightFile ailiaOpenWeightFileA
1835 #define ailiaSetTemporaryCachePath ailiaSetTemporaryCachePathA
1836 #endif
1837 
1838 #ifdef __cplusplus
1839 }
1840 #endif
1841 #endif /* !defined(INCLUDED_AILIA) */
int AILIA_API ailiaOpenWeightMem(struct AILIANetwork *net, const void *buf, unsigned int buf_size)
Reads weights into a network instance. (Read from memory)
#define AILIA_API
Definition: ailia.h:28
int AILIA_API ailiaOpenWeightFileW(struct AILIANetwork *net, const wchar_t *path)
int AILIA_API ailiaOpenWeightFileA(struct AILIANetwork *net, const char *path)
Reads weights into a network instance. (Read from file)
int AILIA_API ailiaOpenWeightEx(struct AILIANetwork *net, const void *fopen_args, ailiaFileCallback callback, int version)
Reads weights into a network instance. (User-defined file access callback)
int AILIA_API ailiaGetSummaryLength(struct AILIANetwork *net, unsigned int *buffer_size)
Gets the size of the buffer needed for the network summary.
int AILIA_API ailiaDisableLayerFusion(struct AILIANetwork *net)
Disalbe layer fusion optimaization for inference.
int AILIA_API ailiaGetBlobNameLengthByIndex(struct AILIANetwork *net, const unsigned int blob_idx, unsigned int *buffer_size)
Gets the size of the buffer needed for output of the name of the internal data (blob).
const char *AILIA_API ailiaGetErrorDetail(struct AILIANetwork *net)
Returns the details of errors.
int AILIA_API ailiaGetBlobData(struct AILIANetwork *net, void *dest, unsigned int dest_size, unsigned int blob_idx)
Gets the internal data (blob) during inference.
int AILIA_API ailiaSetInputBlobShape(struct AILIANetwork *net, const AILIAShape *shape, unsigned int blob_idx, unsigned int version)
Change the shape of the blob given by its index.
int AILIA_API ailiaSetTemporaryCachePathA(const char *cache_dir)
Specifies a temporary cache directory.
int AILIA_API ailiaOpenStreamFileA(struct AILIANetwork *net, const char *path)
Initializes the network instance. (Read from file)
int AILIA_API ailiaGetBlobDim(struct AILIANetwork *net, unsigned int *dim, unsigned int blob_idx)
Gets the dimension of the internal data (blob) during inference.
int AILIA_API ailiaGetBlobShape(struct AILIANetwork *net, AILIAShape *shape, unsigned int blob_idx, unsigned int version)
Gets the shape of the internal data (blob) during inference.
int AILIA_API ailiaGetBlobDataType(struct AILIANetwork *net, int *type, unsigned int blob_idx)
Get the type of Blob.
struct _AILIAEnvironment AILIAEnvironment
const char *AILIA_API ailiaGetVersion(void)
Get the version of the library.
int AILIA_API ailiaGetEnvironmentCount(unsigned int *env_count)
Gets the number of available computational environments (CPU, GPU).
int AILIA_API ailiaGetOutputBlobCount(struct AILIANetwork *net, unsigned int *output_blob_count)
Get the number of output data blobs.
void AILIA_API ailiaDestroy(struct AILIANetwork *net)
It destroys the network instance.
int AILIA_API ailiaSetInputShape(struct AILIANetwork *net, const AILIAShape *shape, unsigned int version)
Changes the shape of the input data during inference.
int AILIA_API ailiaCopyBlobData(struct AILIANetwork *dst_net, unsigned int dst_blob_idx, struct AILIANetwork *src_net, unsigned int src_blob_idx)
Perform copies between blobs that specified.
int AILIA_API ailiaOpenStreamFileW(struct AILIANetwork *net, const wchar_t *path)
int AILIA_API ailiaSetInputBlobShapeND(struct AILIANetwork *net, const unsigned *shape, const unsigned dim, unsigned int blob_idx)
Change the shape of the blob given by its index.
int AILIA_API ailiaFinalize(void)
Release GPU and other resources that have been globally allocated with ailia.
int AILIA_API ailiaSetTemporaryCachePathW(const wchar_t *cache_dir)
const char *AILIA_API ailiaGetStatusString(int status_code)
Returns the string describing given status code.
int AILIA_API ailiaGetOutputShape(struct AILIANetwork *net, AILIAShape *shape, unsigned int version)
Gets the shape of the output data during inference.
int AILIA_API ailiaGetBlobShapeND(struct AILIANetwork *net, unsigned int *shape, unsigned int dim, unsigned int blob_idx)
Gets the amount of internal data (blob) during inference.
int AILIA_API ailiaSetMemoryMode(struct AILIANetwork *net, unsigned int mode)
Set the memory usage policy for inference.
int AILIA_API ailiaGetEnvironment(AILIAEnvironment **env, unsigned int env_idx, unsigned int version)
Gets the list of computational environments.
int AILIA_API ailiaGetInputBlobCount(struct AILIANetwork *net, unsigned int *input_blob_count)
Get the number of input data blobs.
int AILIA_API ailiaFindBlobIndexByName(struct AILIANetwork *net, unsigned int *blob_idx, const char *name)
Searches by name for the index of the internal data (blob) during inference and returns it.
int AILIA_API ailiaPredict(struct AILIANetwork *net, void *dest, unsigned int dest_size, const void *src, unsigned int src_size)
Performs the inferences and provides the inference result.
int AILIA_API ailiaGetOutputDim(struct AILIANetwork *net, unsigned int *dim)
Gets the dimension of the output data during inference.
struct _AILIAShape AILIAShape
int AILIA_API ailiaSetInputBlobData(struct AILIANetwork *net, const void *src, unsigned int src_size, unsigned int blob_idx)
Provides the specified blob with the input data.
int AILIA_API ailiaGetInputShape(struct AILIANetwork *net, AILIAShape *shape, unsigned int version)
Gets the shape of the input data during inference.
int AILIA_API ailiaOpenStreamEx(struct AILIANetwork *net, const void *fopen_args, ailiaFileCallback callback, int version)
Initializes the network instance. (User-defined file access callback)
int AILIA_API ailiaUpdate(struct AILIANetwork *net)
Makes inferences with the input data specified in advance.
int AILIA_API ailiaCreate(struct AILIANetwork **net, int env_id, int num_thread)
Creates a network instance.
int AILIA_API ailiaGetInputDim(struct AILIANetwork *net, unsigned int *dim)
Gets the dimension of the input data during inference.
int AILIA_API ailiaGetOutputShapeND(struct AILIANetwork *net, unsigned int *shape, unsigned int dim)
Gets the shape of the output data during inference.
int AILIA_API ailiaFindBlobNameByIndex(struct AILIANetwork *net, char *buffer, const unsigned int buffer_size, const unsigned int blob_idx)
Searches by index for the name of the internal data (blob) during inference and returns it.
int AILIA_API ailiaSummary(struct AILIANetwork *net, char *const buffer, const unsigned int buffer_size)
Shows the name and shape of each blob.
int AILIA_API ailiaOpenStreamMem(struct AILIANetwork *net, const void *buf, unsigned int buf_size)
Initializes the network instance. (Read from memory)
int AILIA_API ailiaSetProfileMode(struct AILIANetwork *net, unsigned int mode)
Set the profile mode.
int AILIA_API ailiaGetBlobIndexByInputIndex(struct AILIANetwork *net, unsigned int *blob_idx, unsigned int input_blob_idx)
Get the blob index of the input data.
int AILIA_API ailiaGetBlobCount(struct AILIANetwork *net, unsigned int *blob_count)
Gets the amount of internal data (blob) during inference.
int AILIA_API ailiaGetInputShapeND(struct AILIANetwork *net, unsigned int *shape, unsigned int dim)
Gets the shape of the input data during inference.
int AILIA_API ailiaGetBlobIndexByOutputIndex(struct AILIANetwork *net, unsigned int *blob_idx, unsigned int output_blob_idx)
Get the blob index of the input data blob.
int AILIA_API ailiaGetSelectedEnvironment(struct AILIANetwork *net, AILIAEnvironment **env, unsigned int version)
Gets the selected computational environment.
int AILIA_API ailiaSetInputShapeND(struct AILIANetwork *net, const unsigned int *shape, unsigned int dim)
Changes the shape of the input data during inference.
user-defined callback
Definition: ailia.h:1461
const char * name
Definition: ailia.h:1485
int backend
Definition: ailia.h:1493
int type
Definition: ailia.h:1477
int id
Definition: ailia.h:1469
int props
Definition: ailia.h:1501
Definition: ailia.h:371
unsigned int w
Definition: ailia.h:403
unsigned int z
Definition: ailia.h:395
unsigned int y
Definition: ailia.h:387
unsigned int x
Definition: ailia.h:379
unsigned int dim
Definition: ailia.h:411
Definition: ailia_call.h:206