Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
anagainaru committed Sep 13, 2024
1 parent f9e49f5 commit ad07058
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 77 deletions.
5 changes: 3 additions & 2 deletions testing/adios2/engine/bp/TestBPWriteReadCuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void CUDADetectMemSpace(const std::string mode)
std::bind(std::plus<float>(), std::placeholders::_1, INCREMENT));

bpWriter.BeginStep();
bpWriter.Put(var_gpur32, gpuSimData, ioMode);
bpWriter.Put(var_gpur32, gpuSimData, ioMode);
bpWriter.Put(var_r32, r32s.data(), ioMode);
bpWriter.EndStep();
}
Expand Down Expand Up @@ -115,7 +115,8 @@ void CUDADetectMemSpace(const std::string mode)
for (size_t i = 0; i < NTotal; i++)
{
char msg[1 << 8] = {0};
snprintf(msg, sizeof(msg), "t=%d i=%zu r32o=%f r32s=%f gpu32o=%f", t, i, r32o[i], r32s[i], gpur32o[i]);
snprintf(msg, sizeof(msg), "t=%d i=%zu r32o=%f r32s=%f gpu32o=%f", t, i, r32o[i],
r32s[i], gpur32o[i]);
ASSERT_LT(std::abs(r32o[i] - r32s[i]), EPSILON) << msg;
ASSERT_LT(std::abs(gpur32o[i] - r32s[i]), EPSILON) << msg;
}
Expand Down
153 changes: 78 additions & 75 deletions testing/adios2/engine/bp/TestBPWriteReadKokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void KokkosDetectMemSpace(const std::string mode)
adios2::ADIOS adios;
{ // write
Kokkos::View<float *, Kokkos::HostSpace> cpuData("simBuffer", Nx);
Kokkos::parallel_for("initBuffer", Kokkos::RangePolicy<Kokkos::Serial>(0, Nx),
KOKKOS_LAMBDA(int i) { cpuData(i) = static_cast<float>(i); });
Kokkos::parallel_for(
"initBuffer", Kokkos::RangePolicy<Kokkos::Serial>(0, Nx),
KOKKOS_LAMBDA(int i) { cpuData(i) = static_cast<float>(i); });
Kokkos::fence();
auto gpuData = Kokkos::create_mirror_view_and_copy(
Kokkos::DefaultExecutionSpace::memory_space{}, cpuData);
Expand Down Expand Up @@ -60,11 +61,12 @@ void KokkosDetectMemSpace(const std::string mode)
bpWriter.Put(var_gpur32, gpuData, ioMode);
bpWriter.Put(var_r32, cpuData, ioMode);
bpWriter.EndStep();
Kokkos::parallel_for("updateCPUBuffer", Kokkos::RangePolicy<Kokkos::Serial>(0, Nx),
KOKKOS_LAMBDA(int i) { cpuData(i) += INCREMENT; });
Kokkos::parallel_for("updateGPUBuffer",
Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, Nx),
KOKKOS_LAMBDA(int i) { gpuData(i) += INCREMENT; });
Kokkos::parallel_for(
"updateCPUBuffer", Kokkos::RangePolicy<Kokkos::Serial>(0, Nx),
KOKKOS_LAMBDA(int i) { cpuData(i) += INCREMENT; });
Kokkos::parallel_for(
"updateGPUBuffer", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, Nx),
KOKKOS_LAMBDA(int i) { gpuData(i) += INCREMENT; });
Kokkos::fence();
}

Expand Down Expand Up @@ -137,20 +139,17 @@ void KokkosWriteReadMemorySelection()
const size_t ghostCells = 2;
const size_t totalNx = Nx + 2 * ghostCells, totalNy = Ny + 2 * ghostCells;

Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer", totalNx, totalNy);
Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer",
totalNx, totalNy);
// initialize all data to 0 and update values in the active selection
Kokkos::parallel_for(
"zeroBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {totalNx, totalNy}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) = 0;
});
"zeroBuffer", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {totalNx, totalNy}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = 0; });
Kokkos::parallel_for(
"initBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) = x * (mpiRank + 1);
});
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({ghostCells, ghostCells},
{totalNx - ghostCells, totalNy - ghostCells}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * (mpiRank + 1); });
Kokkos::fence();

{ // write
Expand Down Expand Up @@ -181,10 +180,9 @@ void KokkosWriteReadMemorySelection()
// Update values in the simulation data
Kokkos::parallel_for(
"updateBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) += INCREMENT;
});
Kokkos::MDRangePolicy<Kokkos::Rank<2>>(
{ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) += INCREMENT; });
Kokkos::fence();
}

