11 template <
typename NT,
typename KERNEL,
typename ExecutionSpace>
class IntegratorLat1D
23 if (
grid_size[0] % 2 != 0)
throw std::runtime_error(
"IntegratorLat1D: Grid size must be even");
26 void set_a(
const std::array<ctype, 1>
a) { this->a =
a; }
29 template <
typename... T>
void get(NT &dest,
const T &...t)
const
34 Kokkos::View<NT, typename ExecutionSpace::memory_space> result(Kokkos::view_alloc(space,
"result"));
36 get(space, result, t...);
39 auto result_host = Kokkos::create_mirror_view(result);
40 Kokkos::deep_copy(space, result_host, result);
44 template <
typename OT,
typename... T>
45 requires(!std::is_same_v<OT, NT>)
46 void get(OT &dest,
const T &...t)
const
49 get(space, dest, t...);
52 template <
typename OT,
typename... T>
53 requires(!std::is_same_v<OT, NT>)
54 void get(ExecutionSpace &space, OT &dest,
const T &...t)
const
56 const auto args = std::make_tuple(t...);
63 const auto x0size =
grid_size[0] / q0_mult;
65 Kokkos::parallel_reduce(
67 Kokkos::RangePolicy<ExecutionSpace, Kokkos::IndexType<uint>>(space, 0,
69 KOKKOS_LAMBDA(
const uint idx_x, NT &update) {
70 const ctype q0 = xfac * idx_x;
71 const NT result = std::apply([&](
const auto &...args) {
return KERNEL::kernel(q0, args...); }, args);
72 update += q0_mult * fac * result;
77 template <
typename view_type,
typename Coordinates,
typename... Args>
78 void map(ExecutionSpace &space,
const view_type integral_view,
const Coordinates &coordinates,
const Args &...args)
80 const auto m_args = std::make_tuple(args...);
82 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
83 using TeamType = Kokkos::TeamPolicy<ExecutionSpace>::member_type;
90 const auto x0size =
grid_size[0] / q0_mult;
93 Kokkos::TeamPolicy(space, integral_view.size(), Kokkos::AUTO), KOKKOS_LAMBDA(
const TeamType &team) {
95 const uint k = team.league_rank();
97 auto subview = Kokkos::subview(integral_view, k);
99 const auto idx = coordinates.from_linear_index(k);
100 const auto pos = coordinates.forward(idx);
102 const auto full_args = std::tuple_cat(pos, m_args);
106 const auto constant =
107 std::apply([&](
const auto &...iargs) {
return KERNEL::constant(iargs...); }, full_args);
109 Kokkos::parallel_reduce(
110 Kokkos::TeamThreadRange(team, 0, x0size),
111 [&](
const uint idx_x, NT &update) {
112 const ctype q0 = xfac * idx_x;
114 std::apply([&](
const auto &...iargs) {
return KERNEL::kernel(q0, iargs...); }, full_args);
115 update += q0_mult * fac * result;
121 template <
typename Coordinates,
typename... Args>
122 auto map(NT *dest,
const Coordinates &coordinates,
const Args &...args)
125 ExecutionSpace space;
128 auto dest_view = Kokkos::View<NT *, CPU_memory, Kokkos::MemoryUnmanaged>(dest, coordinates.size());
131 auto dest_device_view = Kokkos::View<NT *, ExecutionSpace>(
132 Kokkos::view_alloc(space,
"MapIntegrators_device_view"), coordinates.size());
135 map(space, dest_device_view, coordinates, args...);
138 auto dest_host_view = Kokkos::create_mirror_view(space, dest_device_view);
139 Kokkos::deep_copy(space, dest_host_view, dest_device_view);
142 Kokkos::deep_copy(space, dest_view, dest_host_view);
144 return std::move(space);
150 std::array<ctype, 1>
a;
Definition integrator_lat_1d.hh:12
void get(ExecutionSpace &space, OT &dest, const T &...t) const
Definition integrator_lat_1d.hh:54
void get(NT &dest, const T &...t) const
Definition integrator_lat_1d.hh:29
ExecutionSpace execution_space
Definition integrator_lat_1d.hh:18
void set_q0_symmetric(bool symmetric)
Definition integrator_lat_1d.hh:27
IntegratorLat1D(const std::array< uint, 1 > grid_size, const std::array< ctype, 1 > a, bool q0_symmetric=false)
Definition integrator_lat_1d.hh:20
auto map(NT *dest, const Coordinates &coordinates, const Args &...args)
Definition integrator_lat_1d.hh:122
bool q0_symmetric
Definition integrator_lat_1d.hh:151
void map(ExecutionSpace &space, const view_type integral_view, const Coordinates &coordinates, const Args &...args)
Definition integrator_lat_1d.hh:78
void set_a(const std::array< ctype, 1 > a)
Definition integrator_lat_1d.hh:26
void get(OT &dest, const T &...t) const
Definition integrator_lat_1d.hh:46
const std::array< uint, 1 > grid_size
Definition integrator_lat_1d.hh:147
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_lat_1d.hh:17
std::array< ctype, 1 > a
Definition integrator_lat_1d.hh:150
typename internal::_ctype< CT >::value ctype
Definition types.hh:134
Definition complex_math.hh:10
unsigned int uint
Definition utils.hh:24
An extension of the Kokkos::Sum reducer that adds a constant value to the result.
Definition kokkos.hh:66