3#include <AMReX_Config.H>
36template <
typename T,
typename N,
37 std::enable_if_t<std::is_integral_v<N>,
int> = 0>
38T
Sum (N n, T
const* v, T init_val = 0);
56template <
typename T,
typename N,
typename F,
57 std::enable_if_t<std::is_integral_v<N> &&
58 !std::is_same_v<T*,std::decay_t<F>>,
int> = 0>
59T
Sum (N n,
F const& f, T init_val = 0);
75template <
typename T,
typename N,
76 std::enable_if_t<std::is_integral_v<N>,
int> = 0>
77T
Min (N n, T
const* v, T init_val = std::numeric_limits<T>::max());
95template <
typename T,
typename N,
typename F,
96 std::enable_if_t<std::is_integral_v<N> &&
97 !std::is_same_v<T*,std::decay_t<F>>,
int> = 0>
98T
Min (N n,
F const& f, T init_val = std::numeric_limits<T>::max());
114template <
typename T,
typename N,
115 std::enable_if_t<std::is_integral_v<N>,
int> = 0>
116T
Max (N n, T
const* v, T init_val = std::numeric_limits<T>::lowest());
134template <
typename T,
typename N,
typename F,
135 std::enable_if_t<std::is_integral_v<N> &&
136 !std::is_same_v<T*,std::decay_t<F>>,
int> = 0>
137T
Max (N n,
F const& f, T init_val = std::numeric_limits<T>::lowest());
152template <
typename T,
typename N,
153 std::enable_if_t<std::is_integral_v<N>,
int> = 0>
154std::pair<T,T>
MinMax (N n, T
const* v);
171template <
typename T,
typename N,
typename F,
172 std::enable_if_t<std::is_integral_v<N> &&
173 !std::is_same_v<T*,std::decay_t<F>>,
int> = 0>
174std::pair<T,T>
MinMax (N n,
F const& f);
191template <
typename T,
typename N,
typename P,
192 std::enable_if_t<std::is_integral_v<N>,
int> = 0>
193bool AnyOf (N n, T
const* v, P
const& pred);
208template <
typename P,
int dim>
214namespace Reduce::detail {
218 template <std::
size_t I,
typename T,
typename P>
220 void for_each_parallel (T& d, T
const& s,
Gpu::Handler const& h)
222 P().parallel_update(amrex::get<I>(d), amrex::get<I>(s), h);
225 template <std::size_t I,
typename T,
typename P,
typename P1,
typename... Ps>
227 void for_each_parallel (T& d, T
const& s, Gpu::Handler
const& h)
229 P().parallel_update(amrex::get<I>(d), amrex::get<I>(s), h);
230 for_each_parallel<I+1,T,P1,Ps...>(d, s, h);
233 template <std::
size_t I,
typename T,
typename P>
235 void for_each_parallel (T& d, T
const& s)
237 P().parallel_update(amrex::get<I>(d), amrex::get<I>(s));
240 template <std::size_t I,
typename T,
typename P,
typename P1,
typename... Ps>
242 void for_each_parallel (T& d, T
const& s)
244 P().parallel_update(amrex::get<I>(d), amrex::get<I>(s));
245 for_each_parallel<I+1,T,P1,Ps...>(d, s);
250 template <std::
size_t I,
typename T,
typename P>
252 void for_each_local (T& d, T
const& s)
254 P().local_update(amrex::get<I>(d), amrex::get<I>(s));
257 template <std::size_t I,
typename T,
typename P,
typename P1,
typename... Ps>
259 void for_each_local (T& d, T
const& s)
261 P().local_update(amrex::get<I>(d), amrex::get<I>(s));
262 for_each_local<I+1,T,P1,Ps...>(d, s);
265 template <std::
size_t I,
typename T,
typename P>
267 constexpr void for_each_init (T& t)
269 P().init(amrex::get<I>(t));
272 template <std::size_t I,
typename T,
typename P,
typename P1,
typename... Ps>
274 constexpr void for_each_init (T& t)
276 P().init(amrex::get<I>(t));
277 for_each_init<I+1,T,P1,Ps...>(t);
288 template <
typename T>
292 if (h.threadIdx() == 0) { d += r; }
295 template <
typename T,
int MT=AMREX_GPU_MAX_THREADS>
298 T r = Gpu::blockReduceSum<MT>(s);
299 if (threadIdx.x == 0) { d += r; }
304 template <
typename T>
308 template <
typename T>
309 constexpr void init (T& t)
const noexcept { t = 0; }
317 template <
typename T>
321 if (h.threadIdx() == 0) { d =
amrex::min(d,r); }
324 template <
typename T,
int MT=AMREX_GPU_MAX_THREADS>
327 T r = Gpu::blockReduceMin<MT>(s);
328 if (threadIdx.x == 0) { d =
amrex::min(d,r); }
333 template <
typename T>
337 template <
typename T>
338 constexpr std::enable_if_t<std::numeric_limits<T>::is_specialized>
339 init (T& t)
const noexcept { t = std::numeric_limits<T>::max(); }
341 template <
typename T>
342 constexpr std::enable_if_t<!std::numeric_limits<T>::is_specialized>
343 init (T& t)
const noexcept { t = T::max(); }
351 template <
typename T>
355 if (h.threadIdx() == 0) { d =
amrex::max(d,r); }
358 template <
typename T,
int MT=AMREX_GPU_MAX_THREADS>
361 T r = Gpu::blockReduceMax<MT>(s);
362 if (threadIdx.x == 0) { d =
amrex::max(d,r); }
367 template <
typename T>
371 template <
typename T>
372 constexpr std::enable_if_t<std::numeric_limits<T>::is_specialized>
373 init (T& t)
const noexcept { t = std::numeric_limits<T>::lowest(); }
375 template <
typename T>
376 constexpr std::enable_if_t<!std::numeric_limits<T>::is_specialized>
377 init (T& t)
const noexcept { t = T::lowest(); }
385 template <
typename T>
387 std::enable_if_t<std::is_integral_v<T>>
390 if (h.threadIdx() == 0) { d = d && r; }
393 template <
typename T,
int MT=AMREX_GPU_MAX_THREADS>
395 std::enable_if_t<std::is_integral_v<T>>
397 T r = Gpu::blockReduceLogicalAnd<MT>(s);
398 if (threadIdx.x == 0) { d = d && r; }
403 template <
typename T>
405 std::enable_if_t<std::is_integral_v<T>>
408 template <
typename T>
409 constexpr std::enable_if_t<std::is_integral_v<T>>
410 init (T& t)
const noexcept { t =
true; }
418 template <
typename T>
420 std::enable_if_t<std::is_integral_v<T>>
423 if (h.threadIdx() == 0) { d = d || r; }
426 template <
typename T,
int MT=AMREX_GPU_MAX_THREADS>
428 std::enable_if_t<std::is_integral_v<T>>
430 T r = Gpu::blockReduceLogicalOr<MT>(s);
431 if (threadIdx.x == 0) { d = d || r; }
436 template <
typename T>
438 std::enable_if_t<std::is_integral_v<T>>
441 template <
typename T>
442 constexpr std::enable_if_t<std::is_integral_v<T>>
443 init (T& t)
const noexcept { t =
false; }
446template <
typename... Ps>
class ReduceOps;
451template <
typename... Ts>
457 template <
typename... Ps>
459 : m_max_blocks(
Gpu::
Device::maxBlocksPerLaunch()),
462 * m_max_blocks * sizeof(
Type)))),
463 m_fn_value([&reduce_op,this] () ->
Type { return this->
value(reduce_op); })
465 reduce_op.resetResultReadiness();
466 static_assert(std::is_trivially_copyable<Type>(),
467 "ReduceData::Type must be trivially copyable");
468 static_assert(std::is_trivially_destructible<Type>(),
469 "ReduceData::Type must be trivially destructible");
471 new (m_host_tuple) Type();
477 !m_used_external_stream || m_value_called,
478 "ReduceData used on an external GPU stream must call value() before destruction.");
490 Type r = m_fn_value();
491 m_value_called =
true;
495 template <
typename... Ps>
499 m_value_called =
true;
505 return m_device_tuple+streamIndexChecked(s)*m_max_blocks;
517 m_max_stream_index = std::max(m_max_stream_index,streamIndexChecked(s));
528 if (m_stream_index_zero_set) {
530 "ReduceData cannot be reused across different external GPU streams "
531 "or between an external GPU stream and AMReX stream 0.");
533 m_stream_index_zero = s;
534 m_stream_index_zero_set =
true;
541 int m_max_stream_index = 0;
542 Type* m_host_tuple =
nullptr;
543 Type* m_device_tuple =
nullptr;
544 GpuArray<int,AMREX_GPU_MAX_STREAMS> m_nblocks;
546 bool m_stream_index_zero_set =
false;
547 bool m_used_external_stream =
false;
548 bool m_value_called =
false;
549 std::function<Type()> m_fn_value;
553namespace Reduce::detail {
557 template <
typename F,
int dim>
559 auto call_f_intvect_box (F
const& f, IntVectND<dim> iv, IndexTypeND<dim>)
noexcept ->
560 decltype(amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
562 return amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
565 template <
typename F,
int dim>
567 auto call_f_intvect_box (F
const& f, IntVectND<dim> iv, IndexTypeND<dim> t)
noexcept ->
568 decltype(f(BoxND<dim>(iv, iv, t)))
570 return f(BoxND<dim>(iv, iv, t));
574 template <
typename F,
typename T,
int dim>
576 auto call_f_intvect_n (F
const& f, IntVectND<dim> iv, T n)
noexcept ->
577 decltype(amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n))
579 return amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
584 struct iterate_box {};
585 struct iterate_box_comp {};
587 template <
typename I,
typename F,
typename T,
typename... Ps,
588 std::enable_if_t<std::is_same_v<iterate_box,I>,
int> = 0>
590 void mf_call_f (F
const& f,
int ibox,
int i,
int j,
int k,
int, T& r)
noexcept
592 auto const& pr = f(ibox,i,j,k);
593 Reduce::detail::for_each_local<0, T, Ps...>(r, pr);
596 template <
typename I,
typename F,
typename T,
typename... Ps,
597 std::enable_if_t<std::is_same_v<iterate_box_comp,I>,
int> = 0>
599 void mf_call_f (F
const& f,
int ibox,
int i,
int j,
int k,
int ncomp, T& r)
noexcept
601 for (
int n = 0; n < ncomp; ++n) {
602 auto const& pr = f(ibox,i,j,k,n);
603 Reduce::detail::for_each_local<0, T, Ps...>(r, pr);
610template <
typename... Ps>
618 template <
typename I,
typename MF,
typename D,
typename F>
619 void eval_mf (I, MF
const& mf,
IntVect const& nghost,
int ncomp, D& reduce_data,
F const& f)
621 using ReduceTuple =
typename D::Type;
622 const int nboxes = mf.local_size();
624 auto const& parforinfo = mf.getParForInfo(nghost);
625 auto nblocks_per_box = parforinfo.getNBlocksPerBox(AMREX_GPU_MAX_THREADS);
627 const int nblocks = nblocks_per_box * nboxes;
628 const BoxIndexer* dp_boxes = parforinfo.getBoxes();
630 auto const& stream = Gpu::gpuStream();
631 auto pdst = reduce_data.devicePtr(stream);
632 int nblocks_ec = std::min(nblocks, reduce_data.maxBlocks());
634 int& nblocks_ref = reduce_data.nBlocks(stream);
635 auto old_nblocks =
static_cast<unsigned int>(nblocks_ref);
636 nblocks_ref =
amrex::max(nblocks_ref, nblocks_ec);
637 reduce_data.updateMaxStreamIndex(stream);
641 constexpr std::size_t shared_mem_bytes =
sizeof(
unsigned long long)*Gpu::Device::warp_size;
642 amrex::launch<AMREX_GPU_MAX_THREADS>(nblocks_ec, shared_mem_bytes, stream,
645 Dim1 blockIdx {gh.blockIdx()};
646 Dim1 threadIdx{gh.threadIdx()};
648 amrex::launch_global<AMREX_GPU_MAX_THREADS>
649 <<<nblocks_ec, AMREX_GPU_MAX_THREADS, 0, stream>>>
654 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(r);
655 ReduceTuple& dst =
pdst[blockIdx.x];
656 if (threadIdx.x == 0 && blockIdx.x >= old_nblocks) {
659 for (
int iblock = blockIdx.x; iblock < nblocks; iblock += nblocks_ec) {
660 int ibox = iblock / nblocks_per_box;
661 auto icell = std::uint64_t(iblock-ibox*nblocks_per_box)*AMREX_GPU_MAX_THREADS + threadIdx.x;
664 if (icell < indexer.
numPts()) {
665 auto [i, j, k] = indexer(icell);
666 Reduce::detail::mf_call_f<I,
F, ReduceTuple, Ps...>
667 (f, ibox, i, j, k, ncomp, r);
671 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r, gh);
673 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r);
680 template <
typename I,
int dim,
typename D,
typename F>
681 void eval_box (I,
BoxND<dim> const& box,
int ncomp, D& reduce_data,
F const& f)
683 using ReduceTuple =
typename D::Type;
684 auto const& stream = Gpu::gpuStream();
685 auto dp = reduce_data.devicePtr(stream);
686 int& nblocks = reduce_data.nBlocks(stream);
689 constexpr int nitems_per_thread = 4;
690 Long nblocks_ec = (box.
numPts() + nitems_per_thread*AMREX_GPU_MAX_THREADS-1)
691 / (nitems_per_thread*AMREX_GPU_MAX_THREADS);
692 nblocks_ec = std::min<Long>(nblocks_ec, reduce_data.maxBlocks());
693 reduce_data.updateMaxStreamIndex(stream);
696 constexpr std::size_t shared_mem_bytes =
sizeof(
unsigned long long)*Gpu::Device::warp_size;
697 amrex::launch<AMREX_GPU_MAX_THREADS>(nblocks_ec, shared_mem_bytes, stream,
700 Dim1 blockIdx {gh.blockIdx()};
701 Dim1 threadIdx{gh.threadIdx()};
702 Dim1 gridDim {gh.gridDim()};
704 amrex::launch<AMREX_GPU_MAX_THREADS>(nblocks_ec, 0, stream,
709 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(r);
710 ReduceTuple& dst = *(dp+blockIdx.x);
711 if (threadIdx.x == 0 &&
static_cast<int>(blockIdx.x) >= nblocks) {
714 for (std::uint64_t icell = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x,
715 stride = std::uint64_t(AMREX_GPU_MAX_THREADS)*gridDim.x;
719 auto iv = indexer.
intVect(icell);
721 if constexpr (std::is_same_v<Reduce::detail::iterate_box,I>) {
722 auto pr = Reduce::detail::call_f_intvect_box(f, iv, ixtype);
723 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, pr);
725 for (
int n = 0; n < ncomp; ++n) {
726 auto pr = Reduce::detail::call_f_intvect_n(f, iv, n);
727 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, pr);
732 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r, gh);
734 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r);
737 nblocks = std::max(nblocks,
static_cast<int>(nblocks_ec));
742 template <
typename MF,
typename D,
typename F>
743 std::enable_if_t<IsFabArray<MF>::value
744#ifndef AMREX_USE_CUDA
750 using ReduceTuple =
typename D::Type;
751 const int nboxes = mf.local_size();
754 }
else if (!mf.isFusingCandidate()) {
757 const int li = mfi.LocalIndex();
758 this->eval(b, reduce_data,
761 return f(li, i, j, k);
765 eval_mf(Reduce::detail::iterate_box{},
766 mf, nghost, 0, reduce_data, std::forward<F>(f));
770 template <
typename MF,
typename D,
typename F>
771 std::enable_if_t<IsFabArray<MF>::value
772#ifndef AMREX_USE_CUDA
776 eval (MF
const& mf,
IntVect const& nghost,
int ncomp, D& reduce_data, F&& f)
778 using ReduceTuple =
typename D::Type;
780 const int nboxes = mf.local_size();
784 }
else if (!mf.isFusingCandidate()) {
787 const int li = mfi.LocalIndex();
788 this->eval(b, ncomp, reduce_data,
791 return f(li, i, j, k, n);
795 eval_mf(Reduce::detail::iterate_box_comp{},
796 mf, nghost, ncomp, reduce_data, std::forward<F>(f));
800 template <
typename D,
typename F,
int dim>
803 eval_box(Reduce::detail::iterate_box{}, box, 0, reduce_data, f);
806 template <
typename N,
typename D,
typename F,
int dim,
807 typename M=std::enable_if_t<std::is_integral_v<N>> >
810 eval_box(Reduce::detail::iterate_box_comp{}, box, ncomp, reduce_data, f);
813 template <
typename N,
typename D,
typename F,
814 typename M=std::enable_if_t<std::is_integral_v<N>> >
815 void eval (N n, D & reduce_data, F
const& f)
817 if (n <= 0) {
return; }
818 using ReduceTuple =
typename D::Type;
819 auto const& stream = Gpu::gpuStream();
820 auto dp = reduce_data.devicePtr(stream);
821 int& nblocks = reduce_data.nBlocks(stream);
822 constexpr int nitems_per_thread = 4;
823 int nblocks_ec = (n + nitems_per_thread*AMREX_GPU_MAX_THREADS-1)
824 / (nitems_per_thread*AMREX_GPU_MAX_THREADS);
825 nblocks_ec = std::min(nblocks_ec, reduce_data.maxBlocks());
826 reduce_data.updateMaxStreamIndex(stream);
829 constexpr std::size_t shared_mem_bytes =
sizeof(
unsigned long long)*Gpu::Device::warp_size;
830 amrex::launch<AMREX_GPU_MAX_THREADS>(nblocks_ec, shared_mem_bytes, stream,
833 Dim1 blockIdx {gh.blockIdx()};
834 Dim1 threadIdx{gh.threadIdx()};
835 Dim1 gridDim {gh.gridDim()};
837 amrex::launch<AMREX_GPU_MAX_THREADS>(nblocks_ec, 0, stream,
842 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(r);
843 ReduceTuple& dst = *(dp+blockIdx.x);
844 if (threadIdx.x == 0 &&
static_cast<int>(blockIdx.x) >= nblocks) {
847 for (N i = N(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x,
848 stride = N(AMREX_GPU_MAX_THREADS)*gridDim.x;
853 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r,pr);
856 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r, gh);
858 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r);
864 template <
typename D>
865 typename D::Type
value (D & reduce_data)
867 auto hp = reduce_data.hostPtr();
869 if (m_result_is_ready) {
870 reduce_data.markValueCalled();
874 using ReduceTuple =
typename D::Type;
875 auto const& stream = Gpu::gpuStream();
876 auto dp = reduce_data.devicePtr();
877 auto const& nblocks = reduce_data.nBlocks();
878#if defined(AMREX_USE_SYCL)
879 if (reduce_data.maxStreamIndex() == 0 && nblocks[0] <= 4096) {
880 const int N = nblocks[0];
882 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(*hp);
885 Gpu::dtoh_memcpy_async(tmp.
data(), dp,
sizeof(ReduceTuple)*N);
886 Gpu::streamSynchronize();
887 for (
int i = 1; i < N; ++i) {
888 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(tmp[0], tmp[i]);
895 int maxblocks = reduce_data.maxBlocks();
898 constexpr std::size_t shared_mem_bytes =
sizeof(
unsigned long long)*Gpu::Device::warp_size;
899#ifndef AMREX_NO_SYCL_REDUCE_WORKAROUND
902 auto presult = dtmp.
data();
906 amrex::launch<AMREX_GPU_MAX_THREADS>(1, shared_mem_bytes, stream,
910 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(r);
912 for (
int istream = 0, nstreams = nblocks.size(); istream < nstreams; ++istream) {
913 auto dp_stream = dp+istream*maxblocks;
914 for (
int i = gh.item->get_global_id(0), stride = gh.item->get_global_range(0);
915 i < nblocks[istream]; i += stride) {
916 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, dp_stream[i]);
919 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r, gh);
920 if (gh.threadIdx() == 0) { *presult = dst; }
922#ifndef AMREX_NO_SYCL_REDUCE_WORKAROUND
923 Gpu::dtoh_memcpy_async(hp, dtmp.
data(),
sizeof(ReduceTuple));
926 amrex::launch<AMREX_GPU_MAX_THREADS>(1, 0, stream,
930 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(r);
932 for (
int istream = 0, nstreams = nblocks.size(); istream < nstreams; ++istream) {
933 auto dp_stream = dp+istream*maxblocks;
934 for (
int i = AMREX_GPU_MAX_THREADS*blockIdx.x+threadIdx.x, stride = AMREX_GPU_MAX_THREADS*gridDim.x;
935 i < nblocks[istream]; i += stride) {
936 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, dp_stream[i]);
939 Reduce::detail::for_each_parallel<0, ReduceTuple, Ps...>(dst, r);
940 if (threadIdx.x == 0) { *hp = dst; }
943 Gpu::streamSynchronize();
946 m_result_is_ready =
true;
947 reduce_data.markValueCalled();
953 bool m_result_is_ready =
false;
954 void resetResultReadiness () { m_result_is_ready =
false; }
959template <
typename T,
typename N,
960 std::enable_if_t<std::is_integral_v<N>,
int> FOO>
961T Sum (N n, T
const* v, T init_val)
965 using ReduceTuple =
typename decltype(reduce_data)::Type;
967 ReduceTuple hv = reduce_data.
value(reduce_op);
968 return amrex::get<0>(hv) + init_val;
971template <
typename T,
typename N,
typename F,
972 std::enable_if_t<std::is_integral_v<N> &&
973 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
974T Sum (N n, F
const& f, T init_val)
978 using ReduceTuple =
typename decltype(reduce_data)::Type;
980 ReduceTuple hv = reduce_data.
value(reduce_op);
981 return amrex::get<0>(hv) + init_val;
984template <
typename T,
typename N,
985 std::enable_if_t<std::is_integral_v<N>,
int> FOO>
986T Min (N n, T
const* v, T init_val)
990 using ReduceTuple =
typename decltype(reduce_data)::Type;
992 ReduceTuple hv = reduce_data.
value(reduce_op);
993 return std::min(amrex::get<0>(hv),init_val);
996template <
typename T,
typename N,
typename F,
997 std::enable_if_t<std::is_integral_v<N> &&
998 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
999T Min (N n, F
const& f, T init_val)
1003 using ReduceTuple =
typename decltype(reduce_data)::Type;
1005 ReduceTuple hv = reduce_data.
value(reduce_op);
1006 return std::min(amrex::get<0>(hv),init_val);
1009template <
typename T,
typename N,
1010 std::enable_if_t<std::is_integral_v<N>,
int> FOO>
1011T Max (N n, T
const* v, T init_val)
1015 using ReduceTuple =
typename decltype(reduce_data)::Type;
1017 ReduceTuple hv = reduce_data.
value(reduce_op);
1018 return std::max(amrex::get<0>(hv),init_val);
1021template <
typename T,
typename N,
typename F,
1022 std::enable_if_t<std::is_integral_v<N> &&
1023 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
1024T Max (N n, F
const& f, T init_val)
1028 using ReduceTuple =
typename decltype(reduce_data)::Type;
1030 ReduceTuple hv = reduce_data.
value(reduce_op);
1031 return std::max(amrex::get<0>(hv),init_val);
1034template <
typename T,
typename N,
1035 std::enable_if_t<std::is_integral_v<N>,
int> FOO>
1040 using ReduceTuple =
typename decltype(reduce_data)::Type;
1044 auto hv = reduce_data.
value(reduce_op);
1045 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
1048template <
typename T,
typename N,
typename F,
1049 std::enable_if_t<std::is_integral_v<N> &&
1050 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
1055 using ReduceTuple =
typename decltype(reduce_data)::Type;
1060 auto hv = reduce_data.
value(reduce_op);
1061 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
1064template <
typename T,
typename N,
typename P,
1065 std::enable_if_t<std::is_integral_v<N>,
int> FOO>
1066bool AnyOf (N n, T
const* v, P
const& pred)
1072 ec.numBlocks.x = std::min(ec.numBlocks.x, Gpu::Device::maxBlocksPerLaunch());
1074#ifdef AMREX_USE_SYCL
1075 const int num_ints = std::max(Gpu::Device::warp_size,
int(ec.numThreads.x)/Gpu::Device::warp_size) + 1;
1076 const std::size_t shared_mem_bytes = num_ints*
sizeof(
int);
1077 amrex::launch<AMREX_GPU_MAX_THREADS>(ec.numBlocks.x, shared_mem_bytes, Gpu::gpuStream(),
1079 int* has_any = &(
static_cast<int*
>(gh.sharedMemory())[num_ints-1]);
1080 if (gh.threadIdx() == 0) { *has_any = *dp; }
1086 for (N i = AMREX_GPU_MAX_THREADS*gh.blockIdx()+gh.threadIdx(), stride = AMREX_GPU_MAX_THREADS*gh.gridDim();
1087 i < n && !r; i += stride)
1089 r = pred(v[i]) ? 1 : 0;
1092 r = Gpu::blockReduce<Gpu::Device::warp_size>
1094 if (gh.threadIdx() == 0 && r) { *dp = 1; }
1098 amrex::launch<AMREX_GPU_MAX_THREADS>(ec.numBlocks.x, 0, Gpu::gpuStream(),
1100 __shared__
int has_any;
1101 if (threadIdx.x == 0) { has_any = *dp; }
1107 for (N i = AMREX_GPU_MAX_THREADS*blockIdx.x+threadIdx.x, stride = AMREX_GPU_MAX_THREADS*gridDim.x;
1108 i < n && !r; i += stride)
1110 r = pred(v[i]) ? 1 : 0;
1112 r = Gpu::blockReduce<Gpu::Device::warp_size>
1114 if (threadIdx.x == 0 && r) *dp = 1;
1121template <
typename P,
int dim>
1129 ec.numBlocks.x = std::min(ec.numBlocks.x, Gpu::Device::maxBlocksPerLaunch());
1131#ifdef AMREX_USE_SYCL
1132 const int num_ints = std::max(Gpu::Device::warp_size,
int(ec.numThreads.x)/Gpu::Device::warp_size) + 1;
1133 const std::size_t shared_mem_bytes = num_ints*
sizeof(
int);
1134 amrex::launch<AMREX_GPU_MAX_THREADS>(ec.numBlocks.x, shared_mem_bytes, Gpu::gpuStream(),
1136 int* has_any = &(
static_cast<int*
>(gh.sharedMemory())[num_ints-1]);
1137 if (gh.threadIdx() == 0) { *has_any = *dp; }
1143 for (std::uint64_t icell = std::uint64_t(AMREX_GPU_MAX_THREADS)*gh.blockIdx()+gh.threadIdx(),
1144 stride = std::uint64_t(AMREX_GPU_MAX_THREADS)*gh.gridDim();
1145 icell < indexer.
numPts() && !r;
1148 auto iv = indexer.
intVect(icell);
1149 r = amrex::detail::call_f_intvect(pred, iv) ? 1 : 0;
1151 r = Gpu::blockReduce<Gpu::Device::warp_size>
1153 if (gh.threadIdx() == 0 && r) { *dp = 1; }
1160 __shared__
int has_any;
1161 if (threadIdx.x == 0) { has_any = *dp; }
1167 for (std::uint64_t icell = std::uint64_t(AMREX_GPU_MAX_THREADS)*blockIdx.x+threadIdx.x,
1168 stride = std::uint64_t(AMREX_GPU_MAX_THREADS)*gridDim.x;
1169 icell < indexer.
numPts() && !r;
1172 auto iv = indexer.
intVect(icell);
1173 r = amrex::detail::call_f_intvect(pred, iv) ? 1 : 0;
1175 r = Gpu::blockReduce<Gpu::Device::warp_size>
1177 if (threadIdx.x == 0 && r) *dp = 1;
1188template <
typename... Ts>
1192 using Type = GpuTuple<Ts...>;
1194 template <
typename... Ps>
1195 explicit ReduceData (ReduceOps<Ps...>& reduce_op)
1196 : m_tuple(OpenMP::in_parallel() ? 1 : OpenMP::get_max_threads()),
1197 m_fn_value([&reduce_op,this] () -> Type { return this->value(reduce_op); })
1199 reduce_op.resetResultReadiness();
1200 for (
auto& t : m_tuple) {
1201 Reduce::detail::for_each_init<0, Type, Ps...>(t);
1205 ~ReduceData () =
default;
1206 ReduceData (ReduceData<Ts...>
const&) =
delete;
1207 ReduceData (ReduceData<Ts...> &&) =
delete;
1208 void operator= (ReduceData<Ts...>
const&) =
delete;
1209 void operator= (ReduceData<Ts...> &&) =
delete;
1211 Type value () {
return m_fn_value(); }
1213 template <
typename... Ps>
1214 Type value (ReduceOps<Ps...>& reduce_op)
1216 return reduce_op.value(*
this);
1219 Vector<Type>& reference () {
return m_tuple; }
1221 Type& reference (
int tid)
1223 if (m_tuple.size() == 1) {
1227 return m_tuple[tid];
1232 Vector<Type> m_tuple;
1233 std::function<Type()> m_fn_value;
1236namespace Reduce::detail {
1240 template <
typename F,
int dim>
1242 auto call_f_intvect (F
const& f, IntVectND<dim> iv)
noexcept ->
1243 decltype(amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv))
1245 return amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv);
1250 template <
typename F,
typename T,
int dim>
1252 auto call_f_intvect_n (F
const& f, IntVectND<dim> iv, T n)
noexcept ->
1253 decltype(amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n))
1255 return amrex::detail::call_f_intvect_inner(std::make_index_sequence<dim>(), f, iv, n);
1259template <
typename... Ps>
1266 template <
typename D,
typename F,
int dim>
1268 static auto call_f_box (BoxND<dim>
const& box,
typename D::Type & r, F
const& f)
1269 noexcept -> std::enable_if_t<std::is_same_v<std::decay_t<
decltype(
1270 Reduce::detail::call_f_intvect(f, IntVectND<dim>(0))
1271 )>,
typename D::Type>>
1273 using ReduceTuple =
typename D::Type;
1275 [&] (IntVectND<dim> iv) {
1276 auto pr = Reduce::detail::call_f_intvect(f, iv);
1277 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, pr);
1281 template <
typename D,
typename F,
int dim>
1283 static auto call_f_box (BoxND<dim>
const& box,
typename D::Type & r, F
const& f)
1284 noexcept -> std::enable_if_t<std::is_same_v<std::decay_t<
decltype(f(box))>,
1287 using ReduceTuple =
typename D::Type;
1288 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(r, f(box));
1293 template <
typename MF,
typename D,
typename F>
1294 std::enable_if_t<IsFabArray<MF>::value && IsCallable<F, int, int, int, int>::value>
1295 eval (MF
const& mf, IntVect
const& nghost, D & reduce_data, F
const& f)
1297 using ReduceTuple =
typename D::Type;
1303 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1304 for (MFIter mfi(mf,
true); mfi.isValid(); ++mfi) {
1305 Box const& b = mfi.growntilebox(nghost);
1306 const int li = mfi.LocalIndex();
1309 for (
int k = lo.z; k <= hi.z; ++k) {
1310 for (
int j = lo.y; j <= hi.y; ++j) {
1311 for (
int i = lo.x; i <= hi.x; ++i) {
1312 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k));
1315 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1316 reduce_data.reference(OpenMP::get_thread_num()), rr);
1320 template <
typename MF,
typename D,
typename F>
1321 std::enable_if_t<IsFabArray<MF>::value && IsCallable<F, int, int, int, int, int>::value>
1322 eval (MF
const& mf, IntVect
const& nghost,
int ncomp, D & reduce_data, F
const& f)
1324 using ReduceTuple =
typename D::Type;
1330 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1331 for (MFIter mfi(mf,
true); mfi.isValid(); ++mfi) {
1332 Box const& b = mfi.growntilebox(nghost);
1333 const int li = mfi.LocalIndex();
1336 for (
int n = 0; n < ncomp; ++n) {
1337 for (
int k = lo.z; k <= hi.z; ++k) {
1338 for (
int j = lo.y; j <= hi.y; ++j) {
1339 for (
int i = lo.x; i <= hi.x; ++i) {
1340 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(li,i,j,k,n));
1343 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1344 reduce_data.reference(OpenMP::get_thread_num()), rr);
1348 template <
typename D,
typename F,
int dim>
1349 void eval (BoxND<dim>
const& box, D & reduce_data, F&& f)
1351 using ReduceTuple =
typename D::Type;
1353 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1354 call_f_box<D>(box, rr, std::forward<F>(f));
1355 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1356 reduce_data.reference(OpenMP::get_thread_num()), rr);
1359 template <
typename N,
typename D,
typename F,
int dim,
1360 typename M=std::enable_if_t<std::is_integral_v<N>> >
1361 void eval (BoxND<dim>
const& box, N ncomp, D & reduce_data, F
const& f)
1363 using ReduceTuple =
typename D::Type;
1365 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1367 [&] (IntVectND<dim> iv,
int n) {
1368 auto pr = Reduce::detail::call_f_intvect_n(f, iv, n);
1369 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, pr);
1371 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1372 reduce_data.reference(OpenMP::get_thread_num()), rr);
1375 template <
typename N,
typename D,
typename F,
1376 typename M=std::enable_if_t<std::is_integral_v<N>> >
1377 void eval (N n, D & reduce_data, F
const& f)
1379 using ReduceTuple =
typename D::Type;
1381 Reduce::detail::for_each_init<0, ReduceTuple, Ps...>(rr);
1382 for (N i = 0; i < n; ++i) {
1383 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rr, f(i));
1385 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(
1386 reduce_data.reference(OpenMP::get_thread_num()), rr);
1389 template <
typename D>
1390 typename D::Type value (D & reduce_data)
1392 auto& rrv = reduce_data.reference();
1393 if (! m_result_is_ready) {
1394 using ReduceTuple =
typename D::Type;
1395 if (rrv.size() > 1) {
1396 for (
int i = 1, N = rrv.size(); i < N; ++i) {
1397 Reduce::detail::for_each_local<0, ReduceTuple, Ps...>(rrv[0], rrv[i]);
1400 m_result_is_ready =
true;
1406 template <
typename... T>
friend class ReduceData;
1407 bool m_result_is_ready =
false;
1408 void resetResultReadiness () { m_result_is_ready =
false; }
1413template <
typename T,
typename N,
typename F,
1414 std::enable_if_t<std::is_integral_v<N> &&
1415 !std::is_same_v<T*,std::decay_t<F>>,
int> >
1416T
Sum (N n, F
const& f, T init_val)
1420#pragma omp parallel for reduction(+:r)
1422 for (N i = 0; i < n; ++i) {
1428template <
typename T,
typename N,
1429 std::enable_if_t<std::is_integral_v<N>,
int> >
1430T
Sum (N n, T
const* v, T init_val)
1432 return Sum(n, [=] (N i) -> T {
return v[i]; }, init_val);
1435template <
typename T,
typename N,
typename F,
1436 std::enable_if_t<std::is_integral_v<N> &&
1437 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
1438T
Min (N n, F
const& f, T init_val)
1442#pragma omp parallel for reduction(min:r)
1444 for (N i = 0; i < n; ++i) {
1445 r = std::min(r,f(i));
1450template <
typename T,
typename N,
1451 std::enable_if_t<std::is_integral_v<N>,
int> >
1452T
Min (N n, T
const* v, T init_val)
1454 return Reduce::Min(n, [=] (N i) -> T {
return v[i]; }, init_val);
1457template <
typename T,
typename N,
typename F,
1458 std::enable_if_t<std::is_integral_v<N> &&
1459 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
1460T
Max (N n, F
const& f, T init_val)
1464#pragma omp parallel for reduction(max:r)
1466 for (N i = 0; i < n; ++i) {
1467 r = std::max(r,f(i));
1472template <
typename T,
typename N,
1473 std::enable_if_t<std::is_integral_v<N>,
int> >
1474T
Max (N n, T
const* v, T init_val)
1476 return Reduce::Max(n, [=] (N i) -> T {
return v[i]; }, init_val);
1479template <
typename T,
typename N,
typename F,
1480 std::enable_if_t<std::is_integral_v<N> &&
1481 !std::is_same_v<T*,std::decay_t<F>>,
int> FOO>
1482std::pair<T,T>
MinMax (N n, F
const& f)
1484 T r_min = std::numeric_limits<T>::max();
1485 T r_max = std::numeric_limits<T>::lowest();
1487#pragma omp parallel for reduction(min:r_min) reduction(max:r_max)
1489 for (N i = 0; i < n; ++i) {
1491 r_min = std::min(r_min,tmp);
1492 r_max = std::max(r_max,tmp);
1494 return std::make_pair(r_min,r_max);
1497template <
typename T,
typename N, std::enable_if_t<std::is_
integral_v<N>,
int>>
1498std::pair<T,T>
MinMax (N n, T
const* v)
1500 return Reduce::MinMax<T>(n, [=] (N i) -> T {
return v[i]; });
1503template <
typename T,
typename N,
typename P,
1504 std::enable_if_t<std::is_integral_v<N>,
int> >
1505bool AnyOf (N n, T
const* v, P&& pred)
1507 return std::any_of(v, v+n, std::forward<P>(pred));
1510template <
typename P,
int dim>
1511bool AnyOf (BoxND<dim>
const& box, P
const& pred)
1513 for (
auto iv : box.iterator()) {
1514 if (Reduce::detail::call_f_intvect(pred, iv)) {
return true; }
1527template <
typename... Ts,
typename... Ps>
1529constexpr GpuTuple<Ts...>
1533 Reduce::detail::for_each_init<0,
decltype(r), Ps...>(r);
1541template <
typename... Ts,
typename... Ps>
1543constexpr GpuTuple<Ts...>
1547 Reduce::detail::for_each_init<0,
decltype(r), Ps...>(r);
1552template <
typename Ops,
typename Ts>
1555template <
typename... Ops,
typename... Ts>
1556class ReducerImpl<TypeList<Ops...>, TypeList<Ts...>>
1559 static_assert(
sizeof...(Ops) > 0);
1560 static_assert(
sizeof...(Ts) > 0);
1561 static_assert(
sizeof...(Ops) ==
sizeof...(Ts));
1564 : m_reduce_data(m_reduce_op)
1568 using Result_t = GpuTuple<Ts...>;
1569 ReduceOps<Ops...> m_reduce_op;
1570 ReduceData<Ts...> m_reduce_data;
1638template <
typename Ops,
typename Ts>
1640 :
public ReducerImpl<ToTypeList_t<Ops>, ToTypeList_t<Ts>>
1654 void operator= (
Reducer const&) =
delete;
1655 void operator= (
Reducer &&) =
delete;
1671 template <
typename F,
int dim>
1672 std::enable_if_t<IsCallable<F, int, int, int>::value ||
1676 this->m_reduce_op.eval(box, this->m_reduce_data, std::forward<F>(f));
1694 template <
typename F,
int dim>
1695 std::enable_if_t<IsCallable<F, int, int, int, int>::value ||
1699 this->m_reduce_op.eval(box, ncomp, this->m_reduce_data, std::forward<F>(f));
1721 template <
typename MF,
typename F>
1722 std::enable_if_t<IsFabArray<MF>::value &&
1726 this->m_reduce_op.eval(mf, nghost, this->m_reduce_data, std::forward<F>(f));
1751 template <
typename MF,
typename F>
1752 std::enable_if_t<IsFabArray<MF>::value &&
1756 this->m_reduce_op.eval(mf, nghost, ncomp, this->m_reduce_data, std::forward<F>(f));
1771 template <
typename N,
typename F>
1772 std::enable_if_t<IsCallable<F, N>::value>
1775 this->m_reduce_op.eval(n, this->m_reduce_data, std::forward<F>(f));
1790 return this->m_reduce_data.value(this->m_reduce_op);
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_MAX_STREAMS
Definition AMReX_GpuDevice.H:21
#define AMREX_LAUNCH_KERNEL(MT, blocks, threads, sharedMem, stream,...)
Definition AMReX_GpuLaunch.H:36
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Real * pdst
Definition AMReX_HypreMLABecLap.cpp:1140
virtual void free(void *pt)=0
A pure virtual function for deleting the arena pointed to by pt.
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:49
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:356
__host__ __device__ IndexTypeND< dim > ixType() const noexcept
Return the indexing type.
Definition AMReX_Box.H:135
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
static int streamIndex(gpuStream_t s=gpuStream()) noexcept
Definition AMReX_GpuDevice.cpp:710
static bool usingExternalStream() noexcept
Definition AMReX_GpuDevice.cpp:837
Cell-Based or Node-Based Indices.
Definition AMReX_IndexType.H:36
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:172
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
T * data() noexcept
Definition AMReX_PODVector.H:666
Definition AMReX_Reduce.H:453
~ReduceData()
Definition AMReX_Reduce.H:475
int maxStreamIndex() const
Definition AMReX_Reduce.H:515
Type value()
Definition AMReX_Reduce.H:488
void updateMaxStreamIndex(gpuStream_t const &s)
Definition AMReX_Reduce.H:516
int & nBlocks(gpuStream_t const &s)
Definition AMReX_Reduce.H:511
ReduceData(ReduceOps< Ps... > &reduce_op)
Definition AMReX_Reduce.H:458
void markValueCalled() noexcept
Definition AMReX_Reduce.H:520
Type * devicePtr(gpuStream_t const &s)
Definition AMReX_Reduce.H:504
Type value(ReduceOps< Ps... > &reduce_op)
Definition AMReX_Reduce.H:496
Type * devicePtr()
Definition AMReX_Reduce.H:503
GpuArray< int, 8 > & nBlocks()
Definition AMReX_Reduce.H:510
ReduceData(ReduceData< Ts... > const &)=delete
Type * hostPtr()
Definition AMReX_Reduce.H:508
int maxBlocks() const
Definition AMReX_Reduce.H:513
ReduceData(ReduceData< Ts... > &&)=delete
Definition AMReX_Reduce.H:612
D::Type value(D &reduce_data)
Definition AMReX_Reduce.H:865
void eval(BoxND< dim > const &box, D &reduce_data, F const &f)
Definition AMReX_Reduce.H:801
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:748
void eval(BoxND< dim > const &box, N ncomp, D &reduce_data, F const &f)
Definition AMReX_Reduce.H:808
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, int ncomp, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:776
void eval(N n, D &reduce_data, F const &f)
Definition AMReX_Reduce.H:815
Class for local reductions (e.g., sum, min and max).
Definition AMReX_Reduce.H:1641
std::enable_if_t< IsCallable< F, int, int, int >::value||IsCallable< F, IntVectND< dim > >::value > eval(BoxND< dim > const &box, F &&f)
Reduction over a Box.
Definition AMReX_Reduce.H:1674
std::enable_if_t< IsFabArray< MF >::value &&IsCallable< F, int, int, int, int, int >::value > eval(MF const &mf, IntVect const &nghost, int ncomp, F &&f)
Reduction over a MultiFab-like object.
Definition AMReX_Reduce.H:1754
std::enable_if_t< IsCallable< F, N >::value > eval(N n, F &&f)
Reduction over a 1D index range.
Definition AMReX_Reduce.H:1773
Result_t getResult()
Get the final reduction result.
Definition AMReX_Reduce.H:1788
typename Base::Result_t Result_t
Reduction result type, GpuTuple<U...>, where U... are the types in Ts.
Definition AMReX_Reduce.H:1645
std::enable_if_t< IsFabArray< MF >::value &&IsCallable< F, int, int, int, int >::value > eval(MF const &mf, IntVect const &nghost, F &&f)
Reduction over a MultiFab-like object.
Definition AMReX_Reduce.H:1724
std::enable_if_t< IsCallable< F, int, int, int, int >::value||IsCallable< F, IntVectND< dim >, int >::value > eval(BoxND< dim > const &box, int ncomp, F &&f)
Reduction over a Box plus component index.
Definition AMReX_Reduce.H:1697
amrex_long Long
Definition AMReX_INT.H:30
T Min(N n, T const *v, T init_val=std::numeric_limits< T >::max())
Compute the minimum of an array of values.
Definition AMReX_Reduce.H:986
T Max(N n, T const *v, T init_val=std::numeric_limits< T >::lowest())
Compute the maximum of an array of values.
Definition AMReX_Reduce.H:1011
std::pair< T, T > MinMax(N n, T const *v)
Compute the minimum and maximum of an array of values.
Definition AMReX_Reduce.H:1036
bool AnyOf(N n, T const *v, P const &pred)
Test whether any element in an array satisfies a unary predicate.
Definition AMReX_Reduce.H:1066
T Sum(N n, T const *v, T init_val=0)
Compute the sum of an array of values.
Definition AMReX_Reduce.H:961
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1331
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1317
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition AMReX_Box.H:1280
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:860
Arena * The_Arena()
Definition AMReX_Arena.cpp:820
void Sum(T &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:221
__host__ __device__ AMREX_FORCE_INLINE T Max(T *const m, T const value) noexcept
Definition AMReX_GpuAtomic.H:419
__host__ __device__ AMREX_FORCE_INLINE T Min(T *const m, T const value) noexcept
Definition AMReX_GpuAtomic.H:356
__device__ int blockReduceLogicalOr(int source) noexcept
Definition AMReX_GpuReduce.H:552
__device__ T blockReduceMax(T source) noexcept
Definition AMReX_GpuReduce.H:451
__device__ T blockReduceMin(T source) noexcept
Definition AMReX_GpuReduce.H:396
__device__ int blockReduceLogicalAnd(int source) noexcept
Definition AMReX_GpuReduce.H:504
__device__ T blockReduceSum(T source) noexcept
Definition AMReX_GpuReduce.H:346
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
__host__ __device__ constexpr GpuTuple< Ts... > IdentityTuple(GpuTuple< Ts... >, ReduceOps< Ps... >) noexcept
Return a GpuTuple containing the identity element for each operation in ReduceOps....
Definition AMReX_Reduce.H:1530
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
typename ToTypeList< T >::type ToTypeList_t
Definition AMReX_TypeList.H:233
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:24
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:44
const int[]
Definition AMReX_BLProfiler.cpp:1664
AMREX_ATTRIBUTE_FLATTEN_FOR void For(T n, L const &f) noexcept
Definition AMReX_GpuLaunchFunctsC.H:136
Definition AMReX_Box.H:2152
__host__ __device__ IntVectND< dim > intVect(std::uint64_t icell) const
Definition AMReX_Box.H:2169
__host__ __device__ std::uint64_t numPts() const
Definition AMReX_Box.H:2193
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43
Definition AMReX_Tuple.H:125
Definition AMReX_GpuMemory.H:56
T dataValue() const
Definition AMReX_GpuMemory.H:92
T * dataPtr()
Definition AMReX_GpuMemory.H:90
Definition AMReX_GpuLaunch.H:119
Definition AMReX_GpuTypes.H:86
Definition AMReX_GpuControl.H:127
Definition AMReX_GpuReduce.H:283
Test if a given type T is callable with arguments of type Args...
Definition AMReX_TypeTraits.H:213
Definition AMReX_Functional.H:14
Definition AMReX_Reduce.H:382
constexpr std::enable_if_t< std::is_integral_v< T > > init(T &t) const noexcept
Definition AMReX_Reduce.H:410
__device__ std::enable_if_t< std::is_integral_v< T > > parallel_update(T &d, T s) const noexcept
Definition AMReX_Reduce.H:396
__host__ __device__ std::enable_if_t< std::is_integral_v< T > > local_update(T &d, T s) const noexcept
Definition AMReX_Reduce.H:406
Definition AMReX_Reduce.H:415
constexpr std::enable_if_t< std::is_integral_v< T > > init(T &t) const noexcept
Definition AMReX_Reduce.H:443
__host__ __device__ std::enable_if_t< std::is_integral_v< T > > local_update(T &d, T s) const noexcept
Definition AMReX_Reduce.H:439
__device__ std::enable_if_t< std::is_integral_v< T > > parallel_update(T &d, T s) const noexcept
Definition AMReX_Reduce.H:429
Definition AMReX_Reduce.H:348
constexpr std::enable_if_t< std::numeric_limits< T >::is_specialized > init(T &t) const noexcept
Definition AMReX_Reduce.H:373
constexpr std::enable_if_t<!std::numeric_limits< T >::is_specialized > init(T &t) const noexcept
Definition AMReX_Reduce.H:377
__host__ __device__ void local_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:369
__device__ void parallel_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:360
Definition AMReX_Reduce.H:314
constexpr std::enable_if_t<!std::numeric_limits< T >::is_specialized > init(T &t) const noexcept
Definition AMReX_Reduce.H:343
__device__ void parallel_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:326
__host__ __device__ void local_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:335
constexpr std::enable_if_t< std::numeric_limits< T >::is_specialized > init(T &t) const noexcept
Definition AMReX_Reduce.H:339
Definition AMReX_Reduce.H:284
__device__ void parallel_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:297
__host__ __device__ void local_update(T &d, T const &s) const noexcept
Definition AMReX_Reduce.H:306
constexpr void init(T &t) const noexcept
Definition AMReX_Reduce.H:309
Struct for holding types.
Definition AMReX_TypeList.H:13