Expand All @@ -209,21 +207,26 @@ void KokkosWriteReadMemorySelection()
EXPECT_EQ(var_r32.Min(), t * INCREMENT + ghostCells);
EXPECT_EQ(var_r32.Max(), t * INCREMENT + (Nx + ghostCells - 1) * mpiSize);

Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> outputData("outBuffer", Nx, Ny);
Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> outputData(
"outBuffer", Nx, Ny);
bpReader.Get(var_r32, outputData);
bpReader.EndStep();

auto cpuData =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace::memory_space{}, outputData);

for (size_t x = 0; x < Nx; x++)
for (size_t y = 0; y < Ny; y++)
{
char msg[1 << 8] = {0};
snprintf(msg, sizeof(msg), "t=%d i=(%zu %zu) rank=%d r32o=%f r32i=%f", t, x, y, mpiRank,
cpuData(x, y), INCREMENT * t + (x + ghostCells) * (mpiRank + 1));
ASSERT_LT(std::abs(cpuData(x, y) - (INCREMENT * t + (x + ghostCells) * (mpiRank + 1))), EPSILON) << msg;
}
for (size_t y = 0; y < Ny; y++)
{
char msg[1 << 8] = {0};
snprintf(msg, sizeof(msg), "t=%d i=(%zu %zu) rank=%d r32o=%f r32i=%f", t, x, y,
mpiRank, cpuData(x, y),
INCREMENT * t + (x + ghostCells) * (mpiRank + 1));
ASSERT_LT(std::abs(cpuData(x, y) -
(INCREMENT * t + (x + ghostCells) * (mpiRank + 1))),
EPSILON)
<< msg;
}
}
EXPECT_EQ(t, NSteps);
bpReader.Close();
Expand Down Expand Up @@ -258,13 +261,11 @@ void KokkosWriteReadMPI2D()
#endif

// Initialize the simulation data
Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer", Nx, Ny);
Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer", Nx,
Ny);
Kokkos::parallel_for(
"initBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {Nx, Ny}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) = x * (mpiRank + 1);
});
"initBuffer", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {Nx, Ny}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * (mpiRank + 1); });
Kokkos::fence();

{ // write
Expand All @@ -290,11 +291,8 @@ void KokkosWriteReadMPI2D()
bpWriter.EndStep();
// Update values in the simulation data
Kokkos::parallel_for(
"updateBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {Nx, Ny}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) += INCREMENT;
});
"updateBuffer", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {Nx, Ny}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) += INCREMENT; });
Kokkos::fence();
}

Expand Down Expand Up @@ -327,7 +325,8 @@ void KokkosWriteReadMPI2D()
EXPECT_EQ(var_r32.Min(), INCREMENT * t);
EXPECT_EQ(var_r32.Max(), INCREMENT * t + (Nx - 1) * mpiSize);

Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> outputData("outBuffer", Nx, Ny);
Kokkos::View<float **, Kokkos::DefaultExecutionSpace::memory_space> outputData(
"outBuffer", Nx, Ny);
bpReader.Get(var_r32, outputData);
bpReader.EndStep();

Expand All @@ -336,36 +335,41 @@ void KokkosWriteReadMPI2D()

for (size_t x = 0; x < Nx; x++)
for (size_t y = 0; y < Ny; y++)
{
char msg[1 << 8] = {0};
snprintf(msg, sizeof(msg), "t=%d i=(%zu %zu) rank=%d r32o=%f r32i=%f", t, x, y, mpiRank,
cpuData(x, y), INCREMENT * t + x * (mpiRank + 1));
ASSERT_LT(std::abs(cpuData(x, y) - (INCREMENT * t + x * (mpiRank + 1))), EPSILON) << msg;
}
{
char msg[1 << 8] = {0};
snprintf(msg, sizeof(msg), "t=%d i=(%zu %zu) rank=%d r32o=%f r32i=%f", t, x, y,
mpiRank, cpuData(x, y), INCREMENT * t + x * (mpiRank + 1));
ASSERT_LT(std::abs(cpuData(x, y) - (INCREMENT * t + x * (mpiRank + 1))),
EPSILON)
<< msg;
}
}
EXPECT_EQ(t, NSteps);

bpReader.Close();
}
}

