Skip to content

Commit

Permalink
Fix a number of tests for GPU
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang committed Feb 4, 2025
1 parent 779df09 commit ecf9035
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
35 changes: 18 additions & 17 deletions Tests/MultiBlock/IndexType/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@
int MyMain();

int main(int argc, char** argv) {
#ifdef AMREX_USE_MPI
MPI_Init(&argc, &argv);
#else
amrex::ignore_unused(argc,argv);
#endif
amrex::Initialize(argc, argv);
// Let me throw exceptions for triggering my debugger
amrex::Initialize(MPI_COMM_WORLD, std::cout, std::cerr, [](const char* msg) { throw std::runtime_error(msg); });
amrex::SetErrorHandler([](const char* msg) { throw std::runtime_error(msg); });
int ret = MyMain();
amrex::Finalize();
#ifdef AMREX_USE_MPI
MPI_Finalize();
#endif
return ret;
}

Expand Down Expand Up @@ -51,19 +44,23 @@ bool ParallelCopyWithItselfIsCorrect(amrex::iMultiFab& mf, const amrex::Box& dom
const int nx = domain.length(0);
const int ny = domain.length(1);
int fails = 0;
amrex::ReduceOps<amrex::ReduceOpSum> reduce_op;
amrex::ReduceData<int> reduce_data(reduce_op);
using ReduceTuple = amrex::GpuTuple<int>;
for (amrex::MFIter mfi(mf); mfi.isValid(); ++mfi) {
const amrex::Box section = dest_box & mfi.tilebox();
if (section.isEmpty()) { continue; }
auto array = mf.const_array(mfi);
amrex::LoopOnCpu(section, [&](int i, int j, int k)
reduce_op.eval(section, reduce_data,
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
{
amrex::Dim3 si = dtos(amrex::Dim3{i,j,k});
int value = si.x + si.y*nx + si.z*nx*ny;
fails += (array(i,j,k) != value);

AMREX_ASSERT(fails==0); // If DEBUG, crash on first error.
auto r = int(array(i,j,k) != value);
return { r };
});
}
fails += amrex::get<0>(reduce_data.value());
return fails == 0;
}

Expand Down Expand Up @@ -113,19 +110,23 @@ bool ParallelCopyFaceToFace(amrex::iMultiFab& dest, const amrex::Box& domain_des
int fails = 0;
const int nx = domain_src.length(0);
const int ny = domain_src.length(1);
amrex::ReduceOps<amrex::ReduceOpSum> reduce_op;
amrex::ReduceData<int> reduce_data(reduce_op);
using ReduceTuple = amrex::GpuTuple<int>;
for (amrex::MFIter mfi(dest); mfi.isValid(); ++mfi) {
const amrex::Box section = dest_box & mfi.tilebox();
if (section.isEmpty()) { continue; }
auto darray = dest.const_array(mfi);
amrex::LoopOnCpu(section, [&](int i, int j, int k)
reduce_op.eval(section, reduce_data,
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
{
amrex::Dim3 si = dtos(amrex::Dim3{i,j,k});
int value = si.x + si.y*nx + si.z*nx*ny;
fails += (darray(i,j,k) != value);

AMREX_ASSERT(fails==0); // If in debug, crash on first error.
auto r = int(darray(i,j,k) != value);
return { r };
});
}
fails += amrex::get<0>(reduce_data.value());
return fails == 0;
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/Particles/DenseBins/inputs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
amrex.the_arena_is_managed = 1
nitems = 100000017
nbins = 5000

#nitems = 20
#nbins = 4
#nbins = 4
2 changes: 0 additions & 2 deletions Tests/Particles/DenseBins/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ void testDenseBins ()
amrex::Vector<int> items(nitems);
initData(nbins, items);

#ifndef AMREX_USE_SYCL
testSerial(nbins, items);
#endif
#ifdef AMREX_USE_OMP
testOpenMP(nbins, items);
#endif
Expand Down
4 changes: 4 additions & 0 deletions Tests/Particles/NamedSoAComponents/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void addParticles ()

int main (int argc, char* argv[])
{
{
amrex::ParmParse pp("amrex");
pp.add("the_arena_is_managed", 1);
}
amrex::Initialize(argc,argv);
{
addParticles();
Expand Down
4 changes: 4 additions & 0 deletions Tests/Particles/SOAParticle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ void addParticles ()

int main(int argc, char* argv[])
{
{
amrex::ParmParse pp("amrex");
pp.add("the_arena_is_managed", 1);
}
amrex::Initialize(argc,argv);
{
addParticles< ParticleContainerPureSoA<4, 2> > ();
Expand Down

0 comments on commit ecf9035

Please sign in to comment.