utils.h 2.25 KB
Newer Older
PanZezhong's avatar
PanZezhong committed
1
2
3
#ifndef INFINIUTILS_H
#define INFINIUTILS_H

PanZezhong's avatar
PanZezhong committed
4
#include "infinicore.h"
PanZezhong's avatar
PanZezhong committed
5
#include "utils/check.h"
6
#include "utils/custom_types.h"
PanZezhong's avatar
PanZezhong committed
7
8
#include "utils/rearrange.h"

PanZezhong's avatar
PanZezhong committed
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
inline size_t infiniSizeOf(infiniDtype_t dtype) {
    switch (dtype) {
    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_C16:
42
        return 2;
PanZezhong's avatar
PanZezhong committed
43
    case INFINI_DTYPE_C32:
44
        return 4;
PanZezhong's avatar
PanZezhong committed
45
    case INFINI_DTYPE_C64:
46
47
        return 8;
    case INFINI_DTYPE_C128:
PanZezhong's avatar
PanZezhong committed
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
83
84
85
86
87
88
89
90
91
92
93
        return 16;
    case INFINI_DTYPE_BF16:
        return 2;
    default:
        return 0;
    }
}

inline std::string infiniDtypeToString(infiniDtype_t dtype) {
    switch (dtype) {
    case INFINI_DTYPE_INVALID:
        return "INVALID";
    case INFINI_DTYPE_BYTE:
        return "BYTE";
    case INFINI_DTYPE_BOOL:
        return "BOOL";
    case INFINI_DTYPE_I8:
        return "I8";
    case INFINI_DTYPE_I16:
        return "I16";
    case INFINI_DTYPE_I32:
        return "I32";
    case INFINI_DTYPE_I64:
        return "I64";
    case INFINI_DTYPE_U8:
        return "U8";
    case INFINI_DTYPE_U16:
        return "U16";
    case INFINI_DTYPE_U32:
        return "U32";
    case INFINI_DTYPE_U64:
        return "U64";
    case INFINI_DTYPE_F8:
        return "F8";
    case INFINI_DTYPE_F16:
        return "F16";
    case INFINI_DTYPE_F32:
        return "F32";
    case INFINI_DTYPE_F64:
        return "F64";
    case INFINI_DTYPE_C16:
        return "C16";
    case INFINI_DTYPE_C32:
        return "C32";
    case INFINI_DTYPE_C64:
        return "C64";
94
95
    case INFINI_DTYPE_C128:
        return "C128";
PanZezhong's avatar
PanZezhong committed
96
97
98
99
100
101
102
    case INFINI_DTYPE_BF16:
        return "BF16";
    default:
        return "INVALID";
    }
}

PanZezhong's avatar
PanZezhong committed
103
#endif