This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
base.h
executable file
·154 lines (130 loc) · 6.67 KB
/
base.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_2_BASE_H
#define ANDROID_HARDWARE_NEURALNETWORKS_V1_2_BASE_H
#include <android/log.h>
#include <android-base/logging.h>
#define NAME_SPACE_BEGIN \
namespace android { \
namespace hardware { \
namespace neuralnetworks { \
namespace V1_2 { \
namespace implementation {
#define NAME_SPACE_STOP \
} \
} \
} \
} \
}
static const char* kTAG = "NN_GPU_HAL";
#define NN_TRACE 0
#define NN_GPU_ENTRY() \
do { \
if (NN_TRACE) \
LOG(INFO) << "NN_GPU_HAL enter: " << __FUNCTION__; \
} while(0);
#define NN_GPU_EXIT() \
do { \
if (NN_TRACE) \
LOG(INFO) << "NN_GPU_HAL exit: " << __FUNCTION__; \
} while(0);
#define NN_GPU_CALL() \
do { \
if (NN_TRACE) \
LOG(INFO) << "NN_GPU_HAL call: " << __FUNCTION__; \
} while(0);
#define NN_DEBUG 0
#define NN_GPU_DEBUG(...) \
if (NN_DEBUG) \
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
#define NN_PERF 0
#define NN_GPU_PERF(...) \
if (NN_PERF) \
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
// Android log function wrappers
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, kTAG, __VA_ARGS__))
#define LOGD(...) \
((void)__android_log_print(ANDROID_LOG_DEBUG, kTAG, __VA_ARGS__))
#define LOGW(...) \
((void)__android_log_print(ANDROID_LOG_WARN, kTAG, __VA_ARGS__))
#define LOGE(...) \
((void)__android_log_print(ANDROID_LOG_ERROR, kTAG, __VA_ARGS__))
// Assert macro, as Android does not generally support assert.
#define ASSERT(v) \
do \
{ \
if (!(v)) \
{ \
LOGE("ASSERT failed at %s:%d - %s", __FILE__, __LINE__, #v); \
abort(); \
} \
} while(0)
// Macro to check if the input parameters for operation are valid or not.
#define NN_CHECK(v) \
do { \
if (!(v)) { \
LOGE("NN_CHECK failed: File[%s], line[%d]", __FILE__, __LINE__); \
return false; \
} \
} while(0);
#define NN_CHECK_EQ(actual, expected) \
NN_CHECK((actual) == (expected))
#define NN_OPS_CHECK NN_CHECK
#define CHECKGLERROR() \
do { \
GLenum err = glGetError(); \
if (err != GL_NO_ERROR) \
{ \
LOGE("glGetError returns error 0x%x at %s:%d", err, __FILE__, __LINE__); \
} \
} while(0);
#define CHECK_GL_STATE_RET() \
{ \
GLenum err = glGetError(); \
if (err != GL_NO_ERROR) \
{ \
LOGE("glGetError returns %d, func:%s, line: %d\n", err, __func__, __LINE__); \
return false; \
} \
return true; \
}
// Vulkan call wrapper
#define CALL_VK(func) \
if (VK_SUCCESS != (func)) { \
__android_log_print(ANDROID_LOG_ERROR, "Vulkan-NN ", \
"Vulkan error. File[%s], line[%d]", __FILE__, \
__LINE__); \
assert(false); \
}
#define VK_CHECK_RESULT(f) \
{ \
if (f != VK_SUCCESS) \
{ \
LOGE("Vulkan check failed, result = %d", f); \
} \
}
#define VKCOM_CHECK_BOOL_RET_VAL(val, ret) \
{ \
bool res = (val); \
if (!res) \
{ \
LOGW(NULL, "Check bool failed"); \
return ret; \
} \
}
#define VKCOM_CHECK_POINTER_RET_VOID(p) \
{ \
if (NULL == (p)) \
{ \
LOGW(NULL, "Check pointer failed"); \
return; \
} \
}
#define VKCOM_CHECK_POINTER_RET_VAL(p, val) \
{ \
if (NULL == (p)) \
{ \
LOGW(NULL, "Check pointer failed"); \
return (val); \
} \
}
#endif