Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_GpuLaunch.nolint.H
Go to the documentation of this file.
1
// Do not include this header anywhere other than AMReX_GpuLaunch.H.
2
// The purpose of this file is to avoid clang-tidy.
3
4
#define AMREX_GET_LAUNCH_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
5
#define AMREX_LAUNCH_DEVICE_LAMBDA(...) AMREX_GET_LAUNCH_MACRO(__VA_ARGS__,\
6
AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE_3, \
7
AMREX_WRONG_NUM_ARGS, \
8
AMREX_WRONG_NUM_ARGS, \
9
AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE_2, \
10
AMREX_WRONG_NUM_ARGS, \
11
AMREX_WRONG_NUM_ARGS, \
12
AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE, \
13
AMREX_WRONG_NUM_ARGS, \
14
AMREX_WRONG_NUM_ARGS)(__VA_ARGS__)
15
16
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA(...) AMREX_GET_LAUNCH_MACRO(__VA_ARGS__,\
17
AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_3, \
18
AMREX_WRONG_NUM_ARGS, \
19
AMREX_WRONG_NUM_ARGS, \
20
AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_2, \
21
AMREX_WRONG_NUM_ARGS, \
22
AMREX_WRONG_NUM_ARGS, \
23
AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE, \
24
AMREX_WRONG_NUM_ARGS, \
25
AMREX_WRONG_NUM_ARGS)(__VA_ARGS__)
26
27
#if (AMREX_SPACEDIM == 1)
28
#define AMREX_LAUNCH_DEVICE_LAMBDA_DIM(a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE (a1,a2,a3)
29
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM(a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE(a1,a2,a3)
30
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM_FLAG(fl,a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_FLAG(fl,a1,a2,a3)
31
#elif (AMREX_SPACEDIM == 2)
32
#define AMREX_LAUNCH_DEVICE_LAMBDA_DIM(a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE_2 (a1,a2,a3,b1,b2,b3)
33
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM(a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_2(a1,a2,a3,b1,b2,b3)
34
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM_FLAG(fl,a1,a2,a3,b1,b2,b3,c1,c2,c3) AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_2_FLAG(fl,a1,a2,a3,b1,b2,b3)
35
#elif (AMREX_SPACEDIM == 3)
36
#define AMREX_LAUNCH_DEVICE_LAMBDA_DIM(...) AMREX_GPU_LAUNCH_DEVICE_LAMBDA_RANGE_3 (__VA_ARGS__)
37
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM(...) AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_3(__VA_ARGS__)
38
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM_FLAG(...) AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_3_FLAG(__VA_ARGS__)
39
#endif
40
41
#ifdef AMREX_USE_GPU
42
43
#define AMREX_HOST_DEVICE_PARALLEL_FOR_1D_FLAG(where_to_run,n,i,block) \
44
{ using amrex_i_inttype = std::remove_const_t<decltype(n)>; \
45
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
46
{ \
47
amrex::ParallelFor(n, [=] AMREX_GPU_DEVICE (amrex_i_inttype i) noexcept \
48
block \
49
); \
50
} \
51
else { \
52
AMREX_PRAGMA_SIMD \
53
for (amrex_i_inttype i = 0; i < n; ++i) { \
54
block \
55
} \
56
}}
57
58
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D_FLAG(where_to_run,box,i,j,k,block) \
59
{ \
60
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
61
{ \
62
amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept \
63
block \
64
); \
65
} \
66
else { \
67
amrex::LoopConcurrentOnCpu(box, [=] (int i, int j, int k) noexcept \
68
block \
69
); \
70
} \
71
}
72
73
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run,box,nc,i,j,k,n,block) \
74
{ \
75
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
76
{ \
77
amrex::ParallelFor(box, nc, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept \
78
block \
79
); \
80
} \
81
else { \
82
amrex::LoopConcurrentOnCpu(box, nc, [=] (int i, int j, int k, int n) noexcept \
83
block \
84
); \
85
} \
86
}
87
88
#define AMREX_HOST_DEVICE_FOR_1D_FLAG(where_to_run,n,i,block) \
89
{ using amrex_i_inttype = std::remove_const_t<decltype(n)>; \
90
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
91
{ \
92
amrex::ParallelFor(n, [=] AMREX_GPU_DEVICE (amrex_i_inttype i) noexcept \
93
block \
94
); \
95
} \
96
else { \
97
for (amrex_i_inttype i = 0; i < n; ++i) { \
98
block \
99
} \
100
}}
101
102
#define AMREX_HOST_DEVICE_FOR_3D_FLAG(where_to_run,box,i,j,k,block) \
103
{ \
104
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
105
{ \
106
amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept \
107
block \
108
); \
109
} \
110
else { \
111
amrex::LoopOnCpu(box, [=] (int i, int j, int k) noexcept \
112
block \
113
); \
114
} \
115
}
116
117
#define AMREX_HOST_DEVICE_FOR_4D_FLAG(where_to_run,box,nc,i,j,k,n,block) \
118
{ \
119
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
120
{ \
121
amrex::ParallelFor(box, nc, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept \
122
block \
123
); \
124
} \
125
else { \
126
amrex::LoopOnCpu(box, nc, [=] (int i, int j, int k, int n) noexcept \
127
block \
128
); \
129
} \
130
}
131
132
#if defined(AMREX_USE_CUDA) && defined(_WIN32)
133
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_FLAG(where_to_run,box,tbox,block) \
134
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
135
{ \
136
amrex::launch(box, [=] AMREX_GPU_DEVICE (std::decay_t<decltype(box)> const& tbox) { block }); \
137
} else { \
138
auto tbox = box; \
139
block; \
140
}
141
#else
142
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_FLAG(where_to_run,box,tbox,block) \
143
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
144
{ \
145
AMREX_LAUNCH_DEVICE_LAMBDA(box,tbox,block); \
146
} else { \
147
auto tbox = box; \
148
block; \
149
}
150
#endif
151
152
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_FLAG(where_to_run,bx1,tbx1,block1) \
153
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
154
{ \
155
AMREX_LAUNCH_DEVICE_LAMBDA(bx1,tbx1,block1); \
156
} else { \
157
auto tbx1 = bx1; \
158
block1; \
159
}
160
161
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_2_FLAG(where_to_run,bx1,tbx1,block1,bx2,tbx2,block2) \
162
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
163
{ \
164
AMREX_LAUNCH_DEVICE_LAMBDA(bx1,tbx1,block1,bx2,tbx2,block2); \
165
} else { \
166
auto tbx1 = bx1; \
167
auto tbx2 = bx2; \
168
block1; \
169
block2; \
170
}
171
172
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_3_FLAG(where_to_run,bx1,tbx1,block1,bx2,tbx2,block2,bx3,tbx3,block3) \
173
if ((where_to_run == RunOn::Device) && (Gpu::inLaunchRegion())) \
174
{ \
175
AMREX_LAUNCH_DEVICE_LAMBDA(bx1,tbx1,block1,bx2,tbx2,block2,bx3,tbx3,block3); \
176
} else { \
177
auto tbx1 = bx1; \
178
auto tbx2 = bx2; \
179
auto tbx3 = bx3; \
180
block1; \
181
block2; \
182
block3; \
183
}
184
185
#else
186
187
#define AMREX_HOST_DEVICE_PARALLEL_FOR_1D_FLAG(where_to_run,n,i,block) \
188
{ using amrex_i_inttype = std::remove_const_t<decltype(n)>; \
189
amrex::ignore_unused(where_to_run); \
190
AMREX_PRAGMA_SIMD \
191
for (amrex_i_inttype i = 0; i < n; ++i) { \
192
block \
193
}}
194
195
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D_FLAG(where_to_run,box,i,j,k,block) \
196
{ \
197
amrex::ignore_unused(where_to_run); \
198
amrex::LoopConcurrentOnCpu(box, [&] (int i, int j, int k) noexcept \
199
block \
200
); \
201
}
202
203
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run,box,nc,i,j,k,n,block) \
204
{ \
205
amrex::ignore_unused(where_to_run); \
206
amrex::LoopConcurrentOnCpu(box, nc, [&] (int i, int j, int k, int n) noexcept \
207
block \
208
); \
209
}
210
211
#define AMREX_HOST_DEVICE_FOR_1D_FLAG(where_to_run,n,i,block) \
212
{ using amrex_i_inttype = std::remove_const_t<decltype(n)>; \
213
amrex::ignore_unused(where_to_run); \
214
for (amrex_i_inttype i = 0; i < n; ++i) { \
215
block \
216
}}
217
218
#define AMREX_HOST_DEVICE_FOR_3D_FLAG(where_to_run,box,i,j,k,block) \
219
{ \
220
amrex::ignore_unused(where_to_run); \
221
amrex::LoopOnCpu(box, [&] (int i, int j, int k) noexcept \
222
block \
223
); \
224
}
225
226
#define AMREX_HOST_DEVICE_FOR_4D_FLAG(where_to_run,box,nc,i,j,k,n,block) \
227
{ \
228
amrex::ignore_unused(where_to_run); \
229
amrex::LoopOnCpu(box, nc, [&] (int i, int j, int k, int n) noexcept \
230
block \
231
); \
232
}
233
234
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_FLAG(where_to_run,box,tbox,block) \
235
amrex::ignore_unused(where_to_run); \
236
{ \
237
auto tbox = box; \
238
block; \
239
}
240
241
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_FLAG(where_to_run,bx1,tbx1,block1) \
242
amrex::ignore_unused(where_to_run); \
243
{ \
244
auto tbx1 = bx1; \
245
block1; \
246
}
247
248
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_2_FLAG(where_to_run,bx1,tbx1,block1,bx2,tbx2,block2) \
249
amrex::ignore_unused(where_to_run); \
250
{ \
251
auto tbx1 = bx1; \
252
auto tbx2 = bx2; \
253
block1; \
254
block2; \
255
}
256
257
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_RANGE_3_FLAG(where_to_run,bx1,tbx1,block1,bx2,tbx2,block2,bx3,tbx3,block3) \
258
amrex::ignore_unused(where_to_run); \
259
{ \
260
auto tbx1 = bx1; \
261
auto tbx2 = bx2; \
262
auto tbx3 = bx3; \
263
block1; \
264
block2; \
265
block3; \
266
}
267
268
#endif
Src
Base
AMReX_GpuLaunch.nolint.H
Generated by
1.15.0