bool compareSelection2D(const Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> a, const adios2::Dims &shape, const adios2::Dims &start,
const adios2::Dims &count, Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> b)
bool compareSelection2D(
const Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> a,
const adios2::Dims &shape, const adios2::Dims &start, const adios2::Dims &count,
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> b)
{
std::cout << " compare Block: shape = " << adios2::ToString(shape)
<< " start = " << adios2::ToString(start) << " count = " << adios2::ToString(count)
<< std::endl;
size_t match = 0;
Kokkos::parallel_for(
"compareBuffers",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {count[0], count[1]}),
KOKKOS_LAMBDA(int x, int y) {
Kokkos::parallel_reduce(
"compareBuffers", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {count[0], count[1]}),
KOKKOS_LAMBDA(int x, int y, size_t &lmatch) {
if (b(x, y) != a(start[0] + x, start[1] + y))
{
//match += 1;
Kokkos::printf(" Non-match at pos = (%d %d) : input = %f : output = %f\n", x, y, a(start[0] + x, start[1] + y), b(x, y));
lmatch++;
Kokkos::printf(" Non-match at pos = (%d %d) : input = %f : output = %f\n", x, y,
a(start[0] + x, start[1] + y), b(x, y));
}
});
},
match);
Kokkos::fence();
return (match == 0);
}
Expand All @@ -384,13 +388,11 @@ void KokkosWriteReadSelection2D()
constexpr size_t DIM2 = 3 * C2;
const std::string filename = "BPWRKokkosSel2D.bp";
double a[DIM1 * DIM2];
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer", DIM1, DIM2);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> inputData("inBuffer", DIM1,
DIM2);
Kokkos::parallel_for(
"initBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {DIM1, DIM2}),
KOKKOS_LAMBDA(int x, int y) {
inputData(x, y) = x * 1.0 + y / 100.0;
});
"initBuffer", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {DIM1, DIM2}),
KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * 1.0 + y / 100.0; });
Kokkos::fence();

adios2::ADIOS adios;
Expand All @@ -405,21 +407,20 @@ void KokkosWriteReadSelection2D()
const adios2::Dims shape = {DIM1, DIM2};
const adios2::Dims count = {C1, C2};
adios2::Dims start{0, 0};
adios2::Variable<double> var = ioWrite.DefineVariable<double>("selDouble", shape, start, count);
adios2::Variable<double> var =
ioWrite.DefineVariable<double>("selDouble", shape, start, count);

engine.BeginStep();
for (size_t i = 0; i < DIM1; i += count[0])
{
for (size_t j = 0; j < DIM2; j += count[1])
{
start = {i, j};
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selData("selBuffer", C1, C2);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selData(
"selBuffer", C1, C2);
Kokkos::parallel_for(
"createSelBuffer",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {C1, C2}),
KOKKOS_LAMBDA(int x, int y) {
selData(x, y) = inputData(i + x, j + y);
});
"createSelBuffer", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {C1, C2}),
KOKKOS_LAMBDA(int x, int y) { selData(x, y) = inputData(i + x, j + y); });
Kokkos::fence();
var.SetSelection({start, count});
var.SetMemorySpace(adiosMemSpace);
Expand Down Expand Up @@ -451,7 +452,8 @@ void KokkosWriteReadSelection2D()

/* Entire array */
{
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData("selOutBuffer", DIM1, DIM2);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData(
"selOutBuffer", DIM1, DIM2);
var.SetSelection({s, c});
var.SetMemorySpace(adiosMemSpace);
engine.Get<double>(var, selOutData, adios2::Mode::Sync);
Expand All @@ -461,7 +463,8 @@ void KokkosWriteReadSelection2D()
{
s = {5, 4};
c = count;
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData("selOutBuffer", c[0], c[1]);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData(
"selOutBuffer", c[0], c[1]);
var.SetSelection({s, c});
var.SetMemorySpace(adiosMemSpace);
engine.Get<double>(var, selOutData, adios2::Mode::Sync);
Expand All @@ -471,7 +474,8 @@ void KokkosWriteReadSelection2D()
{
s = {5, 4};
c = {2 * count[0], 2 * count[1]};
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData("selOutBuffer", c[0], c[1]);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData(
"selOutBuffer", c[0], c[1]);
var.SetSelection({s, c});
var.SetMemorySpace(adiosMemSpace);
engine.Get<double>(var, selOutData, adios2::Mode::Sync);
Expand All @@ -481,14 +485,13 @@ void KokkosWriteReadSelection2D()
{
s = {6, 5};
c = {count[0] - 2, count[1] - 2};
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData("selOutBuffer", c[0], c[1]);
Kokkos::View<double **, Kokkos::DefaultExecutionSpace::memory_space> selOutData(
"selOutBuffer", c[0], c[1]);
var.SetSelection({s, c});
var.SetMemorySpace(adiosMemSpace);
engine.Get<double>(var, selOutData, adios2::Mode::Sync);
EXPECT_TRUE(compareSelection2D(inputData, shape, s, c, selOutData));
}


}
}

Expand Down

0 comments on commit ad07058

Please sign in to comment.