diff --git a/testing/adios2/engine/bp/TestBPWriteReadCuda.cpp b/testing/adios2/engine/bp/TestBPWriteReadCuda.cpp index 1d399339b3..597ac7a3aa 100644 --- a/testing/adios2/engine/bp/TestBPWriteReadCuda.cpp +++ b/testing/adios2/engine/bp/TestBPWriteReadCuda.cpp @@ -66,7 +66,7 @@ void CUDADetectMemSpace(const std::string mode) std::bind(std::plus(), 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(); } @@ -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; } diff --git a/testing/adios2/engine/bp/TestBPWriteReadKokkos.cpp b/testing/adios2/engine/bp/TestBPWriteReadKokkos.cpp index de987f8ba1..fa6e71878e 100644 --- a/testing/adios2/engine/bp/TestBPWriteReadKokkos.cpp +++ b/testing/adios2/engine/bp/TestBPWriteReadKokkos.cpp @@ -31,8 +31,9 @@ void KokkosDetectMemSpace(const std::string mode) adios2::ADIOS adios; { // write Kokkos::View cpuData("simBuffer", Nx); - Kokkos::parallel_for("initBuffer", Kokkos::RangePolicy(0, Nx), - KOKKOS_LAMBDA(int i) { cpuData(i) = static_cast(i); }); + Kokkos::parallel_for( + "initBuffer", Kokkos::RangePolicy(0, Nx), + KOKKOS_LAMBDA(int i) { cpuData(i) = static_cast(i); }); Kokkos::fence(); auto gpuData = Kokkos::create_mirror_view_and_copy( Kokkos::DefaultExecutionSpace::memory_space{}, cpuData); @@ -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(0, Nx), - KOKKOS_LAMBDA(int i) { cpuData(i) += INCREMENT; }); - Kokkos::parallel_for("updateGPUBuffer", - Kokkos::RangePolicy(0, Nx), - KOKKOS_LAMBDA(int i) { gpuData(i) += INCREMENT; }); + Kokkos::parallel_for( + "updateCPUBuffer", Kokkos::RangePolicy(0, Nx), + KOKKOS_LAMBDA(int i) { cpuData(i) += INCREMENT; }); + Kokkos::parallel_for( + "updateGPUBuffer", Kokkos::RangePolicy(0, Nx), + KOKKOS_LAMBDA(int i) { gpuData(i) += INCREMENT; }); Kokkos::fence(); } @@ -137,20 +139,17 @@ void KokkosWriteReadMemorySelection() const size_t ghostCells = 2; const size_t totalNx = Nx + 2 * ghostCells, totalNy = Ny + 2 * ghostCells; - Kokkos::View inputData("inBuffer", totalNx, totalNy); + Kokkos::View inputData("inBuffer", + totalNx, totalNy); // initialize all data to 0 and update values in the active selection Kokkos::parallel_for( - "zeroBuffer", - Kokkos::MDRangePolicy>({0, 0}, {totalNx, totalNy}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) = 0; - }); + "zeroBuffer", Kokkos::MDRangePolicy>({0, 0}, {totalNx, totalNy}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = 0; }); Kokkos::parallel_for( "initBuffer", - Kokkos::MDRangePolicy>({ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) = x * (mpiRank + 1); - }); + Kokkos::MDRangePolicy>({ghostCells, ghostCells}, + {totalNx - ghostCells, totalNy - ghostCells}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * (mpiRank + 1); }); Kokkos::fence(); { // write @@ -181,10 +180,9 @@ void KokkosWriteReadMemorySelection() // Update values in the simulation data Kokkos::parallel_for( "updateBuffer", - Kokkos::MDRangePolicy>({ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) += INCREMENT; - }); + Kokkos::MDRangePolicy>( + {ghostCells, ghostCells}, {totalNx - ghostCells, totalNy - ghostCells}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) += INCREMENT; }); Kokkos::fence(); } @@ -209,7 +207,8 @@ void KokkosWriteReadMemorySelection() EXPECT_EQ(var_r32.Min(), t * INCREMENT + ghostCells); EXPECT_EQ(var_r32.Max(), t * INCREMENT + (Nx + ghostCells - 1) * mpiSize); - Kokkos::View outputData("outBuffer", Nx, Ny); + Kokkos::View outputData( + "outBuffer", Nx, Ny); bpReader.Get(var_r32, outputData); bpReader.EndStep(); @@ -217,13 +216,17 @@ void KokkosWriteReadMemorySelection() 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(); @@ -258,13 +261,11 @@ void KokkosWriteReadMPI2D() #endif // Initialize the simulation data - Kokkos::View inputData("inBuffer", Nx, Ny); + Kokkos::View inputData("inBuffer", Nx, + Ny); Kokkos::parallel_for( - "initBuffer", - Kokkos::MDRangePolicy>({0, 0}, {Nx, Ny}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) = x * (mpiRank + 1); - }); + "initBuffer", Kokkos::MDRangePolicy>({0, 0}, {Nx, Ny}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * (mpiRank + 1); }); Kokkos::fence(); { // write @@ -290,11 +291,8 @@ void KokkosWriteReadMPI2D() bpWriter.EndStep(); // Update values in the simulation data Kokkos::parallel_for( - "updateBuffer", - Kokkos::MDRangePolicy>({0, 0}, {Nx, Ny}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) += INCREMENT; - }); + "updateBuffer", Kokkos::MDRangePolicy>({0, 0}, {Nx, Ny}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) += INCREMENT; }); Kokkos::fence(); } @@ -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 outputData("outBuffer", Nx, Ny); + Kokkos::View outputData( + "outBuffer", Nx, Ny); bpReader.Get(var_r32, outputData); bpReader.EndStep(); @@ -336,12 +335,14 @@ 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); @@ -349,23 +350,26 @@ void KokkosWriteReadMPI2D() } } -bool compareSelection2D(const Kokkos::View a, const adios2::Dims &shape, const adios2::Dims &start, - const adios2::Dims &count, Kokkos::View b) +bool compareSelection2D( + const Kokkos::View a, + const adios2::Dims &shape, const adios2::Dims &start, const adios2::Dims &count, + Kokkos::View 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>({0, 0}, {count[0], count[1]}), - KOKKOS_LAMBDA(int x, int y) { + Kokkos::parallel_reduce( + "compareBuffers", Kokkos::MDRangePolicy>({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); } @@ -384,13 +388,11 @@ void KokkosWriteReadSelection2D() constexpr size_t DIM2 = 3 * C2; const std::string filename = "BPWRKokkosSel2D.bp"; double a[DIM1 * DIM2]; - Kokkos::View inputData("inBuffer", DIM1, DIM2); + Kokkos::View inputData("inBuffer", DIM1, + DIM2); Kokkos::parallel_for( - "initBuffer", - Kokkos::MDRangePolicy>({0, 0}, {DIM1, DIM2}), - KOKKOS_LAMBDA(int x, int y) { - inputData(x, y) = x * 1.0 + y / 100.0; - }); + "initBuffer", Kokkos::MDRangePolicy>({0, 0}, {DIM1, DIM2}), + KOKKOS_LAMBDA(int x, int y) { inputData(x, y) = x * 1.0 + y / 100.0; }); Kokkos::fence(); adios2::ADIOS adios; @@ -405,7 +407,8 @@ void KokkosWriteReadSelection2D() const adios2::Dims shape = {DIM1, DIM2}; const adios2::Dims count = {C1, C2}; adios2::Dims start{0, 0}; - adios2::Variable var = ioWrite.DefineVariable("selDouble", shape, start, count); + adios2::Variable var = + ioWrite.DefineVariable("selDouble", shape, start, count); engine.BeginStep(); for (size_t i = 0; i < DIM1; i += count[0]) @@ -413,13 +416,11 @@ void KokkosWriteReadSelection2D() for (size_t j = 0; j < DIM2; j += count[1]) { start = {i, j}; - Kokkos::View selData("selBuffer", C1, C2); + Kokkos::View selData( + "selBuffer", C1, C2); Kokkos::parallel_for( - "createSelBuffer", - Kokkos::MDRangePolicy>({0, 0}, {C1, C2}), - KOKKOS_LAMBDA(int x, int y) { - selData(x, y) = inputData(i + x, j + y); - }); + "createSelBuffer", Kokkos::MDRangePolicy>({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); @@ -451,7 +452,8 @@ void KokkosWriteReadSelection2D() /* Entire array */ { - Kokkos::View selOutData("selOutBuffer", DIM1, DIM2); + Kokkos::View selOutData( + "selOutBuffer", DIM1, DIM2); var.SetSelection({s, c}); var.SetMemorySpace(adiosMemSpace); engine.Get(var, selOutData, adios2::Mode::Sync); @@ -461,7 +463,8 @@ void KokkosWriteReadSelection2D() { s = {5, 4}; c = count; - Kokkos::View selOutData("selOutBuffer", c[0], c[1]); + Kokkos::View selOutData( + "selOutBuffer", c[0], c[1]); var.SetSelection({s, c}); var.SetMemorySpace(adiosMemSpace); engine.Get(var, selOutData, adios2::Mode::Sync); @@ -471,7 +474,8 @@ void KokkosWriteReadSelection2D() { s = {5, 4}; c = {2 * count[0], 2 * count[1]}; - Kokkos::View selOutData("selOutBuffer", c[0], c[1]); + Kokkos::View selOutData( + "selOutBuffer", c[0], c[1]); var.SetSelection({s, c}); var.SetMemorySpace(adiosMemSpace); engine.Get(var, selOutData, adios2::Mode::Sync); @@ -481,14 +485,13 @@ void KokkosWriteReadSelection2D() { s = {6, 5}; c = {count[0] - 2, count[1] - 2}; - Kokkos::View selOutData("selOutBuffer", c[0], c[1]); + Kokkos::View selOutData( + "selOutBuffer", c[0], c[1]); var.SetSelection({s, c}); var.SetMemorySpace(adiosMemSpace); engine.Get(var, selOutData, adios2::Mode::Sync); EXPECT_TRUE(compareSelection2D(inputData, shape, s, c, selOutData)); } - - } }