infinicore.h 3.09 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
#ifndef __INFINICORE_H__
#define __INFINICORE_H__
#include <stdint.h>

5
6
#ifndef __INFINI_EXPORT_C__
#define __INFINI_EXPORT_C__
PanZezhongQY's avatar
PanZezhongQY committed
7
8
#if defined(_WIN32)
#define __export __declspec(dllexport)
9
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
PanZezhongQY's avatar
PanZezhongQY committed
10
11
12
13
14
15
16
17
18
19
20
21
#define __export __attribute__((visibility("default")))
#else
#define __export
#endif

#ifdef __cplusplus
#define __C extern "C"
#include <cstddef>
#else
#define __C
#include <stddef>
#endif
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#endif // __INFINI_EXPORT_C__

#ifndef __INFINI_STATUS__
#define __INFINI_STATUS__
typedef enum {
    // Success
    INFINI_STATUS_SUCCESS = 0,
    // General Errors
    INFINI_STATUS_INTERNAL_ERROR = 1,
    INFINI_STATUS_NOT_IMPLEMENTED = 2,
    INFINI_STATUS_BAD_PARAM = 3,
    INFINI_STATUS_NULL_POINTER = 4,
    INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED = 5,
    INFINI_STATUS_DEVICE_NOT_FOUND = 6,
    // Op Errors
    INFINI_STATUS_BAD_TENSOR_DTYPE = 10,
    INFINI_STATUS_BAD_TENSOR_SHAPE = 11,
    INFINI_STATUS_BAD_TENSOR_STRIDES = 12,
    INFINI_STATUS_INSUFFICIENT_WORKSPACE = 13,
} infiniStatus_t;
#endif // __INFINI_STATUS__
PanZezhongQY's avatar
PanZezhongQY committed
43
44
45

#ifndef __INFINI_DEVICE__
#define __INFINI_DEVICE__
PanZezhong's avatar
PanZezhong committed
46
typedef enum {
PanZezhongQY's avatar
PanZezhongQY committed
47
48
49
50
51
52
53
54
55
56
    INFINI_DEVICE_CPU = 0,
    INFINI_DEVICE_NVIDIA = 1,
    INFINI_DEVICE_CAMBRICON = 2,
    INFINI_DEVICE_ASCEND = 3,
    INFINI_DEVICE_METAX = 4,
    INFINI_DEVICE_MOORE = 5,
    INFINI_DEVICE_ILUVATAR = 6,
    INFINI_DEVICE_KUNLUN = 7,
    INFINI_DEVICE_SUGON = 8,
} infiniDevice_t;
PanZezhong's avatar
PanZezhong committed
57
#endif // __INFINI_DEVICE__
PanZezhongQY's avatar
PanZezhongQY committed
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
83

#ifndef __INFINI_DTYPE__
#define __INFINI_DTYPE__
typedef enum {
    INFINI_DTYPE_INVALID = 0,
    INFINI_DTYPE_BYTE = 1,
    INFINI_DTYPE_BOOL = 2,
    INFINI_DTYPE_I8 = 3,
    INFINI_DTYPE_I16 = 4,
    INFINI_DTYPE_I32 = 5,
    INFINI_DTYPE_I64 = 6,
    INFINI_DTYPE_U8 = 7,
    INFINI_DTYPE_U16 = 8,
    INFINI_DTYPE_U32 = 9,
    INFINI_DTYPE_U64 = 10,
    INFINI_DTYPE_F8 = 11,
    INFINI_DTYPE_F16 = 12,
    INFINI_DTYPE_F32 = 13,
    INFINI_DTYPE_F64 = 14,
    INFINI_DTYPE_C8 = 15,
    INFINI_DTYPE_C16 = 16,
    INFINI_DTYPE_C32 = 17,
    INFINI_DTYPE_C64 = 18,
    INFINI_DTYPE_BF16 = 19,
} infiniDtype_t;

PanZezhong's avatar
PanZezhong committed
84
inline size_t infiniSizeof(infiniDtype_t dtype) {
PanZezhongQY's avatar
PanZezhongQY committed
85
    switch (dtype) {
PanZezhong's avatar
PanZezhong committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    case INFINI_DTYPE_INVALID:
        return 0;
    case INFINI_DTYPE_BYTE:
        return 1;
    case INFINI_DTYPE_BOOL:
        return 1;
    case INFINI_DTYPE_I8:
        return 1;
    case INFINI_DTYPE_I16:
        return 2;
    case INFINI_DTYPE_I32:
        return 4;
    case INFINI_DTYPE_I64:
        return 8;
    case INFINI_DTYPE_U8:
        return 1;
    case INFINI_DTYPE_U16:
        return 2;
    case INFINI_DTYPE_U32:
        return 4;
    case INFINI_DTYPE_U64:
        return 8;
    case INFINI_DTYPE_F8:
        return 1;
    case INFINI_DTYPE_F16:
        return 2;
    case INFINI_DTYPE_F32:
        return 4;
    case INFINI_DTYPE_F64:
        return 8;
    case INFINI_DTYPE_C8:
        return 2;
    case INFINI_DTYPE_C16:
        return 4;
    case INFINI_DTYPE_C32:
        return 8;
    case INFINI_DTYPE_C64:
        return 16;
    case INFINI_DTYPE_BF16:
        return 2;
    default:
        return 0;
PanZezhongQY's avatar
PanZezhongQY committed
128
129
    }
}
PanZezhong's avatar
PanZezhong committed
130
#endif // __INFINI_DTYPE__
PanZezhongQY's avatar
PanZezhongQY committed
131

PanZezhong's avatar
PanZezhong committed
132
#endif // __INFINICORE_H__