1#ifndef __CONTRIBUTION_KERNEL_HPP__
2#define __CONTRIBUTION_KERNEL_HPP__
3#include "Kokkos_Assert.hpp"
4#include "Kokkos_Macros.hpp"
5#include "mc/events.hpp"
6#include <Kokkos_Core.hpp>
7#include <mc/particles_container.hpp>
8#include <mc/traits.hpp>
9#include <simulation/kernels/cycle_reducer.hpp>
10#include <simulation/probe.hpp>
26 TeamPolicy::execution_space::scratch_memory_space>;
63 this->m_particles = std::move(_particles);
67 KOKKOS_INLINE_FUNCTION
void
71 using mem_space = ComputeSpace::memory_space;
72 if constexpr (AutoGenerated::FlagCompileTime::use_probe)
77 const auto _ = this->division_probe.template set<mem_space>(
85 Kokkos::printf(
"[KERNEL] Division Overflow\r\n");
91 KOKKOS_INLINE_FUNCTION
98 static const auto n_c = M::n_c;
100 const std::size_t n_particle =
m_particles.n_particles();
107 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, n_c),
108 [&](
const std::size_t j)
116 && (p0 + upper_bound) <= n_particle);
120 Kokkos::parallel_reduce(
121 Kokkos::TeamThreadRange(team, 0, upper_bound),
122 [&](std::size_t relative_index,
value_type& local_value_reduce)
124 const std::size_t flatten_index = p0 + relative_index;
125 KOKKOS_ASSERT(flatten_index < n_particle);
134 const auto weight =
m_particles.get_weight(flatten_index);
143 for (std::size_t j = 0; j < n_c; ++j)
145 Kokkos::atomic_add(&scratch(j),
146 weight * contribs(flatten_index, j));
151 division(flatten_index, local_value_reduce);
163 Kokkos::single(Kokkos::PerTeam(team),
166 auto access = cs.access();
167 team_value_reduce += value_reduce;
168 for (std::size_t j = 0; j < M::n_c; ++j)
170 access(j, 0) += scratch(j);
175 KOKKOS_INLINE_FUNCTION
184 const std::size_t p0 = team.league_rank() * N;
186 const std::size_t p = team.team_size();
188 KOKKOS_ASSERT(p0 < _ntot)
190 const auto upper_bound = ((p0 + N) >= _ntot) ? _ntot - p0 : N;
192 KOKKOS_ASSERT(upper_bound > 0 && upper_bound <= _ntot);
194 const std::size_t m = (upper_bound + p - 1) / p;
202 Kokkos::parallel_reduce(
203 Kokkos::TeamThreadRange(team, 0, upper_bound),
204 [&](
const std::size_t i,
value_type& local_value_reduce)
206 const std::size_t flatten_index = p0 + i;
207 KOKKOS_ASSERT(flatten_index < _ntot);
211 const auto pos =
m_particles.position(flatten_index);
212 const auto weight =
m_particles.get_weight(flatten_index);
223 division(flatten_index, local_value_reduce);
235 Kokkos::single(Kokkos::PerTeam(team),
236 [&]() { team_value_reduce += value_reduce; });
238 Kokkos::parallel_for(
239 Kokkos::TeamThreadRange(team, 0, p),
240 [&](
const std::size_t tid)
243 for (std::size_t k = 0; k < m; ++k)
245 const std::size_t base = tid + k * p;
246 const std::size_t flat_index = p0 + base;
247 if (base >= upper_bound)
256 KOKKOS_ASSERT(flat_index < _ntot);
258 const double weight =
m_particles.get_weight(flat_index);
259 const auto pos = positions(flat_index);
260 Kokkos::parallel_for(
261 Kokkos::ThreadVectorRange(team, 0, M::n_c),
263 { access(j, pos) += weight * contribs(flat_index, j); });
Main owning object for Monte-Carlo particles.
Definition particles_container.hpp:59
@ Overflow
Definition events.hpp:25
@ NewParticle
Spawn new particle.
Definition events.hpp:21
decltype(Kokkos::Experimental::create_scatter_view( kernelContribution())) ContributionView
Definition alias.hpp:162
@ Division
Definition alias.hpp:127
@ Idle
Definition alias.hpp:126
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:100
Kokkos::View< const double **, Kokkos::LayoutLeft, ComputeSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > > KernelConcentrationType
Definition alias.hpp:165
Probes< AutoGenerated::probe_buffer_size > ProbeAutogeneratedBuffer
Definition probe.hpp:150
Definition contribution_kernel.hpp:15
Definition contribution_kernel.hpp:18
Kokkos::View< float_type *, TeamPolicy::execution_space::scratch_memory_space > ScratchView
Definition contribution_kernel.hpp:24
TeamPolicy::member_type TeamMember
Definition contribution_kernel.hpp:22
M::FloatType d_t
Definition contribution_kernel.hpp:36
KOKKOS_INLINE_FUNCTION void operator()(Tag0D _tag, const TeamMember &team, value_type &team_value_reduce) const
Definition contribution_kernel.hpp:92
KOKKOS_INLINE_FUNCTION void division(const std::size_t idx, value_type &local_reduce) const
Definition contribution_kernel.hpp:67
ContributionFunctor(std::size_t particle_per_team, MC::ContributionView contribution_scatter, MC::ParticlesContainer< M > particles, MC::pool_type rp, MC::KernelConcentrationType _concentrations, MC::EventContainer _event, Simulation::ProbeAutogeneratedBuffer d_probes)
Definition contribution_kernel.hpp:40
Simulation::ProbeAutogeneratedBuffer division_probe
Definition contribution_kernel.hpp:38
MC::ParticlesContainer< M > m_particles
Definition contribution_kernel.hpp:32
Kokkos::TeamPolicy< ComputeSpace > TeamPolicy
Definition contribution_kernel.hpp:21
MC::EventContainer events
Definition contribution_kernel.hpp:37
MC::pool_type random_pool
Definition contribution_kernel.hpp:34
size_t np
Definition contribution_kernel.hpp:55
Simulation::KernelInline::CycleReducerType value_type
Definition contribution_kernel.hpp:27
float float_type
Definition contribution_kernel.hpp:23
MC::KernelConcentrationType concentrations
Definition contribution_kernel.hpp:35
MC::ContributionView m_contribution_scatter
Definition contribution_kernel.hpp:31
void update(MC::ParticlesContainer< M > _particles, double _d_t)
Definition contribution_kernel.hpp:58
std::size_t m_particle_per_team
Definition contribution_kernel.hpp:29
Use to count events that occurs during Monte-Carlo processing cycles.
Definition events.hpp:168
Definition cycle_reducer.hpp:15
std::size_t waiting_allocation_particle
Definition cycle_reducer.hpp:16