-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.h
82 lines (68 loc) · 5.31 KB
/
api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <onnxruntime_c_api.h>
#define ORT_RETURN_ON_ERROR(expr) \
do \
{ \
OrtStatus *status = (expr); \
if (status != NULL) \
{ \
const char *msgStatus = g_ort->GetErrorMessage(status); \
char *msgErr = calloc(strlen(msgStatus), sizeof(char)); \
strcpy(msgErr, msgStatus); \
g_ort->ReleaseStatus(status); \
return msgErr; \
} \
} while (0);
#define RETURN_ERROR_MSG(msg) \
{ \
char *p = msg; \
char *msgErr = calloc(strlen(p) + 1, sizeof(char)); \
strcpy(msgErr, p); \
return msgErr; \
}
const OrtApi *createApi();
char *createMemoryInfo(const OrtApi *g_ort, OrtMemoryInfo **memory_info);
char *createEnv(const OrtApi *g_ort, OrtLoggingLevel level, const char *logid, OrtEnv **env);
char *createSession(const OrtApi *g_ort, OrtEnv *env, OrtSessionOptions **session_options, OrtSession **session, const char *model_path);
char *createAllocator(const OrtApi *g_ort, OrtSession *session, OrtMemoryInfo *memory_info, OrtAllocator **allocator);
char *createTensorWithDataAsOrtValue(const OrtApi *g_ort, OrtMemoryInfo *memory_info, void *input, size_t input_len, int64_t *shape, size_t shape_len, ONNXTensorElementDataType type, OrtValue **out);
char *getAvailableProviders(const OrtApi *g_ort, char ***output, int *len);
char *getInputCount(const OrtApi *g_ort, OrtSession *session, size_t *input_count);
char *getInputNames(const OrtApi *g_ort, OrtSession *session, OrtAllocator *allocator, size_t input_count, char ***out);
char *getInputInfo(const OrtApi *g_ort, OrtSession *session, size_t index, OrtTypeInfo **type_info);
char *getOutputCount(const OrtApi *g_ort, OrtSession *session, size_t *output_count);
char *getOutputNames(const OrtApi *g_ort, OrtSession *session, OrtAllocator *allocator, size_t output_count, char ***out);
char *getOutputInfo(const OrtApi *g_ort, OrtSession *session, size_t index, OrtTypeInfo **type_info);
char *getOnnxTypeFromTypeInfo(const OrtApi *g_ort, OrtTypeInfo *typeInfo, enum ONNXType *out);
char *getTypeInfo(const OrtApi *g_ort, const OrtValue *value, OrtTypeInfo **out);
char *getTensorElementType(const OrtApi *g_ort, const OrtTensorTypeAndShapeInfo *info, enum ONNXTensorElementDataType *out);
char *getTensorShapeElementCount(const OrtApi *g_ort, const OrtTensorTypeAndShapeInfo *info, size_t *out);
char *getDimensionsCount(const OrtApi *g_ort, const OrtTensorTypeAndShapeInfo *info, size_t *out);
char *getDimensions(const OrtApi *g_ort, const OrtTensorTypeAndShapeInfo *info, int64_t *dim_values, size_t dim_values_length);
char *getSequenceElementType(const OrtApi *g_ort, const OrtSequenceTypeInfo *sequence_type_info, OrtTypeInfo **out);
char *getMapKeyType(const OrtApi *g_ort, const OrtMapTypeInfo *map_type_info, enum ONNXTensorElementDataType *out);
char *getMapValueType(const OrtApi *g_ort, const OrtMapTypeInfo *map_type_info, OrtTypeInfo **out);
char *castTypeInfoToTensorInfo(const OrtApi *g_ort, OrtTypeInfo *typeInfo, const OrtTensorTypeAndShapeInfo **out);
char *castTypeInfoToSequenceTypeInfo(const OrtApi *g_ort, OrtTypeInfo *typeInfo, const OrtSequenceTypeInfo **out);
char *castTypeInfoToMapTypeInfo(const OrtApi *g_ort, OrtTypeInfo *typeInfo, const OrtMapTypeInfo **out);
char *getTensorMutableData(const OrtApi *g_ort, OrtValue *value, void **out);
char *getValue(const OrtApi *g_ort, OrtAllocator *allocator, OrtValue *value, int index, OrtValue **out);
char *getValueCount(const OrtApi *g_ort, OrtValue *value, size_t *out);
char *getValueType(const OrtApi *g_ort, const OrtValue *value, enum ONNXType *out);
void releaseEnv(const OrtApi *g_ort, OrtEnv *env);
void releaseMapTypeInfo(const OrtApi *g_ort, OrtMapTypeInfo *info);
void releaseSession(const OrtApi *g_ort, OrtSession *session);
void releaseSessionOptions(const OrtApi *g_ort, OrtSessionOptions *sessionOptions);
void releaseAllocator(const OrtApi *g_ort, OrtAllocator *allocator);
void releaseMemoryInfo(const OrtApi *g_ort, OrtMemoryInfo *memory_info);
void releaseTypeInfo(const OrtApi *g_ort, OrtTypeInfo *type_info);
void releaseTensorTypeInfo(const OrtApi *g_ort, OrtTensorTypeAndShapeInfo *info);
void releaseSequenceTypeInfo(const OrtApi *g_ort, OrtSequenceTypeInfo *info);
void releaseValue(const OrtApi *g_ort, OrtValue *value);
void releaseAllocatorArrayOfString(OrtAllocator *allocator, size_t size, char **strings);
char *releaseAvailableProviders(const OrtApi *g_ort, char **ptr, int len);
char *run(const OrtApi *g_ort, OrtSession *session, OrtMemoryInfo *memory_info, OrtAllocator *allocator,
char **input_names, size_t input_names_len, OrtValue *input_value,
char **output_names, size_t output_names_len, OrtValue **outputs);