Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Source/Particles/ParticleCreation/DefaultInitialization.H
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
constexpr int lev = 0;
const amrex::Real t = WarpX::GetInstance().gett_new(lev);

// Check: does the particle data reside on CPU or GPU?
amrex::Arena const * const pc_arena = pc.arena();
const bool run_on_gpu =
pc_arena->isManaged() || pc_arena->isDevice();

// Initialize the last NumRuntimeRealComps() - n_external_attr_real runtime real attributes
for (int j = PIdx::nattribs + n_external_attr_real; j < ptile.NumRealComps() ; ++j)
{
Expand All @@ -158,7 +163,7 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
const QuantumSynchrotronGetOpticalDepth quantum_sync_get_opt =
p_qs_engine->build_optical_depth_functor();
// If the particle tile was allocated in a memory pool that can run on GPU, launch GPU kernel
if constexpr (amrex::RunOnGpu<typename PTile::template AllocatorType<amrex::Real>>::value) {
if (run_on_gpu) {
amrex::ParallelForRNG(stop - start,
[=] AMREX_GPU_DEVICE (int i, amrex::RandomEngine const& engine) noexcept {
const int ip = i + start;
Expand All @@ -185,7 +190,7 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
const BreitWheelerGetOpticalDepth breit_wheeler_get_opt =
p_bw_engine->build_optical_depth_functor();;
// If the particle tile was allocated in a memory pool that can run on GPU, launch GPU kernel
if constexpr (amrex::RunOnGpu<typename PTile::template AllocatorType<amrex::Real>>::value) {
if (run_on_gpu) {
amrex::ParallelForRNG(stop - start,
[=] AMREX_GPU_DEVICE (int i, amrex::RandomEngine const& engine) noexcept {
const int ip = i + start;
Expand Down Expand Up @@ -214,7 +219,7 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
const amrex::ParserExecutor<7> user_real_attrib_parserexec =
user_real_attrib_parser[ia]->compile<7>();
// If the particle tile was allocated in a memory pool that can run on GPU, launch GPU kernel
if constexpr (amrex::RunOnGpu<typename PTile::template AllocatorType<amrex::Real>>::value) {
if (run_on_gpu) {
amrex::ParallelFor(stop - start,
[=] AMREX_GPU_DEVICE (int i) noexcept {
const int ip = i + start;
Expand Down Expand Up @@ -246,7 +251,7 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
if (it_ioniz != particle_icomps.end() &&
std::distance(particle_icomps.begin(), it_ioniz) == j)
{
if constexpr (amrex::RunOnGpu<typename PTile::template AllocatorType<int>>::value) {
if (run_on_gpu) {
amrex::ParallelFor(stop - start,
[=] AMREX_GPU_DEVICE (int i) noexcept {
const int ip = i + start;
Expand All @@ -268,7 +273,7 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
{
const amrex::ParserExecutor<7> user_int_attrib_parserexec =
user_int_attrib_parser[ia]->compile<7>();
if constexpr (amrex::RunOnGpu<typename PTile::template AllocatorType<int>>::value) {
if (run_on_gpu) {
amrex::ParallelFor(stop - start,
[=] AMREX_GPU_DEVICE (int i) noexcept {
const int ip = i + start;
Expand Down
Loading