11 template <
typename NT,
typename KERNEL,
typename ExecutionSpace>
class IntegratorLat3D
23 if (
grid_size[0] % 2 != 0)
throw std::runtime_error(
"IntegratorLat3D: Grid size must be even");
24 if (
grid_size[1] % 2 != 0)
throw std::runtime_error(
"IntegratorLat3D: Grid size must be even");
27 void set_a(
const std::array<ctype, 2>
a) { this->a =
a; }
30 template <
typename... T>
void get(NT &dest,
const T &...t)
const
35 Kokkos::View<NT, typename ExecutionSpace::memory_space> result(Kokkos::view_alloc(space,
"result"));
37 get(space, result, t...);
40 auto result_host = Kokkos::create_mirror_view(result);
41 Kokkos::deep_copy(space, result_host, result);
45 template <
typename OT,
typename... T>
46 requires(!std::is_same_v<OT, NT>)
47 void get(OT &dest,
const T &...t)
const
50 get(space, dest, t...);
53 template <
typename OT,
typename... T>
54 requires(!std::is_same_v<OT, NT>)
55 void get(ExecutionSpace &space, OT &dest,
const T &...t)
const
57 const auto args = std::make_tuple(t...);
65 const auto x0size =
grid_size[0] / q0_mult;
68 Kokkos::parallel_reduce(
70 Kokkos::MDRangePolicy<ExecutionSpace, Kokkos::Rank<3>>(space, {0, 0, 0}, {x0size, x1size / 2, x1size / 2}),
71 KOKKOS_LAMBDA(
const uint idx_x0,
const uint idx_x1,
const uint idx_x2, NT &update) {
72 const ctype q0 = x0fac * idx_x0;
73 const ctype q1 = x1fac * idx_x1;
74 const ctype q2 = x1fac * idx_x2;
76 std::apply([&](
const auto &...args) {
return KERNEL::kernel(q0, q1, q2, args...); }, args);
77 update += q0_mult * 4 * fac * result;
82 template <
typename view_type,
typename Coordinates,
typename... Args>
83 void map(ExecutionSpace &space,
const view_type integral_view,
const Coordinates &coordinates,
const Args &...args)
85 const auto m_args = std::make_tuple(args...);
87 using TeamPolicy = Kokkos::TeamPolicy<ExecutionSpace>;
88 using TeamType = Kokkos::TeamPolicy<ExecutionSpace>::member_type;
96 const auto x0size =
grid_size[0] / q0_mult;
100 Kokkos::TeamPolicy(space, integral_view.size(), Kokkos::AUTO), KOKKOS_LAMBDA(
const TeamType &team) {
102 const uint k = team.league_rank();
104 auto subview = Kokkos::subview(integral_view, k);
106 const auto idx = coordinates.from_linear_index(k);
107 const auto pos = coordinates.forward(idx);
109 const auto full_args = std::tuple_cat(pos, m_args);
112 Kokkos::parallel_reduce(
113 Kokkos::TeamThreadMDRange(team, x0size, x1size / 2, x1size / 2),
114 [&](
const uint idx_x0,
const uint idx_x1,
const uint idx_x2, NT &update) {
115 const ctype q0 = x0fac * idx_x0;
116 const ctype q1 = x1fac * idx_x1;
117 const ctype q2 = x1fac * idx_x2;
119 std::apply([&](
const auto &...iargs) {
return KERNEL::kernel(q0, q1, q2, iargs...); }, full_args);
120 update += q0_mult * 4 * fac * result;
126 Kokkos::single(Kokkos::PerTeam(team), [=]() {
127 subview() = res + std::apply([&](
const auto &...iargs) {
return KERNEL::constant(iargs...); }, full_args);
132 template <
typename Coordinates,
typename... Args>
133 auto map(NT *dest,
const Coordinates &coordinates,
const Args &...args)
136 ExecutionSpace space;
139 auto dest_view = Kokkos::View<NT *, CPU_memory, Kokkos::MemoryUnmanaged>(dest, coordinates.size());
142 auto dest_device_view = Kokkos::View<NT *, ExecutionSpace>(
143 Kokkos::view_alloc(space,
"MapIntegrators_device_view"), coordinates.size());
146 map(space, dest_device_view, coordinates, args...);
149 auto dest_host_view = Kokkos::create_mirror_view(space, dest_device_view);
150 Kokkos::deep_copy(space, dest_host_view, dest_device_view);
153 Kokkos::deep_copy(space, dest_view, dest_host_view);
155 return std::move(space);
161 std::array<ctype, 2>
a;
Definition integrator_lat_3d.hh:12
std::array< ctype, 2 > a
Definition integrator_lat_3d.hh:161
auto map(NT *dest, const Coordinates &coordinates, const Args &...args)
Definition integrator_lat_3d.hh:133
void set_q0_symmetric(bool symmetric)
Definition integrator_lat_3d.hh:28
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_lat_3d.hh:17
void get(ExecutionSpace &space, OT &dest, const T &...t) const
Definition integrator_lat_3d.hh:55
bool q0_symmetric
Definition integrator_lat_3d.hh:162
void map(ExecutionSpace &space, const view_type integral_view, const Coordinates &coordinates, const Args &...args)
Definition integrator_lat_3d.hh:83
void set_a(const std::array< ctype, 2 > a)
Definition integrator_lat_3d.hh:27
const std::array< uint, 2 > grid_size
Definition integrator_lat_3d.hh:158
IntegratorLat3D(const std::array< uint, 2 > grid_size, const std::array< ctype, 2 > a, bool q0_symmetric=false)
Definition integrator_lat_3d.hh:20
void get(OT &dest, const T &...t) const
Definition integrator_lat_3d.hh:47
void get(NT &dest, const T &...t) const
Definition integrator_lat_3d.hh:30
ExecutionSpace execution_space
Definition integrator_lat_3d.hh:18
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