Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_GpuLaunchFunctsG.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_LAUNCH_FUNCTS_G_H_
2#define AMREX_GPU_LAUNCH_FUNCTS_G_H_
3#include <AMReX_Config.H>
4
5namespace amrex {
6
8namespace detail {
9
10 // call_f_scalar_handler
11
12 template <typename F, typename N>
14 auto call_f_scalar_handler (F const& f, N i, Gpu::Handler const&)
15 noexcept -> decltype(f(0))
16 {
17 return f(i);
18 }
19
20 template <typename F, typename N>
22 auto call_f_scalar_handler (F const& f, N i, Gpu::Handler const& handler)
23 noexcept -> decltype(f(0,Gpu::Handler{}))
24 {
25 return f(i, handler);
26 }
27
28 // call_f_intvect_inner
29
30 template <typename F, std::size_t...Ns, class...Args>
32 auto call_f_intvect_inner (std::index_sequence<Ns...>, F const& f, IntVectND<1> iv, Args...args)
33 noexcept -> decltype(f(0, 0, 0, args...))
34 {
35 return f(iv[0], 0, 0, args...);
36 }
37
38 template <typename F, std::size_t...Ns, class...Args>
40 auto call_f_intvect_inner (std::index_sequence<Ns...>, F const& f, IntVectND<2> iv, Args...args)
41 noexcept -> decltype(f(0, 0, 0, args...))
42 {
43 return f(iv[0], iv[1], 0, args...);
44 }
45
46 template <typename F, int dim, std::size_t...Ns, class...Args>
48 auto call_f_intvect_inner (std::index_sequence<Ns...>, F const& f, IntVectND<dim> iv, Args...args)
49 noexcept -> decltype(f(iv, args...))
50 {
51 return f(iv, args...);
52 }
53
54 template <typename F, int dim, std::size_t...Ns, class...Args>
56 auto call_f_intvect_inner (std::index_sequence<Ns...>, F const& f, IntVectND<dim> iv, Args...args)
57 noexcept -> decltype(f(iv[Ns]..., args...))
58 {
59 return f(iv[Ns]..., args...);
60 }
61
62 // call_f_intvect
63
64 template <typename F, int dim>
66 auto call_f_intvect (F const& f, IntVectND<dim> iv)
67 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
68 {
69 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
70 }
71
72 // call_f_intvect_engine
73
74 template <typename F, int dim>
76 auto call_f_intvect_engine (F const& f, IntVectND<dim> iv, RandomEngine engine)
77 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine))
78 {
79 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, engine);
80 }
81
82 // call_f_intvect_handler
83
84 template <typename F, int dim>
86 auto call_f_intvect_handler (F const& f, IntVectND<dim> iv, Gpu::Handler const&)
87 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
88 {
89 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
90 }
91
92 template <typename F, int dim>
94 auto call_f_intvect_handler (F const& f, IntVectND<dim> iv, Gpu::Handler const& handler)
95 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, Gpu::Handler{}))
96 {
97 return call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, handler);
98 }
99
100 // call_f_intvect_ncomp
101
102 template <typename F, typename T, int dim>
104 auto call_f_intvect_ncomp (F const& f, IntVectND<dim> iv, T ncomp)
105 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, 0))
106 {
107 for (T n = 0; n < ncomp; ++n) {
108 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
109 }
110 }
111
112 // call_f_intvect_ncomp_engine
113
114 template <typename F, typename T, int dim>
116 auto call_f_intvect_ncomp_engine (F const& f, IntVectND<dim> iv, T ncomp, RandomEngine engine)
117 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, 0, engine))
118 {
119 for (T n = 0; n < ncomp; ++n) {
120 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, engine);
121 }
122 }
123
124 // call_f_intvect_ncomp_handler
125
126 template <typename F, typename T, int dim>
128 auto call_f_intvect_ncomp_handler (F const& f, IntVectND<dim> iv, T ncomp, Gpu::Handler const&)
129 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, 0))
130 {
131 for (T n = 0; n < ncomp; ++n) {
132 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
133 }
134 }
135
136 template <typename F, typename T, int dim>
138 auto call_f_intvect_ncomp_handler (F const& f, IntVectND<dim> iv, T ncomp, Gpu::Handler const& handler)
139 noexcept -> decltype(call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, 0, Gpu::Handler{}))
140 {
141 for (T n = 0; n < ncomp; ++n) {
142 call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n, handler);
143 }
144 }
145
146}
148
149#ifdef AMREX_USE_SYCL
150
151template <typename L>
152void single_task (gpuStream_t stream, L const& f)
153{
154 detail::SyclKernelDevPtr<L> skdp(f, stream);
155 L const* pf = skdp.template get<0>();
157
158 auto& q = *(stream.queue);
159 try {
160 q.submit([&] (sycl::handler& h) {
161 if constexpr (detail::is_big_kernel<L>()) {
162 h.single_task([=] () { (*pf)(); });
163 } else {
164 h.single_task(f);
165 }
166 });
167 } catch (sycl::exception const& ex) {
168 amrex::Abort(std::string("single_task: ")+ex.what()+"!!!!!");
169 }
170}
171
172template<typename L>
173void launch (int nblocks, int nthreads_per_block, std::size_t shared_mem_bytes,
174 gpuStream_t stream, L const& f)
175{
176 detail::SyclKernelDevPtr<L> skdp(f, stream);
177 L const* pf = skdp.template get<0>();
179
180 const auto nthreads_total = std::size_t(nthreads_per_block) * nblocks;
181 const std::size_t shared_mem_numull = (shared_mem_bytes+sizeof(unsigned long long)-1)
182 / sizeof(unsigned long long);
183 auto& q = *(stream.queue);
184 try {
185 q.submit([&] (sycl::handler& h) {
186 sycl::local_accessor<unsigned long long>
187 shared_data(sycl::range<1>(shared_mem_numull), h);
188 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
189 sycl::range<1>(nthreads_per_block)),
190 [=] (sycl::nd_item<1> item)
191 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
192 {
193 if constexpr (detail::is_big_kernel<L>()) {
194 (*pf)(Gpu::Handler{&item,shared_data.get_multi_ptr<sycl::access::decorated::yes>().get()});
195 } else {
196 f(Gpu::Handler{&item,shared_data.get_multi_ptr<sycl::access::decorated::yes>().get()});
197 }
198 });
199 });
200 } catch (sycl::exception const& ex) {
201 amrex::Abort(std::string("launch: ")+ex.what()+"!!!!!");
202 }
203}
204
205template<typename L>
206void launch (int nblocks, int nthreads_per_block, gpuStream_t stream, L const& f)
207{
208 detail::SyclKernelDevPtr<L> skdp(f, stream);
209 L const* pf = skdp.template get<0>();
211
212 const auto nthreads_total = std::size_t(nthreads_per_block) * nblocks;
213 auto& q = *(stream.queue);
214 try {
215 q.submit([&] (sycl::handler& h) {
216 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
217 sycl::range<1>(nthreads_per_block)),
218 [=] (sycl::nd_item<1> item)
219 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
220 {
221 if constexpr (detail::is_big_kernel<L>()) {
222 (*pf)(item);
223 } else {
224 f(item);
225 }
226 });
227 });
228 } catch (sycl::exception const& ex) {
229 amrex::Abort(std::string("launch: ")+ex.what()+"!!!!!");
230 }
231}
232
233template <int MT, typename L>
234void launch (int nblocks, std::size_t shared_mem_bytes, gpuStream_t stream,
235 L const& f)
236{
237 detail::SyclKernelDevPtr<L> skdp(f, stream);
238 L const* pf = skdp.template get<0>();
240
241 const auto nthreads_total = MT * std::size_t(nblocks);
242 const std::size_t shared_mem_numull = (shared_mem_bytes+sizeof(unsigned long long)-1)
243 / sizeof(unsigned long long);
244 auto& q = *(stream.queue);
245 try {
246 q.submit([&] (sycl::handler& h) {
247 sycl::local_accessor<unsigned long long>
248 shared_data(sycl::range<1>(shared_mem_numull), h);
249 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
250 sycl::range<1>(MT)),
251 [=] (sycl::nd_item<1> item)
252 [[sycl::reqd_work_group_size(MT)]]
253 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
254 {
255 if constexpr (detail::is_big_kernel<L>()) {
256 (*pf)(Gpu::Handler{&item,shared_data.get_multi_ptr<sycl::access::decorated::yes>().get()});
257 } else {
258 f(Gpu::Handler{&item,shared_data.get_multi_ptr<sycl::access::decorated::yes>().get()});
259 }
260 });
261 });
262 } catch (sycl::exception const& ex) {
263 amrex::Abort(std::string("launch: ")+ex.what()+"!!!!!");
264 }
265}
266
267template <int MT, typename L>
268void launch (int nblocks, gpuStream_t stream, L const& f)
269{
270 detail::SyclKernelDevPtr<L> skdp(f, stream);
271 L const* pf = skdp.template get<0>();
273
274 const auto nthreads_total = MT * std::size_t(nblocks);
275 auto& q = *(stream.queue);
276 try {
277 q.submit([&] (sycl::handler& h) {
278 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
279 sycl::range<1>(MT)),
280 [=] (sycl::nd_item<1> item)
281 [[sycl::reqd_work_group_size(MT)]]
282 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
283 {
284 if constexpr (detail::is_big_kernel<L>()) {
285 (*pf)(item);
286 } else {
287 f(item);
288 }
289 });
290 });
291 } catch (sycl::exception const& ex) {
292 amrex::Abort(std::string("launch: ")+ex.what()+"!!!!!");
293 }
294}
295
296template<int MT, typename T, typename L>
297void launch (T const& n, L const& f)
298{
299 if (amrex::isEmpty(n)) { return; }
300
301 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
302 L const* pf = skdp.template get<0>();
304
305 const auto ec = Gpu::makeExecutionConfig<MT>(n);
306 const auto nthreads_per_block = ec.numThreads.x;
307 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
308 auto& q = Gpu::Device::streamQueue();
309 try {
310 q.submit([&] (sycl::handler& h) {
311 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
312 sycl::range<1>(nthreads_per_block)),
313 [=] (sycl::nd_item<1> item)
314 [[sycl::reqd_work_group_size(MT)]]
315 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
316 {
317 for (auto const i : Gpu::Range(n,item.get_global_id(0),item.get_global_range(0))) {
318 if constexpr (detail::is_big_kernel<L>()) {
319 (*pf)(i);
320 } else {
321 f(i);
322 }
323 }
324 });
325 });
326 } catch (sycl::exception const& ex) {
327 amrex::Abort(std::string("launch: ")+ex.what()+"!!!!!");
328 }
329}
330
331template <int MT, std::integral T, typename L>
332void ParallelFor (Gpu::KernelInfo const& info, T n, L const& f)
333{
334 if (amrex::isEmpty(n)) { return; }
335
336 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
337 L const* pf = skdp.template get<0>();
339
340 const auto ec = Gpu::makeExecutionConfig<MT>(n);
341 const auto nthreads_per_block = ec.numThreads.x;
342 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
343 auto& q = Gpu::Device::streamQueue();
344 try {
345 if (info.hasReduction()) {
346 q.submit([&] (sycl::handler& h) {
347 sycl::local_accessor<unsigned long long>
348 shared_data(sycl::range<1>(std::max(Gpu::Device::warp_size,
349 MT/Gpu::Device::warp_size)), h);
350 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
351 sycl::range<1>(nthreads_per_block)),
352 [=] (sycl::nd_item<1> item)
353 [[sycl::reqd_work_group_size(MT)]]
354 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
355 {
356 for (std::size_t i = item.get_global_id(0), stride = item.get_global_range(0);
357 i < std::size_t(n); i += stride) {
358 int n_active_threads = amrex::min(std::size_t(n)-i+item.get_local_id(0),
359 item.get_local_range(0));
360 if constexpr (detail::is_big_kernel<L>()) {
361 detail::call_f_scalar_handler(*pf, T(i),
362 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
363 n_active_threads});
364 } else {
365 detail::call_f_scalar_handler(f, T(i),
366 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
367 n_active_threads});
368 }
369 }
370 });
371 });
372 } else {
373 q.submit([&] (sycl::handler& h) {
374 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
375 sycl::range<1>(nthreads_per_block)),
376 [=] (sycl::nd_item<1> item)
377 [[sycl::reqd_work_group_size(MT)]]
378 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
379 {
380 for (std::size_t i = item.get_global_id(0), stride = item.get_global_range(0);
381 i < std::size_t(n); i += stride) {
382 if constexpr (detail::is_big_kernel<L>()) {
383 detail::call_f_scalar_handler(*pf, T(i), Gpu::Handler{&item});
384 } else {
385 detail::call_f_scalar_handler(f, T(i), Gpu::Handler{&item});
386 }
387 }
388 });
389 });
390 }
391 } catch (sycl::exception const& ex) {
392 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
393 }
394}
395
396template <int MT, typename L, int dim>
397void ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L const& f)
398{
399 if (amrex::isEmpty(box)) { return; }
400
401 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
402 L const* pf = skdp.template get<0>();
404
405 const BoxIndexerND<dim> indexer(box);
406 using UInt = typename BoxIndexerND<dim>::UInt;
407 const auto ec = Gpu::makeExecutionConfig<MT>(box.numPts());
408 const auto nthreads_per_block = ec.numThreads.x;
409 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
410 auto& q = Gpu::Device::streamQueue();
411 try {
412 if (info.hasReduction()) {
413 q.submit([&] (sycl::handler& h) {
414 sycl::local_accessor<unsigned long long>
415 shared_data(sycl::range<1>(std::max(Gpu::Device::warp_size,
416 MT/Gpu::Device::warp_size)), h);
417 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
418 sycl::range<1>(nthreads_per_block)),
419 [=] (sycl::nd_item<1> item)
420 [[sycl::reqd_work_group_size(MT)]]
421 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
422 {
423 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
424 icell < indexer.numPts(); icell += stride) {
425 auto iv = indexer.intVect(icell);
426 int n_active_threads = amrex::min(indexer.numPts()-icell+UInt(item.get_local_id(0)),
427 UInt(item.get_local_range(0)));
428 if constexpr (detail::is_big_kernel<L>()) {
429 detail::call_f_intvect_handler(*pf,
430 iv, Gpu::Handler{&item,
431 shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
432 n_active_threads});
433 } else {
434 detail::call_f_intvect_handler(f,
435 iv, Gpu::Handler{&item,
436 shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
437 n_active_threads});
438 }
439 }
440 });
441 });
442 } else {
443 q.submit([&] (sycl::handler& h) {
444 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
445 sycl::range<1>(nthreads_per_block)),
446 [=] (sycl::nd_item<1> item)
447 [[sycl::reqd_work_group_size(MT)]]
448 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
449 {
450 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
451 icell < indexer.numPts(); icell += stride) {
452 auto iv = indexer.intVect(icell);
453 if constexpr (detail::is_big_kernel<L>()) {
454 detail::call_f_intvect_handler(*pf,iv,Gpu::Handler{&item});
455 } else {
456 detail::call_f_intvect_handler(f,iv,Gpu::Handler{&item});
457 }
458 }
459 });
460 });
461 }
462 } catch (sycl::exception const& ex) {
463 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
464 }
465}
466
467template <int MT, std::integral T, typename L, int dim>
468void ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L const& f)
469{
470 if (amrex::isEmpty(box)) { return; }
471
472 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
473 L const* pf = skdp.template get<0>();
475
476 const BoxIndexerND<dim> indexer(box);
477 using UInt = typename BoxIndexerND<dim>::UInt;
478 const auto ec = Gpu::makeExecutionConfig<MT>(box.numPts());
479 const auto nthreads_per_block = ec.numThreads.x;
480 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
481 auto& q = Gpu::Device::streamQueue();
482 try {
483 if (info.hasReduction()) {
484 q.submit([&] (sycl::handler& h) {
485 sycl::local_accessor<unsigned long long>
486 shared_data(sycl::range<1>(std::max(Gpu::Device::warp_size,
487 MT/Gpu::Device::warp_size)), h);
488 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
489 sycl::range<1>(nthreads_per_block)),
490 [=] (sycl::nd_item<1> item)
491 [[sycl::reqd_work_group_size(MT)]]
492 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
493 {
494 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
495 icell < indexer.numPts(); icell += stride) {
496 auto iv = indexer.intVect(icell);
497 int n_active_threads = amrex::min(indexer.numPts()-icell+UInt(item.get_local_id(0)),
498 UInt(item.get_local_range(0)));
499 if constexpr (detail::is_big_kernel<L>()) {
500 detail::call_f_intvect_ncomp_handler(*pf, iv, ncomp,
501 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
502 n_active_threads});
503 } else {
504 detail::call_f_intvect_ncomp_handler(f, iv, ncomp,
505 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
506 n_active_threads});
507 }
508 }
509 });
510 });
511 } else {
512 q.submit([&] (sycl::handler& h) {
513 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
514 sycl::range<1>(nthreads_per_block)),
515 [=] (sycl::nd_item<1> item)
516 [[sycl::reqd_work_group_size(MT)]]
517 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
518 {
519 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
520 icell < indexer.numPts(); icell += stride) {
521 auto iv = indexer.intVect(icell);
522 if constexpr (detail::is_big_kernel<L>()) {
523 detail::call_f_intvect_ncomp_handler(*pf,iv,ncomp,Gpu::Handler{&item});
524 } else {
525 detail::call_f_intvect_ncomp_handler(f,iv,ncomp,Gpu::Handler{&item});
526 }
527 }
528 });
529 });
530 }
531 } catch (sycl::exception const& ex) {
532 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
533 }
534}
535
536template <std::integral T, typename L>
537void ParallelForRNG (T n, L const& f)
538{
539 if (amrex::isEmpty(n)) { return; }
540
541 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
542 L const* pf = skdp.template get<0>();
544
545 const auto ec = Gpu::ExecutionConfig(n);
546 const auto nthreads_per_block = ec.numThreads.x;
547 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
548 auto& q = Gpu::Device::streamQueue();
549 auto& engdescr = *(getRandEngineDescriptor());
550 try {
551 q.submit([&] (sycl::handler& h) {
552 auto engine_acc = engdescr.get_access(h);
553 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
554 sycl::range<1>(nthreads_per_block)),
555 [=] (sycl::nd_item<1> item)
556 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
557 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
558 {
559 auto const tid = item.get_global_id(0);
560 auto engine = engine_acc.load(tid);
561 RandomEngine rand_eng{&engine};
562 for (std::size_t i = tid, stride = item.get_global_range(0); i < std::size_t(n); i += stride) {
563 if constexpr (detail::is_big_kernel<L>()) {
564 (*pf)(T(i),rand_eng);
565 } else {
566 f(T(i),rand_eng);
567 }
568 }
569 engine_acc.store(engine, tid);
570 });
571 });
572 q.wait_and_throw(); // because next launch might be on a different queue
573 } catch (sycl::exception const& ex) {
574 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
575 }
576}
577
578template <typename L, int dim>
579void ParallelForRNG (BoxND<dim> const& box, L const& f)
580{
581 if (amrex::isEmpty(box)) { return; }
582
583 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
584 L const* pf = skdp.template get<0>();
586
587 const BoxIndexerND<dim> indexer(box);
588 using UInt = typename BoxIndexerND<dim>::UInt;
589 const auto ec = Gpu::ExecutionConfig(box.numPts());
590 const auto nthreads_per_block = ec.numThreads.x;
591 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
592 auto& q = Gpu::Device::streamQueue();
593 auto& engdescr = *(getRandEngineDescriptor());
594 try {
595 q.submit([&] (sycl::handler& h) {
596 auto engine_acc = engdescr.get_access(h);
597 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
598 sycl::range<1>(nthreads_per_block)),
599 [=] (sycl::nd_item<1> item)
600 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
601 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
602 {
603 auto const tid = item.get_global_id(0);
604 auto engine = engine_acc.load(tid);
605 RandomEngine rand_eng{&engine};
606 for (UInt icell = UInt(tid), stride = UInt(item.get_global_range(0));
607 icell < indexer.numPts(); icell += stride) {
608 auto iv = indexer.intVect(icell);
609 if constexpr (detail::is_big_kernel<L>()) {
610 detail::call_f_intvect_engine(*pf,iv,rand_eng);
611 } else {
612 detail::call_f_intvect_engine(f,iv,rand_eng);
613 }
614 }
615 engine_acc.store(engine, tid);
616 });
617 });
618 q.wait_and_throw(); // because next launch might be on a different queue
619 } catch (sycl::exception const& ex) {
620 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
621 }
622}
623
624template <std::integral T, typename L, int dim>
625void ParallelForRNG (BoxND<dim> const& box, T ncomp, L const& f)
626{
627 if (amrex::isEmpty(box)) { return; }
628
629 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
630 L const* pf = skdp.template get<0>();
632
633 const BoxIndexerND<dim> indexer(box);
634 using UInt = typename BoxIndexerND<dim>::UInt;
635 const auto ec = Gpu::ExecutionConfig(box.numPts());
636 const auto nthreads_per_block = ec.numThreads.x;
637 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
638 auto& q = Gpu::Device::streamQueue();
639 auto& engdescr = *(getRandEngineDescriptor());
640 try {
641 q.submit([&] (sycl::handler& h) {
642 auto engine_acc = engdescr.get_access(h);
643 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
644 sycl::range<1>(nthreads_per_block)),
645 [=] (sycl::nd_item<1> item)
646 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
647 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
648 {
649 auto const tid = item.get_global_id(0);
650 auto engine = engine_acc.load(tid);
651 RandomEngine rand_eng{&engine};
652 for (UInt icell = UInt(tid), stride = UInt(item.get_global_range(0));
653 icell < indexer.numPts(); icell += stride) {
654 auto iv = indexer.intVect(icell);
655 if constexpr (detail::is_big_kernel<L>()) {
656 detail::call_f_intvect_ncomp_engine(*pf,iv,ncomp,rand_eng);
657 } else {
658 detail::call_f_intvect_ncomp_engine(f,iv,ncomp,rand_eng);
659 }
660 }
661 engine_acc.store(engine, tid);
662 });
663 });
664 q.wait_and_throw(); // because next launch might be on a different queue
665 } catch (sycl::exception const& ex) {
666 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
667 }
668}
669
670template <int MT, typename L1, typename L2, int dim>
671void ParallelFor (Gpu::KernelInfo const& /*info*/, BoxND<dim> const& box1, BoxND<dim> const& box2, L1 const& f1, L2 const& f2)
672{
673 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
674
675 detail::SyclKernelDevPtr<L1,L2> skdp(f1, f2, Gpu::gpuStream());
676 L1 const* pf1 = skdp.template get<0>();
677 L2 const* pf2 = skdp.template get<1>();
678 amrex::ignore_unused(pf1,pf2);
679
680 const BoxIndexerND<dim> indexer1(box1);
681 using UInt = typename BoxIndexerND<dim>::UInt;
682 const BoxIndexerND<dim> indexer2(box2);
683 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(), box2.numPts()));
684 const auto nthreads_per_block = ec.numThreads.x;
685 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
686 auto& q = Gpu::Device::streamQueue();
687 try {
688 q.submit([&] (sycl::handler& h) {
689 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
690 sycl::range<1>(nthreads_per_block)),
691 [=] (sycl::nd_item<1> item)
692 [[sycl::reqd_work_group_size(MT)]]
693 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
694 {
695 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
696 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
697 icell < ncells; icell += stride) {
698 if (icell < indexer1.numPts()) {
699 auto iv = indexer1.intVect(icell);
700 if constexpr (detail::is_big_kernel<L1,L2>()) {
701 detail::call_f_intvect(*pf1,iv);
702 } else {
703 detail::call_f_intvect(f1,iv);
704 }
705 }
706 if (icell < indexer2.numPts()) {
707 auto iv = indexer2.intVect(icell);
708 if constexpr (detail::is_big_kernel<L1,L2>()) {
709 detail::call_f_intvect(*pf2,iv);
710 } else {
711 detail::call_f_intvect(f2,iv);
712 }
713 }
714 }
715 });
716 });
717 } catch (sycl::exception const& ex) {
718 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
719 }
720}
721
722template <int MT, typename L1, typename L2, typename L3, int dim>
723void ParallelFor (Gpu::KernelInfo const& /*info*/,
724 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
725 L1 const& f1, L2 const& f2, L3 const& f3)
726{
727 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
728
729 detail::SyclKernelDevPtr<L1,L2,L3> skdp(f1, f2, f3, Gpu::gpuStream());
730 L1 const* pf1 = skdp.template get<0>();
731 L2 const* pf2 = skdp.template get<1>();
732 L3 const* pf3 = skdp.template get<2>();
733 amrex::ignore_unused(pf1,pf2,pf3);
734
735 const BoxIndexerND<dim> indexer1(box1);
736 using UInt = typename BoxIndexerND<dim>::UInt;
737 const BoxIndexerND<dim> indexer2(box2);
738 const BoxIndexerND<dim> indexer3(box3);
739 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
740 const auto nthreads_per_block = ec.numThreads.x;
741 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
742 auto& q = Gpu::Device::streamQueue();
743 try {
744 q.submit([&] (sycl::handler& h) {
745 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
746 sycl::range<1>(nthreads_per_block)),
747 [=] (sycl::nd_item<1> item)
748 [[sycl::reqd_work_group_size(MT)]]
749 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
750 {
751 auto const ncells = amrex::max(indexer1.numPts(), indexer2.numPts(), indexer3.numPts());
752 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
753 icell < ncells; icell += stride) {
754 if (icell < indexer1.numPts()) {
755 auto iv = indexer1.intVect(icell);
756 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
757 detail::call_f_intvect(*pf1,iv);
758 } else {
759 detail::call_f_intvect(f1,iv);
760 }
761 }
762 if (icell < indexer2.numPts()) {
763 auto iv = indexer2.intVect(icell);
764 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
765 detail::call_f_intvect(*pf2,iv);
766 } else {
767 detail::call_f_intvect(f2,iv);
768 }
769 }
770 if (icell < indexer3.numPts()) {
771 auto iv = indexer3.intVect(icell);
772 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
773 detail::call_f_intvect(*pf3,iv);
774 } else {
775 detail::call_f_intvect(f3,iv);
776 }
777 }
778 }
779 });
780 });
781 } catch (sycl::exception const& ex) {
782 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
783 }
784}
785
786template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
787void ParallelFor (Gpu::KernelInfo const& /*info*/,
788 BoxND<dim> const& box1, T1 ncomp1, L1 const& f1,
789 BoxND<dim> const& box2, T2 ncomp2, L2 const& f2)
790{
791 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
792
793 detail::SyclKernelDevPtr<L1,L2> skdp(f1, f2, Gpu::gpuStream());
794 L1 const* pf1 = skdp.template get<0>();
795 L2 const* pf2 = skdp.template get<1>();
796 amrex::ignore_unused(pf1,pf2);
797
798 const BoxIndexerND<dim> indexer1(box1);
799 using UInt = typename BoxIndexerND<dim>::UInt;
800 const BoxIndexerND<dim> indexer2(box2);
801 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
802 const auto nthreads_per_block = ec.numThreads.x;
803 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
804 auto& q = Gpu::Device::streamQueue();
805 try {
806 q.submit([&] (sycl::handler& h) {
807 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
808 sycl::range<1>(nthreads_per_block)),
809 [=] (sycl::nd_item<1> item)
810 [[sycl::reqd_work_group_size(MT)]]
811 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
812 {
813 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
814 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
815 icell < ncells; icell += stride) {
816 if (icell < indexer1.numPts()) {
817 auto iv = indexer1.intVect(icell);
818 if constexpr (detail::is_big_kernel<L1,L2>()) {
819 detail::call_f_intvect_ncomp(*pf1,iv,ncomp1);
820 } else {
821 detail::call_f_intvect_ncomp(f1,iv,ncomp1);
822 }
823 }
824 if (icell < indexer2.numPts()) {
825 auto iv = indexer2.intVect(icell);
826 if constexpr (detail::is_big_kernel<L1,L2>()) {
827 detail::call_f_intvect_ncomp(*pf2,iv,ncomp2);
828 } else {
829 detail::call_f_intvect_ncomp(f2,iv,ncomp2);
830 }
831 }
832 }
833 });
834 });
835 } catch (sycl::exception const& ex) {
836 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
837 }
838}
839
840template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
841void ParallelFor (Gpu::KernelInfo const& /*info*/,
842 BoxND<dim> const& box1, T1 ncomp1, L1 const& f1,
843 BoxND<dim> const& box2, T2 ncomp2, L2 const& f2,
844 BoxND<dim> const& box3, T3 ncomp3, L3 const& f3)
845{
846 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
847
848 detail::SyclKernelDevPtr<L1,L2,L3> skdp(f1, f2, f3, Gpu::gpuStream());
849 L1 const* pf1 = skdp.template get<0>();
850 L2 const* pf2 = skdp.template get<1>();
851 L3 const* pf3 = skdp.template get<2>();
852 amrex::ignore_unused(pf1,pf2,pf3);
853
854 const BoxIndexerND<dim> indexer1(box1);
855 using UInt = typename BoxIndexerND<dim>::UInt;
856 const BoxIndexerND<dim> indexer2(box2);
857 const BoxIndexerND<dim> indexer3(box3);
858 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
859 const auto nthreads_per_block = ec.numThreads.x;
860 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
861 auto& q = Gpu::Device::streamQueue();
862 try {
863 q.submit([&] (sycl::handler& h) {
864 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
865 sycl::range<1>(nthreads_per_block)),
866 [=] (sycl::nd_item<1> item)
867 [[sycl::reqd_work_group_size(MT)]]
868 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
869 {
870 auto const ncells = amrex::max(indexer1.numPts(), indexer2.numPts(), indexer3.numPts());
871 for (UInt icell = UInt(item.get_global_id(0)), stride = UInt(item.get_global_range(0));
872 icell < ncells; icell += stride) {
873 if (icell < indexer1.numPts()) {
874 auto iv = indexer1.intVect(icell);
875 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
876 detail::call_f_intvect_ncomp(*pf1,iv,ncomp1);
877 } else {
878 detail::call_f_intvect_ncomp(f1,iv,ncomp1);
879 }
880 }
881 if (icell < indexer2.numPts()) {
882 auto iv = indexer2.intVect(icell);
883 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
884 detail::call_f_intvect_ncomp(*pf2,iv,ncomp2);
885 } else {
886 detail::call_f_intvect_ncomp(f2,iv,ncomp2);
887 }
888 }
889 if (icell < indexer3.numPts()) {
890 auto iv = indexer3.intVect(icell);
891 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
892 detail::call_f_intvect_ncomp(*pf3,iv,ncomp3);
893 } else {
894 detail::call_f_intvect_ncomp(f3,iv,ncomp3);
895 }
896 }
897 }
898 });
899 });
900 } catch (sycl::exception const& ex) {
901 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
902 }
903}
904
905#else
906// CUDA or HIP
907
908template <typename L>
909void single_task (gpuStream_t stream, L const& f)
910{
911 AMREX_LAUNCH_KERNEL(Gpu::Device::warp_size, 1, 1, 0, stream, f);
913}
914
915template <int MT, typename L>
916void launch (int nblocks, std::size_t shared_mem_bytes, gpuStream_t stream,
917 L const& f)
918{
919 AMREX_LAUNCH_KERNEL(MT, nblocks, MT, shared_mem_bytes, stream, f);
921}
922
923template <int MT, typename L>
924void launch (int nblocks, gpuStream_t stream, L const& f)
925{
926 AMREX_LAUNCH_KERNEL(MT, nblocks, MT, 0, stream, f);
928}
929
930template<typename L>
931void launch (int nblocks, int nthreads_per_block, std::size_t shared_mem_bytes,
932 gpuStream_t stream, L const& f)
933{
934 AMREX_LAUNCH_KERNEL_NOBOUND(nblocks, nthreads_per_block, shared_mem_bytes, stream, f);
936}
937
938template<typename L>
939void launch (int nblocks, int nthreads_per_block, gpuStream_t stream, L&& f) noexcept
940{
941 launch(nblocks, nthreads_per_block, 0, stream, std::forward<L>(f));
942}
943
944template<int MT, std::integral T, typename L>
945void launch (T const& n, L const& f)
946{
947 static_assert(sizeof(T) >= 2);
948 if (amrex::isEmpty(n)) { return; }
949 const auto& nec = Gpu::makeNExecutionConfigs<MT>(n);
950 for (auto const& ec : nec) {
951 const T start_idx = T(ec.start_idx);
952 const T nleft = n - start_idx;
953 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
954 [=] AMREX_GPU_DEVICE () noexcept {
955 auto tid = std::uint64_t(MT)*blockIdx.x+threadIdx.x;
956 if (tid < std::uint64_t(nleft)) {
957 f(T(tid)+start_idx);
958 }
959 });
960 }
962}
963
964template<int MT, int dim, typename L>
965void launch (BoxND<dim> const& box, L const& f)
966{
967 if (box.isEmpty()) { return; }
968 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
969 const BoxIndexerND<dim> indexer(box);
970 using UInt = typename BoxIndexerND<dim>::UInt;
971 const auto type = box.ixType();
972 for (auto const& ec : nec) {
973 const auto start_idx = UInt(ec.start_idx);
974 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
975 [=] AMREX_GPU_DEVICE () noexcept {
976 auto icell = UInt(MT)*blockIdx.x+threadIdx.x + start_idx;
977 if (icell < indexer.numPts()) {
978 auto iv = indexer.intVect(icell);
979 f(BoxND<dim>(iv,iv,type));
980 }
981 });
982 }
984}
985
990template <int MT, std::integral T, typename L>
991requires (MaybeDeviceRunnable<L>::value)
992void
993ParallelFor (Gpu::KernelInfo const&, T n, L const& f)
994{
995 static_assert(sizeof(T) >= 2);
996 if (amrex::isEmpty(n)) { return; }
997 const auto& nec = Gpu::makeNExecutionConfigs<MT>(n);
998 for (auto const& ec : nec) {
999 const T start_idx = T(ec.start_idx);
1000 const T nleft = n - start_idx;
1001 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
1002 [=] AMREX_GPU_DEVICE () noexcept {
1003 auto tid = std::uint64_t(MT)*blockIdx.x+threadIdx.x;
1004 if (tid < std::uint64_t(nleft)) {
1005 detail::call_f_scalar_handler(f, T(tid)+start_idx,
1006 Gpu::Handler(amrex::min((std::uint64_t(nleft)-tid+(std::uint64_t)threadIdx.x),
1007 (std::uint64_t)MT)));
1008 }
1009 });
1010 }
1012}
1013
1018template <int MT, typename L, int dim>
1019requires (MaybeDeviceRunnable<L>::value)
1020void
1021ParallelFor (Gpu::KernelInfo const&, BoxND<dim> const& box, L const& f)
1022{
1023 if (amrex::isEmpty(box)) { return; }
1024 const BoxIndexerND<dim> indexer(box);
1025 using UInt = typename BoxIndexerND<dim>::UInt;
1026 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
1027 for (auto const& ec : nec) {
1028 const auto start_idx = UInt(ec.start_idx);
1029 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
1030 [=] AMREX_GPU_DEVICE () noexcept {
1031 auto icell = UInt(MT)*blockIdx.x+threadIdx.x + start_idx;
1032 if (icell < indexer.numPts()) {
1033 auto iv = indexer.intVect(icell);
1034 detail::call_f_intvect_handler(f, iv,
1035 Gpu::Handler(amrex::min((indexer.numPts()-icell+(UInt)threadIdx.x),
1036 (UInt)MT)));
1037 }
1038 });
1039 }
1041}
1042
1047template <int MT, std::integral T, typename L, int dim>
1048requires (MaybeDeviceRunnable<L>::value)
1049void
1050ParallelFor (Gpu::KernelInfo const&, BoxND<dim> const& box, T ncomp, L const& f)
1051{
1052 if (amrex::isEmpty(box)) { return; }
1053 const BoxIndexerND<dim> indexer(box);
1054 using UInt = typename BoxIndexerND<dim>::UInt;
1055 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
1056 for (auto const& ec : nec) {
1057 const auto start_idx = UInt(ec.start_idx);
1058 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
1059 [=] AMREX_GPU_DEVICE () noexcept {
1060 auto icell = UInt(MT)*blockIdx.x+threadIdx.x + start_idx;
1061 if (icell < indexer.numPts()) {
1062 auto iv = indexer.intVect(icell);
1063 detail::call_f_intvect_ncomp_handler(f, iv, ncomp,
1064 Gpu::Handler(amrex::min((indexer.numPts()-icell+(UInt)threadIdx.x),
1065 (UInt)MT)));
1066 }
1067 });
1068 }
1070}
1071
1077template <std::integral T, typename L>
1078requires (MaybeDeviceRunnable<L>::value)
1079void
1080ParallelForRNG (T n, L const& f)
1081{
1082 if (amrex::isEmpty(n)) { return; }
1083 randState_t* rand_state = getRandState();
1084 const auto ec = Gpu::ExecutionConfig(n);
1085 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1087 ec.numThreads, 0, Gpu::gpuStream(),
1088 [=] AMREX_GPU_DEVICE () noexcept {
1089 Long tid = Long(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1090 RandomEngine engine{&(rand_state[tid])};
1091 for (Long i = tid, stride = Long(AMREX_GPU_MAX_THREADS)*gridDim.x; i < Long(n); i += stride) {
1092 f(T(i),engine);
1093 }
1094 });
1095 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1097}
1098
1104template <typename L, int dim>
1105requires (MaybeDeviceRunnable<L>::value)
1106void
1107ParallelForRNG (BoxND<dim> const& box, L const& f)
1108{
1109 if (amrex::isEmpty(box)) { return; }
1110 randState_t* rand_state = getRandState();
1111 const BoxIndexerND<dim> indexer(box);
1112 using UInt = typename BoxIndexerND<dim>::UInt;
1113 const auto ec = Gpu::ExecutionConfig(box.numPts());
1114 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1116 ec.numThreads, 0, Gpu::gpuStream(),
1117 [=] AMREX_GPU_DEVICE () noexcept {
1118 auto const tid = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1119 RandomEngine engine{&(rand_state[tid])};
1120 for (UInt icell = UInt(tid), stride = UInt(AMREX_GPU_MAX_THREADS)*gridDim.x; icell < indexer.numPts(); icell += stride) {
1121 auto iv = indexer.intVect(icell);
1122 detail::call_f_intvect_engine(f, iv, engine);
1123 }
1124 });
1125 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1127}
1128
1134template <std::integral T, typename L, int dim>
1135requires (MaybeDeviceRunnable<L>::value)
1136void
1137ParallelForRNG (BoxND<dim> const& box, T ncomp, L const& f)
1138{
1139 if (amrex::isEmpty(box)) { return; }
1140 randState_t* rand_state = getRandState();
1141 const BoxIndexerND<dim> indexer(box);
1142 using UInt = typename BoxIndexerND<dim>::UInt;
1143 const auto ec = Gpu::ExecutionConfig(box.numPts());
1144 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1146 ec.numThreads, 0, Gpu::gpuStream(),
1147 [=] AMREX_GPU_DEVICE () noexcept {
1148 auto const tid = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1149 RandomEngine engine{&(rand_state[tid])};
1150 for (UInt icell = UInt(tid), stride = UInt(AMREX_GPU_MAX_THREADS)*gridDim.x; icell < indexer.numPts(); icell += stride) {
1151 auto iv = indexer.intVect(icell);
1152 detail::call_f_intvect_ncomp_engine(f, iv, ncomp, engine);
1153 }
1154 });
1155 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1157}
1158
1163template <int MT, typename L1, typename L2, int dim>
1164requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1165void
1167 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1168{
1169 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
1170 const BoxIndexerND<dim> indexer1(box1);
1171 using UInt = typename BoxIndexerND<dim>::UInt;
1172 const BoxIndexerND<dim> indexer2(box2);
1173 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
1174 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1175 [=] AMREX_GPU_DEVICE () noexcept {
1176 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
1177 for (UInt icell = UInt(MT)*blockIdx.x+threadIdx.x, stride = UInt(MT)*gridDim.x;
1178 icell < ncells; icell += stride) {
1179 if (icell < indexer1.numPts()) {
1180 auto iv = indexer1.intVect(icell);
1181 detail::call_f_intvect(f1, iv);
1182 }
1183 if (icell < indexer2.numPts()) {
1184 auto iv = indexer2.intVect(icell);
1185 detail::call_f_intvect(f2, iv);
1186 }
1187 }
1188 });
1190}
1191
1196template <int MT, typename L1, typename L2, typename L3, int dim>
1197requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1198 MaybeDeviceRunnable<L3>::value)
1199void
1201 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1202 L1&& f1, L2&& f2, L3&& f3)
1203{
1204 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
1205 const BoxIndexerND<dim> indexer1(box1);
1206 using UInt = typename BoxIndexerND<dim>::UInt;
1207 const BoxIndexerND<dim> indexer2(box2);
1208 const BoxIndexerND<dim> indexer3(box3);
1209 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
1210 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1211 [=] AMREX_GPU_DEVICE () noexcept {
1212 auto const ncells = std::max({indexer1.numPts(), indexer2.numPts(), indexer3.numPts()});
1213 for (UInt icell = UInt(MT)*blockIdx.x+threadIdx.x, stride = UInt(MT)*gridDim.x;
1214 icell < ncells; icell += stride) {
1215 if (icell < indexer1.numPts()) {
1216 auto iv = indexer1.intVect(icell);
1217 detail::call_f_intvect(f1, iv);
1218 }
1219 if (icell < indexer2.numPts()) {
1220 auto iv = indexer2.intVect(icell);
1221 detail::call_f_intvect(f2, iv);
1222 }
1223 if (icell < indexer3.numPts()) {
1224 auto iv = indexer3.intVect(icell);
1225 detail::call_f_intvect(f3, iv);
1226 }
1227 }
1228 });
1230}
1231
1236template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1237requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1238void
1240 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1241 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1242{
1243 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
1244 const BoxIndexerND<dim> indexer1(box1);
1245 using UInt = typename BoxIndexerND<dim>::UInt;
1246 const BoxIndexerND<dim> indexer2(box2);
1247 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
1248 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1249 [=] AMREX_GPU_DEVICE () noexcept {
1250 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
1251 for (UInt icell = UInt(MT)*blockIdx.x+threadIdx.x, stride = UInt(MT)*gridDim.x;
1252 icell < ncells; icell += stride) {
1253 if (icell < indexer1.numPts()) {
1254 auto iv = indexer1.intVect(icell);
1255 detail::call_f_intvect_ncomp(f1, iv, ncomp1);
1256 }
1257 if (icell < indexer2.numPts()) {
1258 auto iv = indexer2.intVect(icell);
1259 detail::call_f_intvect_ncomp(f2, iv, ncomp2);
1260 }
1261 }
1262 });
1264}
1265
1270template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1271requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1272 MaybeDeviceRunnable<L3>::value)
1273void
1275 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1276 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1277 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
1278{
1279 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
1280 const BoxIndexerND<dim> indexer1(box1);
1281 using UInt = typename BoxIndexerND<dim>::UInt;
1282 const BoxIndexerND<dim> indexer2(box2);
1283 const BoxIndexerND<dim> indexer3(box3);
1284 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
1285 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1286 [=] AMREX_GPU_DEVICE () noexcept {
1287 auto const ncells = std::max({indexer1.numPts(), indexer2.numPts(), indexer3.numPts()});
1288 for (UInt icell = UInt(MT)*blockIdx.x+threadIdx.x, stride = UInt(MT)*gridDim.x;
1289 icell < ncells; icell += stride) {
1290 if (icell < indexer1.numPts()) {
1291 auto iv = indexer1.intVect(icell);
1292 detail::call_f_intvect_ncomp(f1, iv, ncomp1);
1293 }
1294 if (icell < indexer2.numPts()) {
1295 auto iv = indexer2.intVect(icell);
1296 detail::call_f_intvect_ncomp(f2, iv, ncomp2);
1297 }
1298 if (icell < indexer3.numPts()) {
1299 auto iv = indexer3.intVect(icell);
1300 detail::call_f_intvect_ncomp(f3, iv, ncomp3);
1301 }
1302 }
1303 });
1305}
1306
1307#endif
1308
1309template <typename L>
1310void single_task (L&& f) noexcept
1311{
1312 single_task(Gpu::gpuStream(), std::forward<L>(f));
1313}
1314
1315template<typename T, typename L>
1316void launch (T const& n, L&& f) noexcept
1317{
1318 launch<AMREX_GPU_MAX_THREADS>(n, std::forward<L>(f));
1319}
1320
1325template <std::integral T, typename L>
1326requires (MaybeDeviceRunnable<L>::value)
1327void
1328ParallelFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1329{
1330 ParallelFor<AMREX_GPU_MAX_THREADS>(info, n, std::forward<L>(f));
1331}
1332
1337template <typename L, int dim>
1338requires (MaybeDeviceRunnable<L>::value)
1339void
1340ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1341{
1342 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box, std::forward<L>(f));
1343}
1344
1349template <std::integral T, typename L, int dim>
1350requires (MaybeDeviceRunnable<L>::value)
1351void
1352ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1353{
1354 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box, ncomp, std::forward<L>(f));
1355}
1356
1361template <typename L1, typename L2, int dim>
1362requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1363void
1365 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1366{
1367 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, box2, std::forward<L1>(f1),
1368 std::forward<L2>(f2));
1369}
1370
1375template <typename L1, typename L2, typename L3, int dim>
1376requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1377 MaybeDeviceRunnable<L3>::value)
1378void
1380 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1381 L1&& f1, L2&& f2, L3&& f3) noexcept
1382{
1383 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, box2, box3, std::forward<L1>(f1),
1384 std::forward<L2>(f2), std::forward<L3>(f3));
1385}
1386
1391template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1392requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1393void
1395 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1396 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1397{
1398 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, ncomp1, std::forward<L1>(f1),
1399 box2, ncomp2, std::forward<L2>(f2));
1400}
1401
1406template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1407requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1408 MaybeDeviceRunnable<L3>::value)
1409void
1411 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1412 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1413 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1414{
1415 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, ncomp1, std::forward<L1>(f1),
1416 box2, ncomp2, std::forward<L2>(f2),
1417 box3, ncomp3, std::forward<L3>(f3));
1418}
1419
1420template <std::integral T, typename L>
1421void For (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1422{
1423 ParallelFor<AMREX_GPU_MAX_THREADS>(info, n,std::forward<L>(f));
1424}
1425
1426template <int MT, std::integral T, typename L>
1427void For (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1428{
1429 ParallelFor<MT>(info, n,std::forward<L>(f));
1430}
1431
1432template <typename L, int dim>
1433void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1434{
1435 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,std::forward<L>(f));
1436}
1437
1438template <int MT, typename L, int dim>
1439void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1440{
1441 ParallelFor<MT>(info, box,std::forward<L>(f));
1442}
1443
1444template <std::integral T, typename L, int dim>
1445void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1446{
1447 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box,ncomp,std::forward<L>(f));
1448}
1449
1450template <int MT, std::integral T, typename L, int dim>
1451void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1452{
1453 ParallelFor<MT>(info,box,ncomp,std::forward<L>(f));
1454}
1455
1456template <typename L1, typename L2, int dim>
1457void For (Gpu::KernelInfo const& info,
1458 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1459{
1460 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1461}
1462
1463template <int MT, typename L1, typename L2, int dim>
1464void For (Gpu::KernelInfo const& info,
1465 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1466{
1467 ParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1468}
1469
1470template <typename L1, typename L2, typename L3, int dim>
1471void For (Gpu::KernelInfo const& info,
1472 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1473 L1&& f1, L2&& f2, L3&& f3) noexcept
1474{
1475 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1476}
1477
1478template <int MT, typename L1, typename L2, typename L3, int dim>
1479void For (Gpu::KernelInfo const& info,
1480 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1481 L1&& f1, L2&& f2, L3&& f3) noexcept
1482{
1483 ParallelFor<MT>(info,box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1484}
1485
1486template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1487void For (Gpu::KernelInfo const& info,
1488 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1489 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1490{
1491 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1492}
1493
1494template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1495void For (Gpu::KernelInfo const& info,
1496 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1497 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1498{
1499 ParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1500}
1501
1502template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1503void For (Gpu::KernelInfo const& info,
1504 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1505 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1506 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1507{
1509 box1,ncomp1,std::forward<L1>(f1),
1510 box2,ncomp2,std::forward<L2>(f2),
1511 box3,ncomp3,std::forward<L3>(f3));
1512}
1513
1514template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1515void For (Gpu::KernelInfo const& info,
1516 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1517 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1518 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1519{
1520 ParallelFor<MT>(info,
1521 box1,ncomp1,std::forward<L1>(f1),
1522 box2,ncomp2,std::forward<L2>(f2),
1523 box3,ncomp3,std::forward<L3>(f3));
1524}
1525
1530template <std::integral T, typename L>
1531void ParallelFor (T n, L&& f) noexcept
1532{
1533 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1534}
1535
1540template <int MT, std::integral T, typename L>
1541void ParallelFor (T n, L&& f) noexcept
1542{
1543 ParallelFor<MT>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1544}
1545
1550template <typename L, int dim>
1551void ParallelFor (BoxND<dim> const& box, L&& f) noexcept
1552{
1553 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, box, std::forward<L>(f));
1554}
1555
1560template <int MT, typename L, int dim>
1561void ParallelFor (BoxND<dim> const& box, L&& f) noexcept
1562{
1563 ParallelFor<MT>(Gpu::KernelInfo{}, box, std::forward<L>(f));
1564}
1565
1570template <std::integral T, typename L, int dim>
1571void ParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1572{
1573 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1574}
1575
1580template <int MT, std::integral T, typename L, int dim>
1581void ParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1582{
1583 ParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1584}
1585
1590template <typename L1, typename L2, int dim>
1591void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1592{
1593 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1594}
1595
1600template <int MT, typename L1, typename L2, int dim>
1601void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1602{
1603 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1604}
1605
1610template <typename L1, typename L2, typename L3, int dim>
1611void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1612 L1&& f1, L2&& f2, L3&& f3) noexcept
1613{
1614 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1615}
1616
1621template <int MT, typename L1, typename L2, typename L3, int dim>
1622void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1623 L1&& f1, L2&& f2, L3&& f3) noexcept
1624{
1625 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1626}
1627
1632template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1633void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1634 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1635{
1636 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1637}
1638
1643template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1644void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1645 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1646{
1647 ParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1648}
1649
1654template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1655void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1656 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1657 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1658{
1660 box1,ncomp1,std::forward<L1>(f1),
1661 box2,ncomp2,std::forward<L2>(f2),
1662 box3,ncomp3,std::forward<L3>(f3));
1663}
1664
1669template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1670void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1671 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1672 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1673{
1675 box1,ncomp1,std::forward<L1>(f1),
1676 box2,ncomp2,std::forward<L2>(f2),
1677 box3,ncomp3,std::forward<L3>(f3));
1678}
1679
1680template <std::integral T, typename L>
1681void For (T n, L&& f) noexcept
1682{
1683 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, n,std::forward<L>(f));
1684}
1685
1686template <int MT, std::integral T, typename L>
1687void For (T n, L&& f) noexcept
1688{
1689 ParallelFor<MT>(Gpu::KernelInfo{}, n,std::forward<L>(f));
1690}
1691
1692template <typename L, int dim>
1693void For (BoxND<dim> const& box, L&& f) noexcept
1694{
1695 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, box,std::forward<L>(f));
1696}
1697
1698template <int MT, typename L, int dim>
1699void For (BoxND<dim> const& box, L&& f) noexcept
1700{
1701 ParallelFor<MT>(Gpu::KernelInfo{}, box,std::forward<L>(f));
1702}
1703
1704template <std::integral T, typename L, int dim>
1705void For (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1706{
1707 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1708}
1709
1710template <int MT, std::integral T, typename L, int dim>
1711void For (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1712{
1713 ParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1714}
1715
1716template <typename L1, typename L2, int dim>
1717void For (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1718{
1719 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1720}
1721
1722template <int MT, typename L1, typename L2, int dim>
1723void For (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1724{
1725 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1726}
1727
1728template <typename L1, typename L2, typename L3, int dim>
1729void For (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1730 L1&& f1, L2&& f2, L3&& f3) noexcept
1731{
1732 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1733}
1734
1735template <int MT, typename L1, typename L2, typename L3, int dim>
1736void For (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1737 L1&& f1, L2&& f2, L3&& f3) noexcept
1738{
1739 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1740}
1741
1742template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1743void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1744 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1745{
1746 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1747}
1748
1749template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1750void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1751 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1752{
1753 ParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1754}
1755
1756template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1757void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1758 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1759 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1760{
1762 box1,ncomp1,std::forward<L1>(f1),
1763 box2,ncomp2,std::forward<L2>(f2),
1764 box3,ncomp3,std::forward<L3>(f3));
1765}
1766
1767template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1768void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1769 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1770 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1771{
1773 box1,ncomp1,std::forward<L1>(f1),
1774 box2,ncomp2,std::forward<L2>(f2),
1775 box3,ncomp3,std::forward<L3>(f3));
1776}
1777
1778template <std::integral T, typename L>
1780void
1782{
1783 if (Gpu::inLaunchRegion()) {
1784 ParallelFor<AMREX_GPU_MAX_THREADS>(info,n,std::forward<L>(f));
1785 } else {
1787 for (T i = 0; i < n; ++i) { f(i); }
1788 }
1789}
1790
1791template <int MT, std::integral T, typename L>
1792requires (MaybeHostDeviceRunnable<L>::value)
1793void
1795{
1796 if (Gpu::inLaunchRegion()) {
1797 ParallelFor<MT>(info,n,std::forward<L>(f));
1798 } else {
1800 for (T i = 0; i < n; ++i) { f(i); }
1801 }
1802}
1803
1804template <std::integral T, typename L>
1805requires (MaybeHostDeviceRunnable<L>::value)
1806void
1807HostDeviceParallelFor (T n, L&& f) noexcept
1808{
1810}
1811
1812template <int MT, std::integral T, typename L>
1813requires (MaybeHostDeviceRunnable<L>::value)
1814void
1815HostDeviceParallelFor (T n, L&& f) noexcept
1816{
1817 HostDeviceParallelFor<MT>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1818}
1819
1820template <typename L, int dim>
1821requires (MaybeHostDeviceRunnable<L>::value)
1822void
1823HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f)
1824{
1825 if (Gpu::inLaunchRegion()) {
1826 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,std::forward<L>(f));
1827 } else {
1828 LoopConcurrentOnCpu(box,std::forward<L>(f));
1829 }
1830}
1831
1832template <int MT, typename L, int dim>
1833requires (MaybeHostDeviceRunnable<L>::value)
1834void
1835HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f)
1836{
1837 if (Gpu::inLaunchRegion()) {
1838 ParallelFor<MT>(info, box,std::forward<L>(f));
1839 } else {
1840 LoopConcurrentOnCpu(box,std::forward<L>(f));
1841 }
1842}
1843
1844template <std::integral T, typename L, int dim>
1845requires (MaybeHostDeviceRunnable<L>::value)
1846void
1847HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f)
1848{
1849 if (Gpu::inLaunchRegion()) {
1850 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,ncomp,std::forward<L>(f));
1851 } else {
1852 LoopConcurrentOnCpu(box,ncomp,std::forward<L>(f));
1853 }
1854}
1855
1856template <int MT, std::integral T, typename L, int dim>
1857requires (MaybeHostDeviceRunnable<L>::value)
1858void
1859HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f)
1860{
1861 if (Gpu::inLaunchRegion()) {
1862 ParallelFor<MT>(info, box,ncomp,std::forward<L>(f));
1863 } else {
1864 LoopConcurrentOnCpu(box,ncomp,std::forward<L>(f));
1865 }
1866}
1867
1868template <typename L1, typename L2, int dim>
1869requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1870void
1872 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1873{
1874 if (Gpu::inLaunchRegion()) {
1875 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1876 } else {
1877 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1878 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1879 }
1880}
1881
1882template <int MT, typename L1, typename L2, int dim>
1883requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1884void
1886 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1887{
1888 if (Gpu::inLaunchRegion()) {
1889 ParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1890 } else {
1891 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1892 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1893 }
1894}
1895
1896template <typename L1, typename L2, typename L3, int dim>
1897requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1898 MaybeHostDeviceRunnable<L3>::value)
1899void
1901 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1902 L1&& f1, L2&& f2, L3&& f3)
1903{
1904 if (Gpu::inLaunchRegion()) {
1905 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,box3,
1906 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1907 } else {
1908 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1909 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1910 LoopConcurrentOnCpu(box3,std::forward<L3>(f3));
1911 }
1912}
1913
1914template <int MT, typename L1, typename L2, typename L3, int dim>
1915requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1916 MaybeHostDeviceRunnable<L3>::value)
1917void
1919 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1920 L1&& f1, L2&& f2, L3&& f3)
1921{
1922 if (Gpu::inLaunchRegion()) {
1923 ParallelFor<MT>(info,box1,box2,box3,
1924 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1925 } else {
1926 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1927 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1928 LoopConcurrentOnCpu(box3,std::forward<L3>(f3));
1929 }
1930}
1931
1932template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1933requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1934void
1936 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1937 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1938{
1939 if (Gpu::inLaunchRegion()) {
1940 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1941 } else {
1942 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1943 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
1944 }
1945}
1946
1947template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1948requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1949void
1951 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1952 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1953{
1954 if (Gpu::inLaunchRegion()) {
1955 ParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1956 } else {
1957 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1958 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
1959 }
1960}
1961
1962template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1963requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1964 MaybeHostDeviceRunnable<L3>::value)
1965void
1967 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1968 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1969 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
1970{
1971 if (Gpu::inLaunchRegion()) {
1973 box1,ncomp1,std::forward<L1>(f1),
1974 box2,ncomp2,std::forward<L2>(f2),
1975 box3,ncomp3,std::forward<L3>(f3));
1976 } else {
1977 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1978 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
1979 LoopConcurrentOnCpu(box3,ncomp3,std::forward<L3>(f3));
1980 }
1981}
1982
1983template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1984requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1985 MaybeHostDeviceRunnable<L3>::value)
1986void
1988 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1989 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1990 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
1991{
1992 if (Gpu::inLaunchRegion()) {
1993 ParallelFor<MT>(info,
1994 box1,ncomp1,std::forward<L1>(f1),
1995 box2,ncomp2,std::forward<L2>(f2),
1996 box3,ncomp3,std::forward<L3>(f3));
1997 } else {
1998 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1999 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
2000 LoopConcurrentOnCpu(box3,ncomp3,std::forward<L3>(f3));
2001 }
2002}
2003
2004template <std::integral T, typename L>
2005void HostDeviceFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
2006{
2007 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,n,std::forward<L>(f));
2008}
2009
2010template <int MT, std::integral T, typename L>
2011void HostDeviceFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
2012{
2013 HostDeviceParallelFor<MT>(info,n,std::forward<L>(f));
2014}
2015
2016template <typename L, int dim>
2017void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
2018{
2019 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box,std::forward<L>(f));
2020}
2021
2022template <int MT, typename L, int dim>
2023void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
2024{
2025 HostDeviceParallelFor<MT>(info,box,std::forward<L>(f));
2026}
2027
2028template <std::integral T, typename L, int dim>
2029void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
2030{
2031 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box,ncomp,std::forward<L>(f));
2032}
2033
2034template <int MT, std::integral T, typename L, int dim>
2035void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
2036{
2037 HostDeviceParallelFor<MT>(info,box,ncomp,std::forward<L>(f));
2038}
2039
2040template <typename L1, typename L2, int dim>
2041void HostDeviceFor (Gpu::KernelInfo const& info,
2042 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2043{
2044 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2045}
2046
2047template <int MT, typename L1, typename L2, int dim>
2048void HostDeviceFor (Gpu::KernelInfo const& info,
2049 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2050{
2051 HostDeviceParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2052}
2053
2054template <typename L1, typename L2, typename L3, int dim>
2055void HostDeviceFor (Gpu::KernelInfo const& info,
2056 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2057 L1&& f1, L2&& f2, L3&& f3) noexcept
2058{
2060 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2061}
2062
2063template <int MT, typename L1, typename L2, typename L3, int dim>
2064void HostDeviceFor (Gpu::KernelInfo const& info,
2065 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2066 L1&& f1, L2&& f2, L3&& f3) noexcept
2067{
2068 HostDeviceParallelFor<MT>(info, box1,box2,box3,
2069 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2070}
2071
2072template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2073void HostDeviceFor (Gpu::KernelInfo const& info,
2074 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2075 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2076{
2077 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2078}
2079
2080template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2081void HostDeviceFor (Gpu::KernelInfo const& info,
2082 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2083 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2084{
2085 HostDeviceParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2086}
2087
2088template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2089void HostDeviceFor (Gpu::KernelInfo const& info,
2090 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2091 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2092 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2093{
2095 box1,ncomp1,std::forward<L1>(f1),
2096 box2,ncomp2,std::forward<L2>(f2),
2097 box3,ncomp3,std::forward<L3>(f3));
2098}
2099
2100template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2101void HostDeviceFor (Gpu::KernelInfo const& info,
2102 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2103 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2104 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2105{
2107 box1,ncomp1,std::forward<L1>(f1),
2108 box2,ncomp2,std::forward<L2>(f2),
2109 box3,ncomp3,std::forward<L3>(f3));
2110}
2111
2112template <std::integral T, typename L>
2113void HostDeviceParallelFor (T n, L&& f) noexcept
2114{
2116}
2117
2118template <int MT, std::integral T, typename L>
2119void HostDeviceParallelFor (T n, L&& f) noexcept
2120{
2121 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},n,std::forward<L>(f));
2122}
2123
2124template <typename L, int dim>
2125void HostDeviceParallelFor (BoxND<dim> const& box, L&& f) noexcept
2126{
2128}
2129
2130template <int MT, typename L, int dim>
2131void HostDeviceParallelFor (BoxND<dim> const& box, L&& f) noexcept
2132{
2133 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box,std::forward<L>(f));
2134}
2135
2136template <std::integral T, typename L, int dim>
2137void HostDeviceParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
2138{
2139 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
2140}
2141
2142template <int MT, std::integral T, typename L, int dim>
2143void HostDeviceParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
2144{
2145 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
2146}
2147
2148template <typename L1, typename L2, int dim>
2149void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2150{
2151 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2152}
2153
2154template <int MT, typename L1, typename L2, int dim>
2155void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2156{
2157 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2158}
2159
2160template <typename L1, typename L2, typename L3, int dim>
2161void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2162 L1&& f1, L2&& f2, L3&& f3) noexcept
2163{
2165 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2166}
2167
2168template <int MT, typename L1, typename L2, typename L3, int dim>
2169void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2170 L1&& f1, L2&& f2, L3&& f3) noexcept
2171{
2173 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2174}
2175
2176template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2177void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2178 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2179{
2180 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2181}
2182
2183template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2184void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2185 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2186{
2187 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2188}
2189
2190template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2191void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2192 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2193 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2194{
2196 box1,ncomp1,std::forward<L1>(f1),
2197 box2,ncomp2,std::forward<L2>(f2),
2198 box3,ncomp3,std::forward<L3>(f3));
2199}
2200
2201template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2202void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2203 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2204 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2205{
2207 box1,ncomp1,std::forward<L1>(f1),
2208 box2,ncomp2,std::forward<L2>(f2),
2209 box3,ncomp3,std::forward<L3>(f3));
2210}
2211
2212}
2213
2214#endif
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:84
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:123
#define AMREX_GPU_ERROR_CHECK()
Definition AMReX_GpuError.H:151
#define AMREX_LAUNCH_KERNEL(MT, blocks, threads, sharedMem, stream,...)
Definition AMReX_GpuLaunch.H:37
#define AMREX_LAUNCH_KERNEL_NOBOUND(blocks, threads, sharedMem, stream,...)
Definition AMReX_GpuLaunch.H:39
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:54
__host__ __device__ bool isEmpty() const noexcept
Checks if it is an empty BoxND.
Definition AMReX_Box.H:223
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:385
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:148
static unsigned int maxBlocksPerLaunch() noexcept
Definition AMReX_GpuDevice.H:242
static constexpr int warp_size
Definition AMReX_GpuDevice.H:239
Definition AMReX_GpuKernelInfo.H:8
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:31
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:54
__host__ __device__ range_detail::range_impl< T > Range(T const &b) noexcept
Definition AMReX_GpuRange.H:128
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
Vector< ExecConfig > makeNExecutionConfigs(Long N) noexcept
Definition AMReX_GpuLaunch.H:181
ExecutionConfig makeExecutionConfig(Long N) noexcept
Definition AMReX_GpuLaunch.H:153
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:310
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:732
@ F
Definition AMReX_Order.H:7
void For(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:400
randState_t * getRandState()
Definition AMReX_RandomEngine.H:65
void launch(T const &n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:122
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
void HostDeviceFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:835
curandState_t randState_t
Definition AMReX_RandomEngine.H:58
bool isEmpty(T n) noexcept
Definition AMReX_GpuRange.H:15
IntVectND(const Array< int, dim > &) -> IntVectND< dim >
void single_task(L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1245
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:1157
void LoopConcurrentOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:388
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get the Idx-th element of IntVectND<dim>.
Definition AMReX_IntVect.H:1367
Utility that maps flattened point indices back to IntVectND coordinates.
Definition AMReX_Box.H:2509
UIntT UInt
Definition AMReX_Box.H:2511
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Convert flattened point index icell to its IntVectND coordinate.
Definition AMReX_Box.H:2541
__host__ __device__ UInt numPts() const
Return the number of points covered by the indexed box.
Definition AMReX_Box.H:2577
Definition AMReX_GpuLaunch.H:121
dim3 numThreads
Definition AMReX_GpuLaunch.H:147
Definition AMReX_GpuTypes.H:86
Definition AMReX_TypeTraits.H:102
Definition AMReX_RandomEngine.H:72