-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.h
210 lines (186 loc) · 4.53 KB
/
macros.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#pragma once
#ifndef SKETCH_MACROS_H__
#define SKETCH_MACROS_H__
// INLINE
#ifndef INLINE
# if __GNUC__ || __clang__
# define INLINE __attribute__((always_inline)) inline
# else
# define INLINE inline
# endif
#endif
// unlikely/likely
#ifndef unlikely
# if defined(__GNUC__) || defined(__INTEL_COMPILER)
# define unlikely(x) __builtin_expect((x), 0)
# else
# define unlikely(x) (x)
# endif
#endif
#ifndef likely
# if defined(__GNUC__) || defined(__INTEL_COMPILER)
# define likely(x) __builtin_expect(!!(x), 1)
# else
# define likely(x) (x)
# endif
#endif
#ifndef ALWAYS_INLINE
# ifdef __GNUC__
# define ALWAYS_INLINE __attribute__((always_inline))
# else
# define ALWAYS_INLINE [[always_inline]]
# endif
#endif
// OpenMP
#ifdef _OPENMP
# ifndef OMP_PRAGMA
# define OMP_PRAGMA(x) _Pragma(x)
# endif
# ifndef OMP_ONLY
# define OMP_ONLY(...) __VA_ARGS__
# endif
# ifndef OMP_PFOR
# define OMP_PFOR OMP_PRAGMA("omp parallel for")
# endif
# ifndef OMP_PFOR_DYN
# define OMP_PFOR_DYN OMP_PRAGMA("omp parallel for schedule(dynamic)")
# endif
# ifndef OMP_ELSE
# define OMP_ELSE(x, y) x
# endif
# ifndef OMP_ATOMIC
# define OMP_ATOMIC OMP_PRAGMA("omp atomic")
# endif
# ifndef OMP_CRITICAL
# define OMP_CRITICAL OMP_PRAGMA("omp critical")
# endif
# ifndef OMP_SECTIONS
# define OMP_SECTIONS OMP_PRAGMA("omp sections")
# endif
# ifndef OMP_SECTION
# define OMP_SECTION OMP_PRAGMA("omp section")
# endif
# ifndef OMP_BARRIER
# define OMP_BARRIER OMP_PRAGMA("omp barrier")
# endif
# ifndef OMP_SET_NT
# define OMP_SET_NT(x) omp_set_num_threads(x)
# endif
#else
# ifndef OMP_PRAGMA
# define OMP_PRAGMA(x)
# endif
# ifndef OMP_ONLY
# define OMP_ONLY(...)
# endif
# ifndef OMP_ELSE
# define OMP_ELSE(x, y) y
# endif
# ifndef OMP_PFOR
# define OMP_PFOR
# endif
# ifndef OMP_PFOR_DYN
# define OMP_PFOR_DYN
# endif
# ifndef OMP_ATOMIC
# define OMP_ATOMIC
# endif
# ifndef OMP_CRITICAL
# define OMP_CRITICAL
# endif
# ifndef OMP_SECTIONS
# define OMP_SECTIONS
# endif
# ifndef OMP_SECTION
# define OMP_SECTION
# endif
# ifndef OMP_BARRIER
# define OMP_BARRIER
# endif
# ifndef OMP_SET_NT
# define OMP_SET_NT(x)
# endif
#endif
#ifndef SK_RESTRICT
# if __CUDACC__ || __GNUC__ || __clang__
# define SK_RESTRICT __restrict__
# elif _MSC_VER
# define SK_RESTRICT __restrict
# else
# define SK_RESTRICT
# endif
#endif
#ifdef __CUDA_ARCH__
# define CUDA_ARCH_ONLY(...) __VA_ARGS__
# define HOST_ONLY(...)
#else
# define CUDA_ARCH_ONLY(...)
# define HOST_ONLY(...) __VA_ARGS__
#endif
#ifdef __CUDACC__
# define CUDA_PRAGMA(x) _Pragma(x)
# define CUDA_ONLY(...) __VA_ARGS__
#else
# define CUDA_PRAGMA(x)
# define CUDA_ONLY(...)
#endif
#define CPP_PASTE(...) sk__xstr__(__VA_ARGS__)
#define CPP_PASTE_UNROLL(...) sk__xstr__("unroll" __VA_ARGS__)
#if !NDEBUG
# define DBG_ONLY(...) __VA_ARGS__
# define DBG_ELSE(x, y) x
#else
# define DBG_ONLY(...)
# define DBG_ELSE(x, y) y
#endif
#if VERBOSE_AF
# define VERBOSE_ONLY(...) __VA_ARGS__
#else
# define VERBOSE_ONLY(...)
#endif
#ifndef FOREVER
# define FOREVER for(;;)
#endif
#ifndef SK_UNROLL
# define SK_UNROLL _Pragma("message \"The macro, it does nothing\"")
// Don't use SK_UNROLL, it only tells you if these below macros are defined.
# if defined(__GNUC__) && !defined(__clang__)
# define SK_UNROLL_4 _Pragma("GCC unroll 4")
# define SK_UNROLL_8 _Pragma("GCC unroll 8")
# define SK_UNROLL_16 _Pragma("GCC unroll 16")
# define SK_UNROLL_32 _Pragma("GCC unroll 32")
# define SK_UNROLL_64 _Pragma("GCC unroll 64")
# elif defined(__CUDACC__) || defined(__clang__)
# define SK_UNROLL_4 _Pragma("unroll 4")
# define SK_UNROLL_8 _Pragma("unroll 8")
# define SK_UNROLL_16 _Pragma("unroll 16")
# define SK_UNROLL_32 _Pragma("unroll 32")
# define SK_UNROLL_64 _Pragma("unroll 64")
# else
# define SK_UNROLL_4
# define SK_UNROLL_8
# define SK_UNROLL_16
# define SK_UNROLL_32
# define SK_UNROLL_64
# endif
#endif
#if defined(__has_cpp_attribute) && __cplusplus >= __has_cpp_attribute(no_unique_address)
# define SK_NO_ADDRESS [[no_unique_address]]
#else
# define SK_NO_ADDRESS
#endif
#ifndef CONST_IF
# if defined(__cpp_if_constexpr) && __cplusplus >= __cpp_if_constexpr
# define CONST_IF(...) if constexpr(__VA_ARGS__)
# else
# define CONST_IF(...) if(__VA_ARGS__)
# endif
#endif
#ifndef BLAZE_CHECK_DEBUG
# ifndef NDEBUG
# define BLAZE_CHECK_DEBUG
# else
# define BLAZE_CHECK_DEBUG , ::blaze::unchecked
# endif
#endif
#endif /* SKETCH_MACROS_H__ */