From a597a41cd175a8a05028b2e77663d42617be2354 Mon Sep 17 00:00:00 2001 From: anagainaru Date: Tue, 8 Oct 2024 11:19:22 -0400 Subject: [PATCH 1/2] Use the correct memory space when NdCopy is used by the writer or the reader --- source/adios2/engine/bp5/BP5Writer.cpp | 3 ++- source/adios2/helper/adiosMemory.cpp | 4 ++-- source/adios2/helper/adiosMemory.h | 3 ++- source/adios2/helper/adiosMemory.inl | 7 +++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/adios2/engine/bp5/BP5Writer.cpp b/source/adios2/engine/bp5/BP5Writer.cpp index 5305bd5707..ef26b2b4c0 100644 --- a/source/adios2/engine/bp5/BP5Writer.cpp +++ b/source/adios2/engine/bp5/BP5Writer.cpp @@ -1815,7 +1815,8 @@ void BP5Writer::PutCommon(VariableBase &variable, const void *values, bool sync) helper::NdCopy((const char *)values, helper::CoreDims(ZeroDims), MemoryCount, sourceRowMajor, false, (char *)ptr, MemoryStart, varCount, sourceRowMajor, false, (int)ObjSize, helper::CoreDims(), helper::CoreDims(), - helper::CoreDims(), helper::CoreDims(), false /* safemode */, memSpace); + helper::CoreDims(), helper::CoreDims(), false /* safemode */, memSpace, + /* duringWrite */ true); } else { diff --git a/source/adios2/helper/adiosMemory.cpp b/source/adios2/helper/adiosMemory.cpp index 211f109674..c3967f4f3d 100644 --- a/source/adios2/helper/adiosMemory.cpp +++ b/source/adios2/helper/adiosMemory.cpp @@ -251,7 +251,7 @@ int NdCopy(const char *in, const CoreDims &inStart, const CoreDims &inCount, const CoreDims &outStart, const CoreDims &outCount, const bool outIsRowMajor, const bool outIsLittleEndian, const int typeSize, const CoreDims &inMemStart, const CoreDims &inMemCount, const CoreDims &outMemStart, const CoreDims &outMemCount, - const bool safeMode, MemorySpace MemSpace) + const bool safeMode, const MemorySpace MemSpace, const bool duringWrite) { @@ -439,7 +439,7 @@ int NdCopy(const char *in, const CoreDims &inStart, const CoreDims &inCount, if (MemSpace == MemorySpace::GPU) { helper::NdCopyGPU(inOvlpBase, outOvlpBase, inOvlpGapSize, outOvlpGapSize, ovlpCount, - minContDim, blockSize, MemSpace); + minContDim, blockSize, MemSpace, duringWrite); return 0; } #endif diff --git a/source/adios2/helper/adiosMemory.h b/source/adios2/helper/adiosMemory.h index 7c56dd9823..50860fe70c 100644 --- a/source/adios2/helper/adiosMemory.h +++ b/source/adios2/helper/adiosMemory.h @@ -240,7 +240,8 @@ int NdCopy(const char *in, const CoreDims &inStart, const CoreDims &inCount, const bool outIsLittleEndian, const int typeSize, const CoreDims &inMemStart = CoreDims(), const CoreDims &inMemCount = CoreDims(), const CoreDims &outMemStart = CoreDims(), const CoreDims &outMemCount = CoreDims(), - const bool safeMode = false, MemorySpace MemSpace = MemorySpace::Host); + const bool safeMode = false, const MemorySpace MemSpace = MemorySpace::Host, + const bool duringWrite = false); template size_t PayloadSize(const T *data, const Dims &count) noexcept; diff --git a/source/adios2/helper/adiosMemory.inl b/source/adios2/helper/adiosMemory.inl index 25928198c7..0d132f5a96 100644 --- a/source/adios2/helper/adiosMemory.inl +++ b/source/adios2/helper/adiosMemory.inl @@ -105,7 +105,7 @@ void CopyFromBufferToGPU(T *GPUbuffer, size_t position, const char *source, Memo static inline void NdCopyGPU(const char *&inOvlpBase, char *&outOvlpBase, CoreDims &inOvlpGapSize, CoreDims &outOvlpGapSize, CoreDims &ovlpCount, size_t minContDim, - size_t blockSize, MemorySpace memSpace) + size_t blockSize, MemorySpace memSpace, bool duringWrite) { DimsArray pos(ovlpCount.size(), (size_t)0); size_t curDim = 0; @@ -116,7 +116,10 @@ static inline void NdCopyGPU(const char *&inOvlpBase, char *&outOvlpBase, CoreDi pos[curDim]++; curDim++; } - CopyFromBufferToGPU(outOvlpBase, 0, inOvlpBase, memSpace, blockSize); + if (duringWrite) + CopyFromGPUToBuffer(outOvlpBase, 0, inOvlpBase, memSpace, blockSize); + else + CopyFromBufferToGPU(outOvlpBase, 0, inOvlpBase, memSpace, blockSize); inOvlpBase += blockSize; outOvlpBase += blockSize; do From 48049f00bab9bddd8b8b952fcaa35584a299df29 Mon Sep 17 00:00:00 2001 From: anagainaru Date: Tue, 8 Oct 2024 11:19:35 -0400 Subject: [PATCH 2/2] Specifying the memory space of each buffer for copy operations in the Kokkos backend --- source/adios2/helper/kokkos/adiosKokkos.cpp | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/source/adios2/helper/kokkos/adiosKokkos.cpp b/source/adios2/helper/kokkos/adiosKokkos.cpp index 24b8a0d7a7..307df64028 100644 --- a/source/adios2/helper/kokkos/adiosKokkos.cpp +++ b/source/adios2/helper/kokkos/adiosKokkos.cpp @@ -13,16 +13,6 @@ namespace { -void KokkosDeepCopy(const char *src, char *dst, size_t byteCount) -{ - using mem_space = Kokkos::DefaultExecutionSpace::memory_space; - Kokkos::View> srcView( - src, byteCount); - Kokkos::View> dstView( - dst, byteCount); - Kokkos::deep_copy(dstView, srcView); -} - template void KokkosMinMaxImpl(const T *data, const size_t size, T &min, T &max) { @@ -63,12 +53,22 @@ namespace helper { void MemcpyGPUToBuffer(char *dst, const char *GPUbuffer, size_t byteCount) { - KokkosDeepCopy(GPUbuffer, dst, byteCount); + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View> srcView( + GPUbuffer, byteCount); + Kokkos::View> dstView( + dst, byteCount); + Kokkos::deep_copy(dstView, srcView); } void MemcpyBufferToGPU(char *GPUbuffer, const char *src, size_t byteCount) { - KokkosDeepCopy(src, GPUbuffer, byteCount); + using mem_space = Kokkos::DefaultExecutionSpace::memory_space; + Kokkos::View> srcView( + src, byteCount); + Kokkos::View> dstView(GPUbuffer, + byteCount); + Kokkos::deep_copy(dstView, srcView); } bool IsGPUbuffer(const void *ptr)