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

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

PanZezhong's avatar
PanZezhong committed
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
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:
40
        return 2;
PanZezhong's avatar
PanZezhong committed
41
    case INFINI_DTYPE_C32:
42
        return 4;
PanZezhong's avatar
PanZezhong committed
43
    case INFINI_DTYPE_C64:
44
45
        return 8;
    case INFINI_DTYPE_C128:
PanZezhong's avatar
PanZezhong committed
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
83
84
85
86
87
88
89
90
91
        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";
92
93
    case INFINI_DTYPE_C128:
        return "C128";
PanZezhong's avatar
PanZezhong committed
94
95
96
97
98
99
100
    case INFINI_DTYPE_BF16:
        return "BF16";
    default:
        return "INVALID";
    }
}

101
#define CEIL_DIV(x, y) (((x) + (y)-1) / (y))
102

103
104
105
106
107
108
109
110
namespace utils {

inline size_t align(size_t size, size_t alignment) {
    return (size + alignment - 1) & ~(alignment - 1);
}

} // namespace utils

PanZezhong's avatar
PanZezhong committed
111
#endif