4 #include <AMReX_Config.H>
17 template <
class... Ts>
18 using Tuple = std::tuple<Ts...>;
25 template <std::
size_t I,
typename T>
28 template <
typename U=T, std::enable_if_t<std::is_default_constructible_v<U>,
int> = 0>
36 template <
typename U, std::enable_if_t<std::is_convertible_v<U&&,T>,
int> = 0>
38 :
m_value(std::forward<U>(a_value))
46 template <std::size_t I,
typename Head,
typename... Tail>
51 template<
typename U=Head, std::enable_if_t<std::is_default_constructible_v<U>,
int> = 0>
60 template <
typename UH,
typename... UT, std::enable_if_t<std::is_convertible_v<UH&&,Head>,
int> = 0>
67 template <std::
size_t I,
typename Head>
72 template<
typename U=Head, std::enable_if_t<std::is_default_constructible_v<U>,
int> = 0>
80 template <
typename U, std::enable_if_t<std::is_convertible_v<U&&,Head>,
int> = 0>
90 template <
typename... Ts>
99 :
detail::gpu_tuple_impl<0, Ts...>(args...)
102 template <
typename... Us, std::enable_if_t<
sizeof...(Us) ==
sizeof...(Ts),
int> = 0>
104 :
detail::gpu_tuple_impl<0, Ts...>(std::forward<Us>(args)...)
107 template <
typename... Us, std::enable_if_t<
sizeof...(Us) ==
sizeof...(Ts),
int> = 0>
112 template <
typename... Us, std::enable_if_t<
sizeof...(Us) ==
sizeof...(Ts),
int> = 0>
122 template <
typename... Ts>
124 :
public std::integral_constant<std::size_t, sizeof...(Ts)> {};
130 template <std::size_t I,
typename Head,
typename... Tail>
134 template <
typename Head,
typename... Tail>
143 template <std::size_t I,
typename... Ts>
153 template <std::size_t I,
typename... Ts>
163 template <std::size_t I,
typename... Ts>
170 return std::move(te).m_value;
175 template <std::size_t I,
typename... Ts>
178 typename GpuTupleElement<I, GpuTuple<Ts...> >::type&
184 template <std::size_t I,
typename... Ts>
187 typename GpuTupleElement<I, GpuTuple<Ts...> >::type
const&
193 template <std::size_t I,
typename... Ts>
196 typename GpuTupleElement<I, GpuTuple<Ts...> >::type &&
203 template <std::
size_t I, std::
size_t N,
typename TP1,
typename TP2>
205 std::enable_if_t<(I<N-1),
void>
208 (amrex::get<I>(a) = amrex::get<I>(std::forward<TP2>(
b)),
209 tuple_copy<I+1,N>(a,std::forward<TP2>(
b)));
212 template <std::
size_t I, std::
size_t N,
typename TP1,
typename TP2>
214 std::enable_if_t<I==N-1,
void>
217 amrex::get<I>(a) = amrex::get<I>(std::forward<TP2>(
b));
221 template <
typename... Ts>
222 template <
typename... Us, std::enable_if_t<
sizeof...(Us) ==
sizeof...(Ts),
int> >
230 template <
typename... Ts>
231 template <
typename... Us, std::enable_if_t<
sizeof...(Us) ==
sizeof...(Ts),
int> >
243 template <
typename T>
struct unwrap<std::reference_wrapper<T> > {
using type = T&; };
244 template <
typename T>
248 template <
typename... Ts>
260 template <
typename... Ts>
266 template <
typename... T1s,
typename... T2s,
typename... TPs>
272 template <
typename R,
typename TP1,
typename TP2, std::size_t... N1, std::size_t... N2>
275 std::index_sequence<N1...>
const& , std::index_sequence<N2...>
const& )
277 return R(amrex::get<N1>(a)..., amrex::get<N2>(
b)...);
283 template <
typename TP>
289 return ReturnType(std::forward<TP>(a));
292 template <
typename TP1,
typename TP2>
300 return detail::make_tuple<ReturnType>
301 (std::forward<TP1>(a), std::forward<TP2>(
b),
302 std::make_index_sequence<
GpuTupleSize<std::decay_t<TP1>>::value>(),
303 std::make_index_sequence<
GpuTupleSize<std::decay_t<TP2>>::value>());
306 template <
typename TP1,
typename TP2,
typename... TPs>
315 std::forward<TPs>(args)...);
322 template<std::size_t...Is>
324 template<std::
size_t J>
326 static constexpr std::size_t
get () noexcept {
327 std::size_t arr[
sizeof...(Is)] = {Is...};
331 template<std::
size_t J>
334 std::size_t arr[
sizeof...(Is)] = {Is...};
336 for (std::size_t k=0; k<J; ++k) {
343 template <std::size_t start,
typename... Args, std::size_t... Is>
348 return makeTuple(amrex::get<start+Is>(tup)...);
351 template <
typename... Args, std::size_t... Is,
typename SIL>
357 GetSubTuple<(SIL::template get_exclusive_sum<Is>())>(
359 std::make_index_sequence<SIL::template get<Is>()>()
369 template <std::size_t... Is,
typename... Args>
374 static_assert((0 + ... + Is) ==
sizeof...(Args),
"Incorrect total size in TupleSplit");
377 std::make_index_sequence<
sizeof...(Is)>(),
386 template <
typename F,
typename... Args>
388 auto INVOKE (F&&
f, Args&&... args) -> decltype(
f(std::forward<Args>(args)...));
392 template <
typename F,
typename... Args>
396 using type = decltype(
INVOKE(std::declval<F>(), std::declval<Args>()...));
401 template <
typename F,
typename... Ts>
407 template <
typename F,
typename TP, std::size_t... N>
413 return std::forward<F>(
f)(amrex::get<N>(std::forward<TP>(t))...);
417 template <
typename F,
typename TP>
423 std::make_index_sequence<
GpuTupleSize<std::decay_t<TP>>::value>());
428 template <
typename... Args>
430 constexpr GpuTuple<Args&...>
431 Tie (Args&... args) noexcept
438 template <
typename... Ts>
440 constexpr GpuTuple<Ts&&...>
443 return GpuTuple<Ts&&...>(std::forward<Ts>(args)...);
452 template <
typename... Ts>
454 constexpr GpuTuple<Ts...>
457 return GpuTuple<Ts...>(
static_cast<Ts
>(0)...);
461 template <
typename T, std::size_t... I>
468 template <
typename T>
476 template <
typename T,
typename T2,
typename... Ts, std::enable_if_t<Same<T,T2,Ts...>::value,
int> = 0>
486 template<
typename... Ts>
487 struct std::tuple_size<
amrex::GpuTuple<Ts...>> {
488 static constexpr std::size_t value =
sizeof...(Ts);
492 template<
typename T,
typename... Ts>
497 template<std::size_t s,
typename T,
typename... Ts>
498 struct std::tuple_element<s,
amrex::GpuTuple<T, Ts...>> {
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_Tuple.H:93
constexpr GpuTuple(Us &&... args)
Definition: AMReX_Tuple.H:103
constexpr GpuTuple(Ts const &... args)
Definition: AMReX_Tuple.H:98
AMREX_GPU_HOST_DEVICE GpuTuple< Ts... > & operator=(GpuTuple< Us... > const &rhs)
Definition: AMReX_Tuple.H:224
constexpr AMREX_GPU_HOST_DEVICE GpuTuple()=default
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
@ sum
Definition: AMReX_ParallelReduce.H:19
constexpr AMREX_GPU_HOST_DEVICE R make_tuple(TP1 const &a, TP2 const &b, std::index_sequence< N1... > const &, std::index_sequence< N2... > const &)
Definition: AMReX_Tuple.H:274
constexpr AMREX_GPU_HOST_DEVICE auto GetSubTuple(const GpuTuple< Args... > &tup, std::index_sequence< Is... >) noexcept
Definition: AMReX_Tuple.H:346
constexpr AMREX_GPU_HOST_DEVICE auto TupleSplitImp(const GpuTuple< Args... > &tup, std::index_sequence< Is... >, SIL) noexcept
Definition: AMReX_Tuple.H:354
AMREX_GPU_HOST_DEVICE std::enable_if_t<(I< N-1), void > tuple_copy(TP1 &a, TP2 &&b)
Definition: AMReX_Tuple.H:206
constexpr AMREX_GPU_HOST_DEVICE auto tuple_to_array_helper(T const &tup, std::index_sequence< I... >)
Definition: AMReX_Tuple.H:463
constexpr AMREX_GPU_HOST_DEVICE GpuTupleElement< I, GpuTuple< Ts... > >::type & get_impl(detail::gpu_tuple_element< I, typename GpuTupleElement< I, GpuTuple< Ts... > >::type > &te) noexcept
Definition: AMReX_Tuple.H:147
constexpr AMREX_GPU_HOST_DEVICE auto apply_impl(F &&f, TP &&t, std::index_sequence< N... >) -> typename detail::apply_result< F, detail::tuple_decay_t< TP > >::type
Definition: AMReX_Tuple.H:410
typename unwrap< std::decay_t< T > >::type tuple_decay_t
Definition: AMReX_Tuple.H:245
AMREX_GPU_HOST_DEVICE auto INVOKE(F &&f, Args &&... args) -> decltype(f(std::forward< Args >(args)...))
Definition: AMReX_Amr.cpp:49
std::tuple< Ts... > Tuple
Definition: AMReX_Tuple.H:18
constexpr AMREX_GPU_HOST_DEVICE auto tupleToArray(GpuTuple< T > const &tup)
Definition: AMReX_Tuple.H:470
constexpr AMREX_GPU_HOST_DEVICE GpuTuple< Args &... > Tie(Args &... args) noexcept
Definition: AMReX_Tuple.H:431
constexpr AMREX_GPU_HOST_DEVICE GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition: AMReX_Tuple.H:252
constexpr AMREX_GPU_HOST_DEVICE GpuTupleElement< I, GpuTuple< Ts... > >::type & get(GpuTuple< Ts... > &tup) noexcept
Definition: AMReX_Tuple.H:179
constexpr AMREX_GPU_HOST_DEVICE auto TupleSplit(const GpuTuple< Args... > &tup) noexcept
Returns a GpuTuple of GpuTuples obtained by splitting the input GpuTuple according to the sizes speci...
Definition: AMReX_Tuple.H:372
constexpr AMREX_GPU_HOST_DEVICE auto Apply(F &&f, TP &&t) -> typename detail::apply_result< F, detail::tuple_decay_t< TP > >::type
Definition: AMReX_Tuple.H:420
constexpr AMREX_GPU_HOST_DEVICE GpuTuple< Ts... > MakeZeroTuple(GpuTuple< Ts... >) noexcept
Return a GpuTuple containing all zeros. Note that a default-constructed GpuTuple can have uninitializ...
Definition: AMReX_Tuple.H:455
constexpr AMREX_GPU_HOST_DEVICE GpuTuple< Ts &&... > ForwardAsTuple(Ts &&... args) noexcept
Definition: AMReX_Tuple.H:441
constexpr AMREX_GPU_HOST_DEVICE auto TupleCat(TP &&a) -> typename detail::tuple_cat_result< detail::tuple_decay_t< TP > >::type
Definition: AMReX_Tuple.H:286
Definition: AMReX_FabArrayCommI.H:841
Definition: AMReX_Array.H:34
Head type
Definition: AMReX_Tuple.H:136
Definition: AMReX_Tuple.H:128
Definition: AMReX_Tuple.H:120
Definition: AMReX_Tuple.H:323
static constexpr AMREX_GPU_HOST_DEVICE std::size_t get_exclusive_sum() noexcept
Definition: AMReX_Tuple.H:333
static constexpr AMREX_GPU_HOST_DEVICE std::size_t get() noexcept
Definition: AMReX_Tuple.H:326
typename invoke_result< void, F, Ts... >::type type
Definition: AMReX_Tuple.H:404
Definition: AMReX_Tuple.H:399
Definition: AMReX_Tuple.H:27
constexpr gpu_tuple_element(U &&a_value)
Definition: AMReX_Tuple.H:37
constexpr AMREX_GPU_HOST_DEVICE gpu_tuple_element()
Definition: AMReX_Tuple.H:30
T m_value
Definition: AMReX_Tuple.H:41
constexpr gpu_tuple_element(T const &a_value)
Definition: AMReX_Tuple.H:32
constexpr gpu_tuple_impl(Head const &a_head, Tail const &... a_tail)
Definition: AMReX_Tuple.H:55
constexpr AMREX_GPU_HOST_DEVICE gpu_tuple_impl()
Definition: AMReX_Tuple.H:53
constexpr gpu_tuple_impl(UH &&a_head, UT &&... a_tail)
Definition: AMReX_Tuple.H:61
constexpr gpu_tuple_impl(Head const &a_head)
Definition: AMReX_Tuple.H:76
constexpr gpu_tuple_impl(U &&a_head)
Definition: AMReX_Tuple.H:81
constexpr AMREX_GPU_HOST_DEVICE gpu_tuple_impl()
Definition: AMReX_Tuple.H:74
Definition: AMReX_Tuple.H:44
decltype(INVOKE(std::declval< F >(), std::declval< Args >()...)) type
Definition: AMReX_Tuple.H:396
Definition: AMReX_Tuple.H:390
typename tuple_cat_result< GpuTuple< T1s..., T2s... >, TPs... >::type type
Definition: AMReX_Tuple.H:269
Definition: AMReX_Tuple.H:258
T & type
Definition: AMReX_Tuple.H:243
Definition: AMReX_Tuple.H:242
T type
Definition: AMReX_Tuple.H:242
typename std::tuple_element< s-1, amrex::GpuTuple< Ts... > >::type type
Definition: AMReX_Tuple.H:499
T type
Definition: AMReX_Tuple.H:494