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 const auto ec = Gpu::makeExecutionConfig<MT>(box.numPts());
407 const auto nthreads_per_block = ec.numThreads.x;
408 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
409 auto& q = Gpu::Device::streamQueue();
410 try {
411 if (info.hasReduction()) {
412 q.submit([&] (sycl::handler& h) {
413 sycl::local_accessor<unsigned long long>
414 shared_data(sycl::range<1>(std::max(Gpu::Device::warp_size,
415 MT/Gpu::Device::warp_size)), h);
416 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
417 sycl::range<1>(nthreads_per_block)),
418 [=] (sycl::nd_item<1> item)
419 [[sycl::reqd_work_group_size(MT)]]
420 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
421 {
422 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
423 icell < indexer.numPts(); icell += stride) {
424 auto iv = indexer.intVect(icell);
425 int n_active_threads = amrex::min(indexer.numPts()-icell+std::uint64_t(item.get_local_id(0)),
426 std::uint64_t(item.get_local_range(0)));
427 if constexpr (detail::is_big_kernel<L>()) {
428 detail::call_f_intvect_handler(*pf,
429 iv, Gpu::Handler{&item,
430 shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
431 n_active_threads});
432 } else {
433 detail::call_f_intvect_handler(f,
434 iv, Gpu::Handler{&item,
435 shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
436 n_active_threads});
437 }
438 }
439 });
440 });
441 } else {
442 q.submit([&] (sycl::handler& h) {
443 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
444 sycl::range<1>(nthreads_per_block)),
445 [=] (sycl::nd_item<1> item)
446 [[sycl::reqd_work_group_size(MT)]]
447 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
448 {
449 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
450 icell < indexer.numPts(); icell += stride) {
451 auto iv = indexer.intVect(icell);
452 if constexpr (detail::is_big_kernel<L>()) {
453 detail::call_f_intvect_handler(*pf,iv,Gpu::Handler{&item});
454 } else {
455 detail::call_f_intvect_handler(f,iv,Gpu::Handler{&item});
456 }
457 }
458 });
459 });
460 }
461 } catch (sycl::exception const& ex) {
462 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
463 }
464}
465
466template <int MT, std::integral T, typename L, int dim>
467void ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L const& f)
468{
469 if (amrex::isEmpty(box)) { return; }
470
471 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
472 L const* pf = skdp.template get<0>();
474
475 const BoxIndexerND<dim> indexer(box);
476 const auto ec = Gpu::makeExecutionConfig<MT>(box.numPts());
477 const auto nthreads_per_block = ec.numThreads.x;
478 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
479 auto& q = Gpu::Device::streamQueue();
480 try {
481 if (info.hasReduction()) {
482 q.submit([&] (sycl::handler& h) {
483 sycl::local_accessor<unsigned long long>
484 shared_data(sycl::range<1>(std::max(Gpu::Device::warp_size,
485 MT/Gpu::Device::warp_size)), h);
486 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
487 sycl::range<1>(nthreads_per_block)),
488 [=] (sycl::nd_item<1> item)
489 [[sycl::reqd_work_group_size(MT)]]
490 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
491 {
492 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
493 icell < indexer.numPts(); icell += stride) {
494 auto iv = indexer.intVect(icell);
495 int n_active_threads = amrex::min(indexer.numPts()-icell+std::uint64_t(item.get_local_id(0)),
496 std::uint64_t(item.get_local_range(0)));
497 if constexpr (detail::is_big_kernel<L>()) {
498 detail::call_f_intvect_ncomp_handler(*pf, iv, ncomp,
499 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
500 n_active_threads});
501 } else {
502 detail::call_f_intvect_ncomp_handler(f, iv, ncomp,
503 Gpu::Handler{&item, shared_data.get_multi_ptr<sycl::access::decorated::yes>().get(),
504 n_active_threads});
505 }
506 }
507 });
508 });
509 } else {
510 q.submit([&] (sycl::handler& h) {
511 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
512 sycl::range<1>(nthreads_per_block)),
513 [=] (sycl::nd_item<1> item)
514 [[sycl::reqd_work_group_size(MT)]]
515 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
516 {
517 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
518 icell < indexer.numPts(); icell += stride) {
519 auto iv = indexer.intVect(icell);
520 if constexpr (detail::is_big_kernel<L>()) {
521 detail::call_f_intvect_ncomp_handler(*pf,iv,ncomp,Gpu::Handler{&item});
522 } else {
523 detail::call_f_intvect_ncomp_handler(f,iv,ncomp,Gpu::Handler{&item});
524 }
525 }
526 });
527 });
528 }
529 } catch (sycl::exception const& ex) {
530 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
531 }
532}
533
534template <std::integral T, typename L>
535void ParallelForRNG (T n, L const& f)
536{
537 if (amrex::isEmpty(n)) { return; }
538
539 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
540 L const* pf = skdp.template get<0>();
542
543 const auto ec = Gpu::ExecutionConfig(n);
544 const auto nthreads_per_block = ec.numThreads.x;
545 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
546 auto& q = Gpu::Device::streamQueue();
547 auto& engdescr = *(getRandEngineDescriptor());
548 try {
549 q.submit([&] (sycl::handler& h) {
550 auto engine_acc = engdescr.get_access(h);
551 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
552 sycl::range<1>(nthreads_per_block)),
553 [=] (sycl::nd_item<1> item)
554 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
555 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
556 {
557 auto const tid = item.get_global_id(0);
558 auto engine = engine_acc.load(tid);
559 RandomEngine rand_eng{&engine};
560 for (std::size_t i = tid, stride = item.get_global_range(0); i < std::size_t(n); i += stride) {
561 if constexpr (detail::is_big_kernel<L>()) {
562 (*pf)(T(i),rand_eng);
563 } else {
564 f(T(i),rand_eng);
565 }
566 }
567 engine_acc.store(engine, tid);
568 });
569 });
570 q.wait_and_throw(); // because next launch might be on a different queue
571 } catch (sycl::exception const& ex) {
572 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
573 }
574}
575
576template <typename L, int dim>
577void ParallelForRNG (BoxND<dim> const& box, L const& f)
578{
579 if (amrex::isEmpty(box)) { return; }
580
581 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
582 L const* pf = skdp.template get<0>();
584
585 const BoxIndexerND<dim> indexer(box);
586 const auto ec = Gpu::ExecutionConfig(box.numPts());
587 const auto nthreads_per_block = ec.numThreads.x;
588 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
589 auto& q = Gpu::Device::streamQueue();
590 auto& engdescr = *(getRandEngineDescriptor());
591 try {
592 q.submit([&] (sycl::handler& h) {
593 auto engine_acc = engdescr.get_access(h);
594 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
595 sycl::range<1>(nthreads_per_block)),
596 [=] (sycl::nd_item<1> item)
597 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
598 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
599 {
600 auto const tid = item.get_global_id(0);
601 auto engine = engine_acc.load(tid);
602 RandomEngine rand_eng{&engine};
603 for (std::uint64_t icell = tid, stride = item.get_global_range(0);
604 icell < indexer.numPts(); icell += stride) {
605 auto iv = indexer.intVect(icell);
606 if constexpr (detail::is_big_kernel<L>()) {
607 detail::call_f_intvect_engine(*pf,iv,rand_eng);
608 } else {
609 detail::call_f_intvect_engine(f,iv,rand_eng);
610 }
611 }
612 engine_acc.store(engine, tid);
613 });
614 });
615 q.wait_and_throw(); // because next launch might be on a different queue
616 } catch (sycl::exception const& ex) {
617 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
618 }
619}
620
621template <std::integral T, typename L, int dim>
622void ParallelForRNG (BoxND<dim> const& box, T ncomp, L const& f)
623{
624 if (amrex::isEmpty(box)) { return; }
625
626 detail::SyclKernelDevPtr<L> skdp(f, Gpu::gpuStream());
627 L const* pf = skdp.template get<0>();
629
630 const BoxIndexerND<dim> indexer(box);
631 const auto ec = Gpu::ExecutionConfig(box.numPts());
632 const auto nthreads_per_block = ec.numThreads.x;
633 const auto nthreads_total = std::size_t(nthreads_per_block) * amrex::min(ec.numBlocks.x,Gpu::Device::maxBlocksPerLaunch());
634 auto& q = Gpu::Device::streamQueue();
635 auto& engdescr = *(getRandEngineDescriptor());
636 try {
637 q.submit([&] (sycl::handler& h) {
638 auto engine_acc = engdescr.get_access(h);
639 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
640 sycl::range<1>(nthreads_per_block)),
641 [=] (sycl::nd_item<1> item)
642 [[sycl::reqd_work_group_size(AMREX_GPU_MAX_THREADS)]]
643 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
644 {
645 auto const tid = item.get_global_id(0);
646 auto engine = engine_acc.load(tid);
647 RandomEngine rand_eng{&engine};
648 for (std::uint64_t icell = tid, stride = item.get_global_range(0);
649 icell < indexer.numPts(); icell += stride) {
650 auto iv = indexer.intVect(icell);
651 if constexpr (detail::is_big_kernel<L>()) {
652 detail::call_f_intvect_ncomp_engine(*pf,iv,ncomp,rand_eng);
653 } else {
654 detail::call_f_intvect_ncomp_engine(f,iv,ncomp,rand_eng);
655 }
656 }
657 engine_acc.store(engine, tid);
658 });
659 });
660 q.wait_and_throw(); // because next launch might be on a different queue
661 } catch (sycl::exception const& ex) {
662 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
663 }
664}
665
666template <int MT, typename L1, typename L2, int dim>
667void ParallelFor (Gpu::KernelInfo const& /*info*/, BoxND<dim> const& box1, BoxND<dim> const& box2, L1 const& f1, L2 const& f2)
668{
669 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
670
671 detail::SyclKernelDevPtr<L1,L2> skdp(f1, f2, Gpu::gpuStream());
672 L1 const* pf1 = skdp.template get<0>();
673 L2 const* pf2 = skdp.template get<1>();
674 amrex::ignore_unused(pf1,pf2);
675
676 const BoxIndexerND<dim> indexer1(box1);
677 const BoxIndexerND<dim> indexer2(box2);
678 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(), box2.numPts()));
679 const auto nthreads_per_block = ec.numThreads.x;
680 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
681 auto& q = Gpu::Device::streamQueue();
682 try {
683 q.submit([&] (sycl::handler& h) {
684 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
685 sycl::range<1>(nthreads_per_block)),
686 [=] (sycl::nd_item<1> item)
687 [[sycl::reqd_work_group_size(MT)]]
688 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
689 {
690 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
691 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
692 icell < ncells; icell += stride) {
693 if (icell < indexer1.numPts()) {
694 auto iv = indexer1.intVect(icell);
695 if constexpr (detail::is_big_kernel<L1,L2>()) {
696 detail::call_f_intvect(*pf1,iv);
697 } else {
698 detail::call_f_intvect(f1,iv);
699 }
700 }
701 if (icell < indexer2.numPts()) {
702 auto iv = indexer2.intVect(icell);
703 if constexpr (detail::is_big_kernel<L1,L2>()) {
704 detail::call_f_intvect(*pf2,iv);
705 } else {
706 detail::call_f_intvect(f2,iv);
707 }
708 }
709 }
710 });
711 });
712 } catch (sycl::exception const& ex) {
713 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
714 }
715}
716
717template <int MT, typename L1, typename L2, typename L3, int dim>
718void ParallelFor (Gpu::KernelInfo const& /*info*/,
719 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
720 L1 const& f1, L2 const& f2, L3 const& f3)
721{
722 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
723
724 detail::SyclKernelDevPtr<L1,L2,L3> skdp(f1, f2, f3, Gpu::gpuStream());
725 L1 const* pf1 = skdp.template get<0>();
726 L2 const* pf2 = skdp.template get<1>();
727 L3 const* pf3 = skdp.template get<2>();
728 amrex::ignore_unused(pf1,pf2,pf3);
729
730 const BoxIndexerND<dim> indexer1(box1);
731 const BoxIndexerND<dim> indexer2(box2);
732 const BoxIndexerND<dim> indexer3(box3);
733 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
734 const auto nthreads_per_block = ec.numThreads.x;
735 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
736 auto& q = Gpu::Device::streamQueue();
737 try {
738 q.submit([&] (sycl::handler& h) {
739 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
740 sycl::range<1>(nthreads_per_block)),
741 [=] (sycl::nd_item<1> item)
742 [[sycl::reqd_work_group_size(MT)]]
743 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
744 {
745 auto const ncells = amrex::max(indexer1.numPts(), indexer2.numPts(), indexer3.numPts());
746 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
747 icell < ncells; icell += stride) {
748 if (icell < indexer1.numPts()) {
749 auto iv = indexer1.intVect(icell);
750 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
751 detail::call_f_intvect(*pf1,iv);
752 } else {
753 detail::call_f_intvect(f1,iv);
754 }
755 }
756 if (icell < indexer2.numPts()) {
757 auto iv = indexer2.intVect(icell);
758 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
759 detail::call_f_intvect(*pf2,iv);
760 } else {
761 detail::call_f_intvect(f2,iv);
762 }
763 }
764 if (icell < indexer3.numPts()) {
765 auto iv = indexer3.intVect(icell);
766 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
767 detail::call_f_intvect(*pf3,iv);
768 } else {
769 detail::call_f_intvect(f3,iv);
770 }
771 }
772 }
773 });
774 });
775 } catch (sycl::exception const& ex) {
776 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
777 }
778}
779
780template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
781void ParallelFor (Gpu::KernelInfo const& /*info*/,
782 BoxND<dim> const& box1, T1 ncomp1, L1 const& f1,
783 BoxND<dim> const& box2, T2 ncomp2, L2 const& f2)
784{
785 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
786
787 detail::SyclKernelDevPtr<L1,L2> skdp(f1, f2, Gpu::gpuStream());
788 L1 const* pf1 = skdp.template get<0>();
789 L2 const* pf2 = skdp.template get<1>();
790 amrex::ignore_unused(pf1,pf2);
791
792 const BoxIndexerND<dim> indexer1(box1);
793 const BoxIndexerND<dim> indexer2(box2);
794 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
795 const auto nthreads_per_block = ec.numThreads.x;
796 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
797 auto& q = Gpu::Device::streamQueue();
798 try {
799 q.submit([&] (sycl::handler& h) {
800 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
801 sycl::range<1>(nthreads_per_block)),
802 [=] (sycl::nd_item<1> item)
803 [[sycl::reqd_work_group_size(MT)]]
804 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
805 {
806 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
807 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
808 icell < ncells; icell += stride) {
809 if (icell < indexer1.numPts()) {
810 auto iv = indexer1.intVect(icell);
811 if constexpr (detail::is_big_kernel<L1,L2>()) {
812 detail::call_f_intvect_ncomp(*pf1,iv,ncomp1);
813 } else {
814 detail::call_f_intvect_ncomp(f1,iv,ncomp1);
815 }
816 }
817 if (icell < indexer2.numPts()) {
818 auto iv = indexer2.intVect(icell);
819 if constexpr (detail::is_big_kernel<L1,L2>()) {
820 detail::call_f_intvect_ncomp(*pf2,iv,ncomp2);
821 } else {
822 detail::call_f_intvect_ncomp(f2,iv,ncomp2);
823 }
824 }
825 }
826 });
827 });
828 } catch (sycl::exception const& ex) {
829 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
830 }
831}
832
833template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
834void ParallelFor (Gpu::KernelInfo const& /*info*/,
835 BoxND<dim> const& box1, T1 ncomp1, L1 const& f1,
836 BoxND<dim> const& box2, T2 ncomp2, L2 const& f2,
837 BoxND<dim> const& box3, T3 ncomp3, L3 const& f3)
838{
839 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
840
841 detail::SyclKernelDevPtr<L1,L2,L3> skdp(f1, f2, f3, Gpu::gpuStream());
842 L1 const* pf1 = skdp.template get<0>();
843 L2 const* pf2 = skdp.template get<1>();
844 L3 const* pf3 = skdp.template get<2>();
845 amrex::ignore_unused(pf1,pf2,pf3);
846
847 const BoxIndexerND<dim> indexer1(box1);
848 const BoxIndexerND<dim> indexer2(box2);
849 const BoxIndexerND<dim> indexer3(box3);
850 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
851 const auto nthreads_per_block = ec.numThreads.x;
852 const auto nthreads_total = std::size_t(nthreads_per_block) * ec.numBlocks.x;
853 auto& q = Gpu::Device::streamQueue();
854 try {
855 q.submit([&] (sycl::handler& h) {
856 h.parallel_for(sycl::nd_range<1>(sycl::range<1>(nthreads_total),
857 sycl::range<1>(nthreads_per_block)),
858 [=] (sycl::nd_item<1> item)
859 [[sycl::reqd_work_group_size(MT)]]
860 [[sycl::reqd_sub_group_size(Gpu::Device::warp_size)]]
861 {
862 auto const ncells = amrex::max(indexer1.numPts(), indexer2.numPts(), indexer3.numPts());
863 for (std::uint64_t icell = item.get_global_id(0), stride = item.get_global_range(0);
864 icell < ncells; icell += stride) {
865 if (icell < indexer1.numPts()) {
866 auto iv = indexer1.intVect(icell);
867 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
868 detail::call_f_intvect_ncomp(*pf1,iv,ncomp1);
869 } else {
870 detail::call_f_intvect_ncomp(f1,iv,ncomp1);
871 }
872 }
873 if (icell < indexer2.numPts()) {
874 auto iv = indexer2.intVect(icell);
875 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
876 detail::call_f_intvect_ncomp(*pf2,iv,ncomp2);
877 } else {
878 detail::call_f_intvect_ncomp(f2,iv,ncomp2);
879 }
880 }
881 if (icell < indexer3.numPts()) {
882 auto iv = indexer3.intVect(icell);
883 if constexpr (detail::is_big_kernel<L1,L2,L3>()) {
884 detail::call_f_intvect_ncomp(*pf3,iv,ncomp3);
885 } else {
886 detail::call_f_intvect_ncomp(f3,iv,ncomp3);
887 }
888 }
889 }
890 });
891 });
892 } catch (sycl::exception const& ex) {
893 amrex::Abort(std::string("ParallelFor: ")+ex.what()+"!!!!!");
894 }
895}
896
897#else
898// CUDA or HIP
899
900template <typename L>
901void single_task (gpuStream_t stream, L const& f)
902{
903 AMREX_LAUNCH_KERNEL(Gpu::Device::warp_size, 1, 1, 0, stream, f);
905}
906
907template <int MT, typename L>
908void launch (int nblocks, std::size_t shared_mem_bytes, gpuStream_t stream,
909 L const& f)
910{
911 AMREX_LAUNCH_KERNEL(MT, nblocks, MT, shared_mem_bytes, stream, f);
913}
914
915template <int MT, typename L>
916void launch (int nblocks, gpuStream_t stream, L const& f)
917{
918 AMREX_LAUNCH_KERNEL(MT, nblocks, MT, 0, stream, f);
920}
921
922template<typename L>
923void launch (int nblocks, int nthreads_per_block, std::size_t shared_mem_bytes,
924 gpuStream_t stream, L const& f)
925{
926 AMREX_LAUNCH_KERNEL_NOBOUND(nblocks, nthreads_per_block, shared_mem_bytes, stream, f);
928}
929
930template<typename L>
931void launch (int nblocks, int nthreads_per_block, gpuStream_t stream, L&& f) noexcept
932{
933 launch(nblocks, nthreads_per_block, 0, stream, std::forward<L>(f));
934}
935
936template<int MT, std::integral T, typename L>
937void launch (T const& n, L const& f)
938{
939 static_assert(sizeof(T) >= 2);
940 if (amrex::isEmpty(n)) { return; }
941 const auto& nec = Gpu::makeNExecutionConfigs<MT>(n);
942 for (auto const& ec : nec) {
943 const T start_idx = T(ec.start_idx);
944 const T nleft = n - start_idx;
945 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
946 [=] AMREX_GPU_DEVICE () noexcept {
947 // This will not overflow, even though nblocks*MT might.
948 auto tid = T(MT)*T(blockIdx.x)+T(threadIdx.x);
949 if (tid < nleft) {
950 f(tid+start_idx);
951 }
952 });
953 }
955}
956
957template<int MT, int dim, typename L>
958void launch (BoxND<dim> const& box, L const& f)
959{
960 if (box.isEmpty()) { return; }
961 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
962 const BoxIndexerND<dim> indexer(box);
963 const auto type = box.ixType();
964 for (auto const& ec : nec) {
965 const auto start_idx = std::uint64_t(ec.start_idx);
966 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
967 [=] AMREX_GPU_DEVICE () noexcept {
968 auto icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x + start_idx;
969 if (icell < indexer.numPts()) {
970 auto iv = indexer.intVect(icell);
971 f(BoxND<dim>(iv,iv,type));
972 }
973 });
974 }
976}
977
982template <int MT, std::integral T, typename L>
983requires (MaybeDeviceRunnable<L>::value)
984void
985ParallelFor (Gpu::KernelInfo const&, T n, L const& f)
986{
987 static_assert(sizeof(T) >= 2);
988 if (amrex::isEmpty(n)) { return; }
989 const auto& nec = Gpu::makeNExecutionConfigs<MT>(n);
990 for (auto const& ec : nec) {
991 const T start_idx = T(ec.start_idx);
992 const T nleft = n - start_idx;
993 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
994 [=] AMREX_GPU_DEVICE () noexcept {
995 // This will not overflow, even though nblocks*MT might.
996 auto tid = T(MT)*T(blockIdx.x)+T(threadIdx.x);
997 if (tid < nleft) {
998 detail::call_f_scalar_handler(f, tid+start_idx,
999 Gpu::Handler(amrex::min((std::uint64_t(nleft-tid)+(std::uint64_t)threadIdx.x),
1000 (std::uint64_t)MT)));
1001 }
1002 });
1003 }
1005}
1006
1011template <int MT, typename L, int dim>
1012requires (MaybeDeviceRunnable<L>::value)
1013void
1014ParallelFor (Gpu::KernelInfo const&, BoxND<dim> const& box, L const& f)
1015{
1016 if (amrex::isEmpty(box)) { return; }
1017 const BoxIndexerND<dim> indexer(box);
1018 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
1019 for (auto const& ec : nec) {
1020 const auto start_idx = std::uint64_t(ec.start_idx);
1021 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
1022 [=] AMREX_GPU_DEVICE () noexcept {
1023 auto icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x + start_idx;
1024 if (icell < indexer.numPts()) {
1025 auto iv = indexer.intVect(icell);
1026 detail::call_f_intvect_handler(f, iv,
1027 Gpu::Handler(amrex::min((indexer.numPts()-icell+(std::uint64_t)threadIdx.x),
1028 (std::uint64_t)MT)));
1029 }
1030 });
1031 }
1033}
1034
1039template <int MT, std::integral T, typename L, int dim>
1040requires (MaybeDeviceRunnable<L>::value)
1041void
1042ParallelFor (Gpu::KernelInfo const&, BoxND<dim> const& box, T ncomp, L const& f)
1043{
1044 if (amrex::isEmpty(box)) { return; }
1045 const BoxIndexerND<dim> indexer(box);
1046 const auto& nec = Gpu::makeNExecutionConfigs<MT>(box);
1047 for (auto const& ec : nec) {
1048 const auto start_idx = std::uint64_t(ec.start_idx);
1049 AMREX_LAUNCH_KERNEL(MT, ec.nblocks, MT, 0, Gpu::gpuStream(),
1050 [=] AMREX_GPU_DEVICE () noexcept {
1051 auto icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x + start_idx;
1052 if (icell < indexer.numPts()) {
1053 auto iv = indexer.intVect(icell);
1054 detail::call_f_intvect_ncomp_handler(f, iv, ncomp,
1055 Gpu::Handler(amrex::min((indexer.numPts()-icell+(std::uint64_t)threadIdx.x),
1056 (std::uint64_t)MT)));
1057 }
1058 });
1059 }
1061}
1062
1068template <std::integral T, typename L>
1069requires (MaybeDeviceRunnable<L>::value)
1070void
1071ParallelForRNG (T n, L const& f)
1072{
1073 if (amrex::isEmpty(n)) { return; }
1074 randState_t* rand_state = getRandState();
1075 const auto ec = Gpu::ExecutionConfig(n);
1076 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1078 ec.numThreads, 0, Gpu::gpuStream(),
1079 [=] AMREX_GPU_DEVICE () noexcept {
1080 Long tid = Long(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1081 RandomEngine engine{&(rand_state[tid])};
1082 for (Long i = tid, stride = Long(AMREX_GPU_MAX_THREADS)*gridDim.x; i < Long(n); i += stride) {
1083 f(T(i),engine);
1084 }
1085 });
1086 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1088}
1089
1095template <typename L, int dim>
1096requires (MaybeDeviceRunnable<L>::value)
1097void
1098ParallelForRNG (BoxND<dim> const& box, L const& f)
1099{
1100 if (amrex::isEmpty(box)) { return; }
1101 randState_t* rand_state = getRandState();
1102 const BoxIndexerND<dim> indexer(box);
1103 const auto ec = Gpu::ExecutionConfig(box.numPts());
1104 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1106 ec.numThreads, 0, Gpu::gpuStream(),
1107 [=] AMREX_GPU_DEVICE () noexcept {
1108 auto const tid = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1109 RandomEngine engine{&(rand_state[tid])};
1110 for (std::uint64_t icell = tid, stride = std::uint64_t(AMREX_GPU_MAX_THREADS)*gridDim.x; icell < indexer.numPts(); icell += stride) {
1111 auto iv = indexer.intVect(icell);
1112 detail::call_f_intvect_engine(f, iv, engine);
1113 }
1114 });
1115 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1117}
1118
1124template <std::integral T, typename L, int dim>
1125requires (MaybeDeviceRunnable<L>::value)
1126void
1127ParallelForRNG (BoxND<dim> const& box, T ncomp, L const& f)
1128{
1129 if (amrex::isEmpty(box)) { return; }
1130 randState_t* rand_state = getRandState();
1131 const BoxIndexerND<dim> indexer(box);
1132 const auto ec = Gpu::ExecutionConfig(box.numPts());
1133 AMREX_LAUNCH_KERNEL(AMREX_GPU_MAX_THREADS,
1135 ec.numThreads, 0, Gpu::gpuStream(),
1136 [=] AMREX_GPU_DEVICE () noexcept {
1137 auto const tid = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x;
1138 RandomEngine engine{&(rand_state[tid])};
1139 for (std::uint64_t icell = tid, stride = std::uint64_t(AMREX_GPU_MAX_THREADS)*gridDim.x; icell < indexer.numPts(); icell += stride) {
1140 auto iv = indexer.intVect(icell);
1141 detail::call_f_intvect_ncomp_engine(f, iv, ncomp, engine);
1142 }
1143 });
1144 Gpu::streamSynchronize(); // To avoid multiple streams using RNG
1146}
1147
1152template <int MT, typename L1, typename L2, int dim>
1153requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1154void
1156 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1157{
1158 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
1159 const BoxIndexerND<dim> indexer1(box1);
1160 const BoxIndexerND<dim> indexer2(box2);
1161 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
1162 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1163 [=] AMREX_GPU_DEVICE () noexcept {
1164 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
1165 for (std::uint64_t icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x, stride = std::uint64_t(MT)*gridDim.x;
1166 icell < ncells; icell += stride) {
1167 if (icell < indexer1.numPts()) {
1168 auto iv = indexer1.intVect(icell);
1169 detail::call_f_intvect(f1, iv);
1170 }
1171 if (icell < indexer2.numPts()) {
1172 auto iv = indexer2.intVect(icell);
1173 detail::call_f_intvect(f2, iv);
1174 }
1175 }
1176 });
1178}
1179
1184template <int MT, typename L1, typename L2, typename L3, int dim>
1185requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1186 MaybeDeviceRunnable<L3>::value)
1187void
1189 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1190 L1&& f1, L2&& f2, L3&& f3)
1191{
1192 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
1193 const BoxIndexerND<dim> indexer1(box1);
1194 const BoxIndexerND<dim> indexer2(box2);
1195 const BoxIndexerND<dim> indexer3(box3);
1196 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
1197 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1198 [=] AMREX_GPU_DEVICE () noexcept {
1199 auto const ncells = std::max({indexer1.numPts(), indexer2.numPts(), indexer3.numPts()});
1200 for (std::uint64_t icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x, stride = std::uint64_t(MT)*gridDim.x;
1201 icell < ncells; icell += stride) {
1202 if (icell < indexer1.numPts()) {
1203 auto iv = indexer1.intVect(icell);
1204 detail::call_f_intvect(f1, iv);
1205 }
1206 if (icell < indexer2.numPts()) {
1207 auto iv = indexer2.intVect(icell);
1208 detail::call_f_intvect(f2, iv);
1209 }
1210 if (icell < indexer3.numPts()) {
1211 auto iv = indexer3.intVect(icell);
1212 detail::call_f_intvect(f3, iv);
1213 }
1214 }
1215 });
1217}
1218
1223template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1224requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1225void
1227 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1228 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1229{
1230 if (amrex::isEmpty(box1) && amrex::isEmpty(box2)) { return; }
1231 const BoxIndexerND<dim> indexer1(box1);
1232 const BoxIndexerND<dim> indexer2(box2);
1233 const auto ec = Gpu::makeExecutionConfig<MT>(std::max(box1.numPts(),box2.numPts()));
1234 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1235 [=] AMREX_GPU_DEVICE () noexcept {
1236 auto const ncells = std::max(indexer1.numPts(), indexer2.numPts());
1237 for (std::uint64_t icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x, stride = std::uint64_t(MT)*gridDim.x;
1238 icell < ncells; icell += stride) {
1239 if (icell < indexer1.numPts()) {
1240 auto iv = indexer1.intVect(icell);
1241 detail::call_f_intvect_ncomp(f1, iv, ncomp1);
1242 }
1243 if (icell < indexer2.numPts()) {
1244 auto iv = indexer2.intVect(icell);
1245 detail::call_f_intvect_ncomp(f2, iv, ncomp2);
1246 }
1247 }
1248 });
1250}
1251
1256template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1257requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1258 MaybeDeviceRunnable<L3>::value)
1259void
1261 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1262 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1263 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
1264{
1265 if (amrex::isEmpty(box1) && amrex::isEmpty(box2) && amrex::isEmpty(box3)) { return; }
1266 const BoxIndexerND<dim> indexer1(box1);
1267 const BoxIndexerND<dim> indexer2(box2);
1268 const BoxIndexerND<dim> indexer3(box3);
1269 const auto ec = Gpu::makeExecutionConfig<MT>(std::max({box1.numPts(),box2.numPts(),box3.numPts()}));
1270 AMREX_LAUNCH_KERNEL(MT, ec.numBlocks, ec.numThreads, 0, Gpu::gpuStream(),
1271 [=] AMREX_GPU_DEVICE () noexcept {
1272 auto const ncells = std::max({indexer1.numPts(), indexer2.numPts(), indexer3.numPts()});
1273 for (std::uint64_t icell = std::uint64_t(MT)*blockIdx.x+threadIdx.x, stride = std::uint64_t(MT)*gridDim.x;
1274 icell < ncells; icell += stride) {
1275 if (icell < indexer1.numPts()) {
1276 auto iv = indexer1.intVect(icell);
1277 detail::call_f_intvect_ncomp(f1, iv, ncomp1);
1278 }
1279 if (icell < indexer2.numPts()) {
1280 auto iv = indexer2.intVect(icell);
1281 detail::call_f_intvect_ncomp(f2, iv, ncomp2);
1282 }
1283 if (icell < indexer3.numPts()) {
1284 auto iv = indexer3.intVect(icell);
1285 detail::call_f_intvect_ncomp(f3, iv, ncomp3);
1286 }
1287 }
1288 });
1290}
1291
1292#endif
1293
1294template <typename L>
1295void single_task (L&& f) noexcept
1296{
1297 single_task(Gpu::gpuStream(), std::forward<L>(f));
1298}
1299
1300template<typename T, typename L>
1301void launch (T const& n, L&& f) noexcept
1302{
1303 launch<AMREX_GPU_MAX_THREADS>(n, std::forward<L>(f));
1304}
1305
1310template <std::integral T, typename L>
1311requires (MaybeDeviceRunnable<L>::value)
1312void
1313ParallelFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1314{
1315 ParallelFor<AMREX_GPU_MAX_THREADS>(info, n, std::forward<L>(f));
1316}
1317
1322template <typename L, int dim>
1323requires (MaybeDeviceRunnable<L>::value)
1324void
1325ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1326{
1327 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box, std::forward<L>(f));
1328}
1329
1334template <std::integral T, typename L, int dim>
1335requires (MaybeDeviceRunnable<L>::value)
1336void
1337ParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1338{
1339 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box, ncomp, std::forward<L>(f));
1340}
1341
1346template <typename L1, typename L2, int dim>
1347requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1348void
1350 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1351{
1352 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, box2, std::forward<L1>(f1),
1353 std::forward<L2>(f2));
1354}
1355
1360template <typename L1, typename L2, typename L3, int dim>
1361requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1362 MaybeDeviceRunnable<L3>::value)
1363void
1365 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1366 L1&& f1, L2&& f2, L3&& f3) noexcept
1367{
1368 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, box2, box3, std::forward<L1>(f1),
1369 std::forward<L2>(f2), std::forward<L3>(f3));
1370}
1371
1376template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1377requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value)
1378void
1380 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1381 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1382{
1383 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, ncomp1, std::forward<L1>(f1),
1384 box2, ncomp2, std::forward<L2>(f2));
1385}
1386
1391template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1392requires (MaybeDeviceRunnable<L1>::value && MaybeDeviceRunnable<L2>::value &&
1393 MaybeDeviceRunnable<L3>::value)
1394void
1396 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1397 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1398 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1399{
1400 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box1, ncomp1, std::forward<L1>(f1),
1401 box2, ncomp2, std::forward<L2>(f2),
1402 box3, ncomp3, std::forward<L3>(f3));
1403}
1404
1405template <std::integral T, typename L>
1406void For (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1407{
1408 ParallelFor<AMREX_GPU_MAX_THREADS>(info, n,std::forward<L>(f));
1409}
1410
1411template <int MT, std::integral T, typename L>
1412void For (Gpu::KernelInfo const& info, T n, L&& f) noexcept
1413{
1414 ParallelFor<MT>(info, n,std::forward<L>(f));
1415}
1416
1417template <typename L, int dim>
1418void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1419{
1420 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,std::forward<L>(f));
1421}
1422
1423template <int MT, typename L, int dim>
1424void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
1425{
1426 ParallelFor<MT>(info, box,std::forward<L>(f));
1427}
1428
1429template <std::integral T, typename L, int dim>
1430void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1431{
1432 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box,ncomp,std::forward<L>(f));
1433}
1434
1435template <int MT, std::integral T, typename L, int dim>
1436void For (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
1437{
1438 ParallelFor<MT>(info,box,ncomp,std::forward<L>(f));
1439}
1440
1441template <typename L1, typename L2, int dim>
1442void For (Gpu::KernelInfo const& info,
1443 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1444{
1445 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1446}
1447
1448template <int MT, typename L1, typename L2, int dim>
1449void For (Gpu::KernelInfo const& info,
1450 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1451{
1452 ParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1453}
1454
1455template <typename L1, typename L2, typename L3, int dim>
1456void For (Gpu::KernelInfo const& info,
1457 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1458 L1&& f1, L2&& f2, L3&& f3) noexcept
1459{
1460 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1461}
1462
1463template <int MT, typename L1, typename L2, typename L3, int dim>
1464void For (Gpu::KernelInfo const& info,
1465 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1466 L1&& f1, L2&& f2, L3&& f3) noexcept
1467{
1468 ParallelFor<MT>(info,box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1469}
1470
1471template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1472void For (Gpu::KernelInfo const& info,
1473 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1474 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1475{
1476 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1477}
1478
1479template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1480void For (Gpu::KernelInfo const& info,
1481 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1482 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1483{
1484 ParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1485}
1486
1487template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1488void For (Gpu::KernelInfo const& info,
1489 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1490 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1491 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1492{
1493 ParallelFor<AMREX_GPU_MAX_THREADS>(info,
1494 box1,ncomp1,std::forward<L1>(f1),
1495 box2,ncomp2,std::forward<L2>(f2),
1496 box3,ncomp3,std::forward<L3>(f3));
1497}
1498
1499template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1500void For (Gpu::KernelInfo const& info,
1501 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1502 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1503 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1504{
1505 ParallelFor<MT>(info,
1506 box1,ncomp1,std::forward<L1>(f1),
1507 box2,ncomp2,std::forward<L2>(f2),
1508 box3,ncomp3,std::forward<L3>(f3));
1509}
1510
1515template <std::integral T, typename L>
1516void ParallelFor (T n, L&& f) noexcept
1517{
1518 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1519}
1520
1525template <int MT, std::integral T, typename L>
1526void ParallelFor (T n, L&& f) noexcept
1527{
1528 ParallelFor<MT>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1529}
1530
1535template <typename L, int dim>
1536void ParallelFor (BoxND<dim> const& box, L&& f) noexcept
1537{
1538 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, box, std::forward<L>(f));
1539}
1540
1545template <int MT, typename L, int dim>
1546void ParallelFor (BoxND<dim> const& box, L&& f) noexcept
1547{
1548 ParallelFor<MT>(Gpu::KernelInfo{}, box, std::forward<L>(f));
1549}
1550
1555template <std::integral T, typename L, int dim>
1556void ParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1557{
1558 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1559}
1560
1565template <int MT, std::integral T, typename L, int dim>
1566void ParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1567{
1568 ParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1569}
1570
1575template <typename L1, typename L2, int dim>
1576void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1577{
1578 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1579}
1580
1585template <int MT, typename L1, typename L2, int dim>
1586void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1587{
1588 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1589}
1590
1595template <typename L1, typename L2, typename L3, int dim>
1596void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1597 L1&& f1, L2&& f2, L3&& f3) noexcept
1598{
1599 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1600}
1601
1606template <int MT, typename L1, typename L2, typename L3, int dim>
1607void ParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1608 L1&& f1, L2&& f2, L3&& f3) noexcept
1609{
1610 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1611}
1612
1617template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1618void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1619 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1620{
1621 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1622}
1623
1628template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1629void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1630 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1631{
1632 ParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1633}
1634
1639template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1640void ParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1641 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1642 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1643{
1644 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},
1645 box1,ncomp1,std::forward<L1>(f1),
1646 box2,ncomp2,std::forward<L2>(f2),
1647 box3,ncomp3,std::forward<L3>(f3));
1648}
1649
1654template <int MT, 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{
1659 ParallelFor<MT>(Gpu::KernelInfo{},
1660 box1,ncomp1,std::forward<L1>(f1),
1661 box2,ncomp2,std::forward<L2>(f2),
1662 box3,ncomp3,std::forward<L3>(f3));
1663}
1664
1665template <std::integral T, typename L>
1666void For (T n, L&& f) noexcept
1667{
1668 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, n,std::forward<L>(f));
1669}
1670
1671template <int MT, std::integral T, typename L>
1672void For (T n, L&& f) noexcept
1673{
1674 ParallelFor<MT>(Gpu::KernelInfo{}, n,std::forward<L>(f));
1675}
1676
1677template <typename L, int dim>
1678void For (BoxND<dim> const& box, L&& f) noexcept
1679{
1680 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, box,std::forward<L>(f));
1681}
1682
1683template <int MT, typename L, int dim>
1684void For (BoxND<dim> const& box, L&& f) noexcept
1685{
1686 ParallelFor<MT>(Gpu::KernelInfo{}, box,std::forward<L>(f));
1687}
1688
1689template <std::integral T, typename L, int dim>
1690void For (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1691{
1692 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1693}
1694
1695template <int MT, std::integral T, typename L, int dim>
1696void For (BoxND<dim> const& box, T ncomp, L&& f) noexcept
1697{
1698 ParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
1699}
1700
1701template <typename L1, typename L2, int dim>
1702void For (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1703{
1704 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1705}
1706
1707template <int MT, typename L1, typename L2, int dim>
1708void For (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
1709{
1710 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1711}
1712
1713template <typename L1, typename L2, typename L3, int dim>
1714void For (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1715 L1&& f1, L2&& f2, L3&& f3) noexcept
1716{
1717 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1718}
1719
1720template <int MT, typename L1, typename L2, typename L3, int dim>
1721void For (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1722 L1&& f1, L2&& f2, L3&& f3) noexcept
1723{
1724 ParallelFor<MT>(Gpu::KernelInfo{},box1,box2,box3,std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1725}
1726
1727template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1728void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1729 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1730{
1731 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1732}
1733
1734template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1735void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1736 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
1737{
1738 ParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1739}
1740
1741template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1742void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1743 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1744 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1745{
1746 ParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},
1747 box1,ncomp1,std::forward<L1>(f1),
1748 box2,ncomp2,std::forward<L2>(f2),
1749 box3,ncomp3,std::forward<L3>(f3));
1750}
1751
1752template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1753void For (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1754 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
1755 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
1756{
1757 ParallelFor<MT>(Gpu::KernelInfo{},
1758 box1,ncomp1,std::forward<L1>(f1),
1759 box2,ncomp2,std::forward<L2>(f2),
1760 box3,ncomp3,std::forward<L3>(f3));
1761}
1762
1763template <std::integral T, typename L>
1764requires (MaybeHostDeviceRunnable<L>::value)
1765void
1767{
1768 if (Gpu::inLaunchRegion()) {
1769 ParallelFor<AMREX_GPU_MAX_THREADS>(info,n,std::forward<L>(f));
1770 } else {
1771#ifdef AMREX_USE_SYCL
1772 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1773#else
1775 for (T i = 0; i < n; ++i) { f(i); }
1776#endif
1777 }
1778}
1779
1780template <int MT, std::integral T, typename L>
1781requires (MaybeHostDeviceRunnable<L>::value)
1782void
1784{
1785 if (Gpu::inLaunchRegion()) {
1786 ParallelFor<MT>(info,n,std::forward<L>(f));
1787 } else {
1788#ifdef AMREX_USE_SYCL
1789 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1790#else
1792 for (T i = 0; i < n; ++i) { f(i); }
1793#endif
1794 }
1795}
1796
1797template <std::integral T, typename L>
1798requires (MaybeHostDeviceRunnable<L>::value)
1799void
1800HostDeviceParallelFor (T n, L&& f) noexcept
1801{
1802 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1803}
1804
1805template <int MT, std::integral T, typename L>
1806requires (MaybeHostDeviceRunnable<L>::value)
1807void
1808HostDeviceParallelFor (T n, L&& f) noexcept
1809{
1810 HostDeviceParallelFor<MT>(Gpu::KernelInfo{}, n, std::forward<L>(f));
1811}
1812
1813template <typename L, int dim>
1814requires (MaybeHostDeviceRunnable<L>::value)
1815void
1816HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f)
1817{
1818 if (Gpu::inLaunchRegion()) {
1819 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,std::forward<L>(f));
1820 } else {
1821#ifdef AMREX_USE_SYCL
1822 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1823#else
1824 LoopConcurrentOnCpu(box,std::forward<L>(f));
1825#endif
1826 }
1827}
1828
1829template <int MT, typename L, int dim>
1830requires (MaybeHostDeviceRunnable<L>::value)
1831void
1832HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f)
1833{
1834 if (Gpu::inLaunchRegion()) {
1835 ParallelFor<MT>(info, box,std::forward<L>(f));
1836 } else {
1837#ifdef AMREX_USE_SYCL
1838 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1839#else
1840 LoopConcurrentOnCpu(box,std::forward<L>(f));
1841#endif
1842 }
1843}
1844
1845template <std::integral T, typename L, int dim>
1846requires (MaybeHostDeviceRunnable<L>::value)
1847void
1848HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f)
1849{
1850 if (Gpu::inLaunchRegion()) {
1851 ParallelFor<AMREX_GPU_MAX_THREADS>(info, box,ncomp,std::forward<L>(f));
1852 } else {
1853#ifdef AMREX_USE_SYCL
1854 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1855#else
1856 LoopConcurrentOnCpu(box,ncomp,std::forward<L>(f));
1857#endif
1858 }
1859}
1860
1861template <int MT, std::integral T, typename L, int dim>
1862requires (MaybeHostDeviceRunnable<L>::value)
1863void
1864HostDeviceParallelFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f)
1865{
1866 if (Gpu::inLaunchRegion()) {
1867 ParallelFor<MT>(info, box,ncomp,std::forward<L>(f));
1868 } else {
1869#ifdef AMREX_USE_SYCL
1870 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1871#else
1872 LoopConcurrentOnCpu(box,ncomp,std::forward<L>(f));
1873#endif
1874 }
1875}
1876
1877template <typename L1, typename L2, int dim>
1878requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1879void
1881 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1882{
1883 if (Gpu::inLaunchRegion()) {
1884 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1885 } else {
1886#ifdef AMREX_USE_SYCL
1887 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1888#else
1889 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1890 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1891#endif
1892 }
1893}
1894
1895template <int MT, typename L1, typename L2, int dim>
1896requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1897void
1899 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2)
1900{
1901 if (Gpu::inLaunchRegion()) {
1902 ParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
1903 } else {
1904#ifdef AMREX_USE_SYCL
1905 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1906#else
1907 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1908 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1909#endif
1910 }
1911}
1912
1913template <typename L1, typename L2, typename L3, int dim>
1914requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1915 MaybeHostDeviceRunnable<L3>::value)
1916void
1918 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1919 L1&& f1, L2&& f2, L3&& f3)
1920{
1921 if (Gpu::inLaunchRegion()) {
1922 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,box3,
1923 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1924 } else {
1925#ifdef AMREX_USE_SYCL
1926 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1927#else
1928 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1929 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1930 LoopConcurrentOnCpu(box3,std::forward<L3>(f3));
1931#endif
1932 }
1933}
1934
1935template <int MT, typename L1, typename L2, typename L3, int dim>
1936requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1937 MaybeHostDeviceRunnable<L3>::value)
1938void
1940 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
1941 L1&& f1, L2&& f2, L3&& f3)
1942{
1943 if (Gpu::inLaunchRegion()) {
1944 ParallelFor<MT>(info,box1,box2,box3,
1945 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
1946 } else {
1947#ifdef AMREX_USE_SYCL
1948 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1949#else
1950 LoopConcurrentOnCpu(box1,std::forward<L1>(f1));
1951 LoopConcurrentOnCpu(box2,std::forward<L2>(f2));
1952 LoopConcurrentOnCpu(box3,std::forward<L3>(f3));
1953#endif
1954 }
1955}
1956
1957template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1958requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1959void
1961 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1962 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1963{
1964 if (Gpu::inLaunchRegion()) {
1965 ParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1966 } else {
1967#ifdef AMREX_USE_SYCL
1968 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1969#else
1970 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1971 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
1972#endif
1973 }
1974}
1975
1976template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
1977requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value)
1978void
1980 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
1981 BoxND<dim> const& box2, T2 ncomp2, L2&& f2)
1982{
1983 if (Gpu::inLaunchRegion()) {
1984 ParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
1985 } else {
1986#ifdef AMREX_USE_SYCL
1987 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
1988#else
1989 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
1990 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
1991#endif
1992 }
1993}
1994
1995template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
1996requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
1997 MaybeHostDeviceRunnable<L3>::value)
1998void
2000 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2001 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2002 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
2003{
2004 if (Gpu::inLaunchRegion()) {
2005 ParallelFor<AMREX_GPU_MAX_THREADS>(info,
2006 box1,ncomp1,std::forward<L1>(f1),
2007 box2,ncomp2,std::forward<L2>(f2),
2008 box3,ncomp3,std::forward<L3>(f3));
2009 } else {
2010#ifdef AMREX_USE_SYCL
2011 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
2012#else
2013 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
2014 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
2015 LoopConcurrentOnCpu(box3,ncomp3,std::forward<L3>(f3));
2016#endif
2017 }
2018}
2019
2020template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2021requires (MaybeHostDeviceRunnable<L1>::value && MaybeHostDeviceRunnable<L2>::value &&
2022 MaybeHostDeviceRunnable<L3>::value)
2023void
2025 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2026 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2027 BoxND<dim> const& box3, T3 ncomp3, L3&& f3)
2028{
2029 if (Gpu::inLaunchRegion()) {
2030 ParallelFor<MT>(info,
2031 box1,ncomp1,std::forward<L1>(f1),
2032 box2,ncomp2,std::forward<L2>(f2),
2033 box3,ncomp3,std::forward<L3>(f3));
2034 } else {
2035#ifdef AMREX_USE_SYCL
2036 amrex::Abort("amrex:: HOST_DEVICE disabled for Intel. It takes too long to compile");
2037#else
2038 LoopConcurrentOnCpu(box1,ncomp1,std::forward<L1>(f1));
2039 LoopConcurrentOnCpu(box2,ncomp2,std::forward<L2>(f2));
2040 LoopConcurrentOnCpu(box3,ncomp3,std::forward<L3>(f3));
2041#endif
2042 }
2043}
2044
2045template <std::integral T, typename L>
2046void HostDeviceFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
2047{
2048 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,n,std::forward<L>(f));
2049}
2050
2051template <int MT, std::integral T, typename L>
2052void HostDeviceFor (Gpu::KernelInfo const& info, T n, L&& f) noexcept
2053{
2054 HostDeviceParallelFor<MT>(info,n,std::forward<L>(f));
2055}
2056
2057template <typename L, int dim>
2058void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
2059{
2060 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box,std::forward<L>(f));
2061}
2062
2063template <int MT, typename L, int dim>
2064void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, L&& f) noexcept
2065{
2066 HostDeviceParallelFor<MT>(info,box,std::forward<L>(f));
2067}
2068
2069template <std::integral T, typename L, int dim>
2070void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
2071{
2072 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box,ncomp,std::forward<L>(f));
2073}
2074
2075template <int MT, std::integral T, typename L, int dim>
2076void HostDeviceFor (Gpu::KernelInfo const& info, BoxND<dim> const& box, T ncomp, L&& f) noexcept
2077{
2078 HostDeviceParallelFor<MT>(info,box,ncomp,std::forward<L>(f));
2079}
2080
2081template <typename L1, typename L2, int dim>
2082void HostDeviceFor (Gpu::KernelInfo const& info,
2083 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2084{
2085 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2086}
2087
2088template <int MT, typename L1, typename L2, int dim>
2089void HostDeviceFor (Gpu::KernelInfo const& info,
2090 BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2091{
2092 HostDeviceParallelFor<MT>(info,box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2093}
2094
2095template <typename L1, typename L2, typename L3, int dim>
2096void HostDeviceFor (Gpu::KernelInfo const& info,
2097 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2098 L1&& f1, L2&& f2, L3&& f3) noexcept
2099{
2100 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info, box1,box2,box3,
2101 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2102}
2103
2104template <int MT, typename L1, typename L2, typename L3, int dim>
2105void HostDeviceFor (Gpu::KernelInfo const& info,
2106 BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2107 L1&& f1, L2&& f2, L3&& f3) noexcept
2108{
2109 HostDeviceParallelFor<MT>(info, box1,box2,box3,
2110 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2111}
2112
2113template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2114void HostDeviceFor (Gpu::KernelInfo const& info,
2115 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2116 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2117{
2118 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2119}
2120
2121template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2122void HostDeviceFor (Gpu::KernelInfo const& info,
2123 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2124 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2125{
2126 HostDeviceParallelFor<MT>(info,box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2127}
2128
2129template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2130void HostDeviceFor (Gpu::KernelInfo const& info,
2131 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2132 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2133 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2134{
2135 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(info,
2136 box1,ncomp1,std::forward<L1>(f1),
2137 box2,ncomp2,std::forward<L2>(f2),
2138 box3,ncomp3,std::forward<L3>(f3));
2139}
2140
2141template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2142void HostDeviceFor (Gpu::KernelInfo const& info,
2143 BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2144 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2145 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2146{
2147 HostDeviceParallelFor<MT>(info,
2148 box1,ncomp1,std::forward<L1>(f1),
2149 box2,ncomp2,std::forward<L2>(f2),
2150 box3,ncomp3,std::forward<L3>(f3));
2151}
2152
2153template <std::integral T, typename L>
2154void HostDeviceParallelFor (T n, L&& f) noexcept
2155{
2156 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},n,std::forward<L>(f));
2157}
2158
2159template <int MT, std::integral T, typename L>
2160void HostDeviceParallelFor (T n, L&& f) noexcept
2161{
2162 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},n,std::forward<L>(f));
2163}
2164
2165template <typename L, int dim>
2166void HostDeviceParallelFor (BoxND<dim> const& box, L&& f) noexcept
2167{
2168 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,std::forward<L>(f));
2169}
2170
2171template <int MT, typename L, int dim>
2172void HostDeviceParallelFor (BoxND<dim> const& box, L&& f) noexcept
2173{
2174 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box,std::forward<L>(f));
2175}
2176
2177template <std::integral T, typename L, int dim>
2178void HostDeviceParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
2179{
2180 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
2181}
2182
2183template <int MT, std::integral T, typename L, int dim>
2184void HostDeviceParallelFor (BoxND<dim> const& box, T ncomp, L&& f) noexcept
2185{
2186 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box,ncomp,std::forward<L>(f));
2187}
2188
2189template <typename L1, typename L2, int dim>
2190void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2191{
2192 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2193}
2194
2195template <int MT, typename L1, typename L2, int dim>
2196void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, L1&& f1, L2&& f2) noexcept
2197{
2198 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
2199}
2200
2201template <typename L1, typename L2, typename L3, int dim>
2202void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2203 L1&& f1, L2&& f2, L3&& f3) noexcept
2204{
2205 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{}, box1,box2,box3,
2206 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2207}
2208
2209template <int MT, typename L1, typename L2, typename L3, int dim>
2210void HostDeviceParallelFor (BoxND<dim> const& box1, BoxND<dim> const& box2, BoxND<dim> const& box3,
2211 L1&& f1, L2&& f2, L3&& f3) noexcept
2212{
2213 HostDeviceParallelFor<MT>(Gpu::KernelInfo{}, box1,box2,box3,
2214 std::forward<L1>(f1),std::forward<L2>(f2),std::forward<L3>(f3));
2215}
2216
2217template <std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2218void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2219 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2220{
2221 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2222}
2223
2224template <int MT, std::integral T1, std::integral T2, typename L1, typename L2, int dim>
2225void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2226 BoxND<dim> const& box2, T2 ncomp2, L2&& f2) noexcept
2227{
2228 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},box1,ncomp1,std::forward<L1>(f1),box2,ncomp2,std::forward<L2>(f2));
2229}
2230
2231template <std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2232void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2233 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2234 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2235{
2236 HostDeviceParallelFor<AMREX_GPU_MAX_THREADS>(Gpu::KernelInfo{},
2237 box1,ncomp1,std::forward<L1>(f1),
2238 box2,ncomp2,std::forward<L2>(f2),
2239 box3,ncomp3,std::forward<L3>(f3));
2240}
2241
2242template <int MT, std::integral T1, std::integral T2, std::integral T3, typename L1, typename L2, typename L3, int dim>
2243void HostDeviceParallelFor (BoxND<dim> const& box1, T1 ncomp1, L1&& f1,
2244 BoxND<dim> const& box2, T2 ncomp2, L2&& f2,
2245 BoxND<dim> const& box3, T3 ncomp3, L3&& f3) noexcept
2246{
2247 HostDeviceParallelFor<MT>(Gpu::KernelInfo{},
2248 box1,ncomp1,std::forward<L1>(f1),
2249 box2,ncomp2,std::forward<L2>(f2),
2250 box3,ncomp3,std::forward<L3>(f3));
2251}
2252
2253}
2254
2255#endif
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:85
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#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:239
static constexpr int warp_size
Definition AMReX_GpuDevice.H:236
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:53
__host__ __device__ range_detail::range_impl< T > Range(T const &b) noexcept
Definition AMReX_GpuRange.H:128
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:291
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
void HostDeviceParallelFor(T n, L &&f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:732
void For(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:400
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
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
bool isEmpty(T n) noexcept
Definition AMReX_GpuRange.H:15
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
curandState_t randState_t
Definition AMReX_RandomEngine.H:58
void LoopConcurrentOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:388
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:242
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get I'th element of IntVectND<dim>
Definition AMReX_IntVect.H:1338
Utility that maps flattened point indices back to IntVectND coordinates.
Definition AMReX_Box.H:2494
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Convert flattened point index icell to its IntVectND coordinate.
Definition AMReX_Box.H:2517
__host__ __device__ std::uint64_t numPts() const
Return the number of points covered by the indexed box.
Definition AMReX_Box.H:2552
Definition AMReX_GpuLaunch.H:121
Definition AMReX_GpuTypes.H:88
Definition AMReX_RandomEngine.H:72