Skip to content

Commit

Permalink
Allowing the option of Detect memory space only if any GPU backend is…
Browse files Browse the repository at this point in the history
… enabled
  • Loading branch information
anagainaru committed Dec 27, 2022
1 parent 341ceab commit 0e7c650
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ endif()


set(ADIOS2_CONFIG_OPTS
BP5 DataMan DataSpaces HDF5 HDF5_VOL MHS SST CUDA Fortran MPI Python Blosc Blosc2 BZip2 LIBPRESSIO MGARD PNG SZ ZFP DAOS IME O_DIRECT Sodium Catalyst SysVShMem ZeroMQ Profiling Endian_Reverse
BP5 DataMan DataSpaces HDF5 HDF5_VOL MHS SST CUDA Fortran MPI Python Blosc Blosc2 BZip2 LIBPRESSIO MGARD PNG SZ ZFP DAOS IME O_DIRECT Sodium Catalyst SysVShMem ZeroMQ Profiling Endian_Reverse GPU_Support
)

GenerateADIOSHeaderConfig(${ADIOS2_CONFIG_OPTS})
Expand Down
1 change: 1 addition & 0 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ endif()
if(CMAKE_CUDA_COMPILER AND CUDAToolkit_FOUND)
enable_language(CUDA)
set(ADIOS2_HAVE_CUDA TRUE)
set(ADIOS2_HAVE_GPU_Support TRUE)
endif()

# Fortran
Expand Down
6 changes: 4 additions & 2 deletions source/adios2/common/ADIOSTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ namespace adios2
/** Memory space for the user provided buffers */
enum class MemorySpace
{
#ifdef ADIOS2_HAVE_GPU_SUPPORT
Detect, ///< Detect the memory space automatically
Host, ///< Host memory space (default)
#endif
Host, ///< Host memory space
#ifdef ADIOS2_HAVE_CUDA
CUDA ///< CUDA memory spaces
CUDA ///< CUDA memory spaces
#endif
};

Expand Down
8 changes: 7 additions & 1 deletion source/adios2/core/VariableBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ size_t VariableBase::TotalSize() const noexcept

MemorySpace VariableBase::DetectMemorySpace(const void *ptr)
{
#ifdef ADIOS2_HAVE_GPU_SUPPORT
if (m_MemSpaceRequested != MemorySpace::Detect)
{
m_MemSpaceDetected = m_MemSpaceRequested;
return m_MemSpaceRequested;
}
#endif

// if the user requested MemorySpace::Detect
#ifdef ADIOS2_HAVE_CUDA
cudaPointerAttributes attr;
cudaPointerGetAttributes(&attr, ptr);
Expand All @@ -72,16 +73,21 @@ MemorySpace VariableBase::DetectMemorySpace(const void *ptr)

MemorySpace VariableBase::GetMemorySpace(const void *ptr)
{
#ifdef ADIOS2_HAVE_GPU_SUPPORT
if (m_MemSpaceDetected == MemorySpace::Detect)
m_MemSpaceDetected = DetectMemorySpace(ptr);
return m_MemSpaceDetected;
#endif
return MemorySpace::Host;
}

void VariableBase::SetMemorySpace(const MemorySpace mem)
{
m_MemSpaceRequested = mem;
// reset the detected memory space
#ifdef ADIOS2_HAVE_GPU_SUPPORT
m_MemSpaceDetected = MemorySpace::Detect;
#endif
}

void VariableBase::SetShape(const adios2::Dims &shape)
Expand Down
5 changes: 3 additions & 2 deletions source/adios2/core/VariableBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class VariableBase
* VariableStruct -> from constructor sizeof(struct) */
const size_t m_ElementSize;
/* User requested memory space and the detected memory space */
#ifdef ADIOS2_HAVE_CUDA
#ifdef ADIOS2_HAVE_GPU_SUPPORT
MemorySpace m_MemSpaceRequested = MemorySpace::Detect;
MemorySpace m_MemSpaceDetected = MemorySpace::Detect;
#else
MemorySpace m_MemSpaceRequested = MemorySpace::Host;
MemorySpace m_MemSpaceDetected = MemorySpace::Host;
#endif
MemorySpace m_MemSpaceDetected = MemorySpace::Detect;

ShapeID m_ShapeID = ShapeID::Unknown; ///< see shape types in ADIOSTypes.h
size_t m_BlockID = 0; ///< current block ID for local variables, global = 0
Expand Down

0 comments on commit 0e7c650

Please sign in to comment.