Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing the option of CUDA memory space only if CUDA is enabled #3423

Merged
merged 4 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 deletions source/adios2/common/ADIOSTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ 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)
CUDA ///< CUDA memory spaces
#endif
Host, ///< Host memory space
#ifdef ADIOS2_HAVE_CUDA
CUDA ///< CUDA memory spaces
#endif
};

/** Variable shape type identifier, assigned automatically from the signature of
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
anagainaru marked this conversation as resolved.
Show resolved Hide resolved
}

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