Skip to content

Commit 47af36e

Browse files
Fix Random Engine constructor for GPU compilation (#5877)
AMReX PR included a fix to prevent bugs with random engine definitions AMReX-Codes/amrex#4443 This resulted in the development branch breaking when compiling with GPUs This PR fixes this compilation error
1 parent 4596c26 commit 47af36e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Source/Initialization/PlasmaInjector.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,11 @@ amrex::XDim3 PlasmaInjector::getMomentum (amrex::Real x,
581581
amrex::Real y,
582582
amrex::Real z) const noexcept
583583
{
584+
#ifdef AMREX_USE_GPU
585+
return h_inj_mom->getMomentum(x, y, z, amrex::RandomEngine{nullptr}); // gamma*beta
586+
#else
584587
return h_inj_mom->getMomentum(x, y, z, amrex::RandomEngine{}); // gamma*beta
588+
#endif
585589
}
586590

587591
bool PlasmaInjector::insideBounds (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept

Source/Particles/ParticleBoundaryBuffer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ void ParticleBoundaryBuffer::gatherParticlesFromDomainBoundaries (MultiParticleC
429429
amrex::ReduceData<int> reduce_data(reduce_op);
430430
{
431431
WARPX_PROFILE("ParticleBoundaryBuffer::gatherParticles::count_out_of_bounds");
432+
#ifdef AMREX_USE_GPU
433+
const amrex::RandomEngine rng{nullptr};
434+
#else
432435
const amrex::RandomEngine rng{};
436+
#endif
433437
reduce_op.eval(np, reduce_data, [=] AMREX_GPU_HOST_DEVICE (int ip)
434438
{ return predicate(ptile_data, ip, rng) ? 1 : 0; });
435439
}

Source/Particles/ParticleCreation/DefaultInitialization.H

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
168168
// Otherwise (e.g. particle tile allocated in pinned memory), run on CPU
169169
} else {
170170
for (int ip = start; ip < stop; ++ip) {
171+
#ifdef AMREX_USE_GPU
172+
attr_ptr[ip] = quantum_sync_get_opt(amrex::RandomEngine{nullptr});
173+
#else
171174
attr_ptr[ip] = quantum_sync_get_opt(amrex::RandomEngine{});
175+
#endif
172176
}
173177
}
174178
}
@@ -191,7 +195,11 @@ void DefaultInitializeRuntimeAttributes (PTile& ptile,
191195
// Otherwise (e.g. particle tile allocated in pinned memory), run on CPU
192196
} else {
193197
for (int ip = start; ip < stop; ++ip) {
198+
#ifdef AMREX_USE_GPU
199+
attr_ptr[ip] = breit_wheeler_get_opt(amrex::RandomEngine{nullptr});
200+
#else
194201
attr_ptr[ip] = breit_wheeler_get_opt(amrex::RandomEngine{});
202+
#endif
195203
}
196204
}
197205
}

0 commit comments

Comments
 (0)