infinicore.h 2.83 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
#ifndef __INFINICORE_H__
#define __INFINICORE_H__

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

#ifdef __cplusplus
#define __C extern "C"
#include <cstddef>
#else
#define __C
17
#include <stddef.h>
PanZezhongQY's avatar
PanZezhongQY committed
18
#endif
19
20
21
22
23
24
25
26
27
28
29

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,
PanZezhong's avatar
PanZezhong committed
30
    INFINI_STATUS_DEVICE_NOT_INITIALIZED = 7,
31
32
33
34
35
36
    // 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;
PanZezhongQY's avatar
PanZezhongQY committed
37

PanZezhong's avatar
PanZezhong committed
38
typedef enum {
PanZezhongQY's avatar
PanZezhongQY committed
39
40
41
42
43
44
45
46
47
    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,
48
    INFINI_DEVICE_TYPE_COUNT
PanZezhongQY's avatar
PanZezhongQY committed
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
} infiniDevice_t;

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
74
inline size_t infiniSizeof(infiniDtype_t dtype) {
PanZezhongQY's avatar
PanZezhongQY committed
75
    switch (dtype) {
PanZezhong's avatar
PanZezhong committed
76
77
78
79
80
81
82
83
84
85
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
    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
118
119
120
    }
}

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