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>
25 TeamPolicy::execution_space::scratch_memory_space>;
61 KOKKOS_INLINE_FUNCTION
void
62 division(
const std::size_t idx)
const
65 using mem_space = ComputeSpace::memory_space;
66 if constexpr (AutoGenerated::FlagCompileTime::use_probe)
71 const auto _ = this->probes.template set<mem_space>(
79 Kokkos::printf(
"[KERNEL] Division Overflow\r\n");
85 KOKKOS_INLINE_FUNCTION
91 const std::size_t n_particle =
m_particles.n_particles();
94 static const auto n_c = M::n_c;
98 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, n_c),
99 [&](
const std::size_t j)
107 && (p0 + upper_bound) <= n_particle);
109 Kokkos::parallel_for(
110 Kokkos::TeamThreadRange(team, 0, upper_bound),
111 [&](std::size_t relative_index)
113 const std::size_t flatten_index = p0 + relative_index;
114 KOKKOS_ASSERT(flatten_index < upper_bound);
119 const auto pos =
m_particles.position(flatten_index);
120 const auto weight =
m_particles.get_weight(flatten_index);
129 for (std::size_t j = 0; j < n_c; ++j)
131 Kokkos::atomic_add(&scratch(j),
132 weight * contribs(flatten_index, j));
148 Kokkos::single(Kokkos::PerTeam(team),
151 auto access = cs.access();
152 for (std::size_t j = 0; j < M::n_c; ++j)
154 access(j, 0) += scratch(j);
159 KOKKOS_INLINE_FUNCTION
166 const std::size_t p0 = team.league_rank() * N;
169 KOKKOS_ASSERT(p0 < _ntot)
170 const auto upper_bound = ((p0 + N) >= _ntot) ? _ntot - p0 : N;
172 KOKKOS_ASSERT(upper_bound > 0 && upper_bound <= _ntot);
174 const std::size_t p = team.team_size();
176 const std::size_t m = (upper_bound + p - 1) / p;
182 Kokkos::parallel_for(
183 Kokkos::TeamThreadRange(team, 0, upper_bound),
184 [&](
const std::size_t i)
186 const std::size_t flatten_index = p0 + i;
187 KOKKOS_ASSERT(flatten_index < upper_bound);
191 const auto pos =
m_particles.position(flatten_index);
192 const auto weight =
m_particles.get_weight(flatten_index);
214 Kokkos::parallel_for(
215 Kokkos::TeamThreadRange(team, 0, p),
216 [&](
const std::size_t tid)
219 for (std::size_t k = 0; k < m; ++k)
221 const std::size_t idx = tid + k * p;
222 const std::size_t flat_index = p0 + idx;
223 if (idx >= upper_bound)
228 KOKKOS_ASSERT(flat_index < _ntot);
231 const auto pos = positions(p);
232 Kokkos::parallel_for(
233 Kokkos::ThreadVectorRange(team, 0, M::n_c),
235 { access(j, pos) += weight * contribs(p, j); });
Main owning object for Monte-Carlo particles.
Definition particles_container.hpp:57
@ NewParticle
Spawn new particle.
Definition events.hpp:20
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
Definition contribution_kernel.hpp:14
Definition contribution_kernel.hpp:17
Kokkos::View< float_type *, TeamPolicy::execution_space::scratch_memory_space > ScratchView
Definition contribution_kernel.hpp:23
TeamPolicy::member_type TeamMember
Definition contribution_kernel.hpp:21
KOKKOS_INLINE_FUNCTION void operator()(Tag0D _tag, const TeamMember &team) const
Definition contribution_kernel.hpp:86
M::FloatType d_t
Definition contribution_kernel.hpp:57
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)
Definition contribution_kernel.hpp:26
Kokkos::TeamPolicy< ComputeSpace > TeamPolicy
Definition contribution_kernel.hpp:20
MC::EventContainer events
Definition contribution_kernel.hpp:58
MC::pool_type random_pool
Definition contribution_kernel.hpp:55
size_t np
Definition contribution_kernel.hpp:39
MC::ParticlesContainer< M > m_particles
Definition contribution_kernel.hpp:53
float float_type
Definition contribution_kernel.hpp:22
MC::KernelConcentrationType concentrations
Definition contribution_kernel.hpp:56
MC::ContributionView m_contribution_scatter
Definition contribution_kernel.hpp:52
void update(MC::ParticlesContainer< M > _particles, double _d_t)
Definition contribution_kernel.hpp:42
std::size_t m_particle_per_team
Definition contribution_kernel.hpp:50
KOKKOS_INLINE_FUNCTION void division(const std::size_t idx) const
Definition contribution_kernel.hpp:61
Use to count events that occurs during Monte-Carlo processing cycles.
Definition events.hpp:151