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

Allow Put/Get functions to accept Kokkos Views #3254

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ adios_option(LIBPRESSIO "Enable support for LIBPRESSIO transforms" AUTO)
adios_option(MGARD "Enable support for MGARD transforms" AUTO)
adios_option(PNG "Enable support for PNG transforms" AUTO)
adios_option(CUDA "Enable support for Cuda" AUTO)
adios_option(Kokkos "Enable support for Kokkos" AUTO)
adios_option(MPI "Enable support for MPI" AUTO)
adios_option(DAOS "Enable support for DAOS" AUTO)
adios_option(DataMan "Enable support for DataMan" AUTO)
Expand Down Expand Up @@ -222,7 +223,7 @@ endif()


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

GenerateADIOSHeaderConfig(${ADIOS2_CONFIG_OPTS})
Expand Down
5 changes: 5 additions & 0 deletions bindings/CXX11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ set_property(TARGET adios2_cxx11 PROPERTY OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUF
target_link_libraries(adios2_cxx11 PRIVATE adios2_core adios2::thirdparty::pugixml)
target_compile_features(adios2_cxx11 INTERFACE ${ADIOS2_CXX11_FEATURES})

if(ADIOS2_HAVE_Kokkos)
target_link_libraries(adios2_cxx11 PUBLIC Kokkos::kokkos)
endif()

target_include_directories(adios2_cxx11
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down Expand Up @@ -80,6 +84,7 @@ install(
install(
FILES adios2/cxx11/ADIOS.h
adios2/cxx11/ADIOS.inl
adios2/cxx11/ADIOSMacros.h
adios2/cxx11/IO.h
adios2/cxx11/Group.h
adios2/cxx11/Variable.h
Expand Down
37 changes: 37 additions & 0 deletions bindings/CXX11/adios2/cxx11/ADIOSMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* ADIOSMacros.h : a set of helper macros used by the CXX binding
*
*/

#ifndef ADIOS2_ADIOSMACROS_CXX
#define ADIOS2_ADIOSMACROS_CXX

#ifdef ADIOS2_HAVE_KOKKOS
#include <Kokkos_Core.hpp>

#define ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, MEMORY_SPACE) \
MACRO(int32_t, MEMORY_SPACE) \
MACRO(uint32_t, MEMORY_SPACE) \
MACRO(int64_t, MEMORY_SPACE) \
MACRO(uint64_t, MEMORY_SPACE) \
MACRO(float, MEMORY_SPACE) \
MACRO(double, MEMORY_SPACE)

#ifdef KOKKOS_ENABLE_CUDA
#define ADIOS2_FOREACH_KOKKOS_TYPE_2ARGS(MACRO) \
ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, Kokkos::HostSpace) \
ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, Kokkos::CudaSpace) \
ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, Kokkos::CudaHostPinnedSpace) \
ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, Kokkos::CudaUVMSpace)

#else
#define ADIOS2_FOREACH_KOKKOS_TYPE_2ARGS(MACRO) \
ADIOS2_KOKKOS_MEMORY_SPACE(MACRO, Kokkos::HostSpace)
#endif /* KOKKOS_ENABLE_CUDA */

#endif /* ADIOS2_HAVE_KOKKOS */

#endif /* ADIOS2_ADIOSMACROS_CXX */
13 changes: 13 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "Engine.h"
#include "ADIOSMacros.h"
#include "Engine.tcc"

#include "adios2/core/Engine.h"
Expand Down Expand Up @@ -344,6 +345,18 @@ Engine::AllStepsBlocksInfo(const VariableNT &variable) const
return ret;
}

#ifdef ADIOS2_HAVE_KOKKOS
#define declare_template_instantiation(T, MemSpace) \
template void Engine::Put<T, MemSpace>( \
Variable<T>, Kokkos::View<T *, MemSpace>, const Mode); \
\
template void Engine::Get<T, MemSpace>( \
Variable<T>, Kokkos::View<T *, MemSpace>, const Mode);

ADIOS2_FOREACH_KOKKOS_TYPE_2ARGS(declare_template_instantiation)
#undef declare_template_instantiation
#endif

#define declare_template_instantiation(T) \
template void Engine::Put<T>(Variable<T>, const T *, const Mode); \
template void Engine::Put<T>(const std::string &, const T *, const Mode); \
Expand Down
15 changes: 15 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "adios2/common/ADIOSMacros.h"
#include "adios2/common/ADIOSTypes.h"

#ifdef ADIOS2_HAVE_KOKKOS
#include <Kokkos_Core_fwd.hpp>
#endif

namespace adios2
{

Expand Down Expand Up @@ -211,6 +215,17 @@ class Engine
* collective call and can only be called between Begin/EndStep pairs. */
void PerformDataWrite();

#ifdef ADIOS2_HAVE_KOKKOS
/** Get and Put functions for Kokkos buffers */
template <class T, class MemSpace>
void Put(Variable<T> variable, Kokkos::View<T *, MemSpace> data,
const Mode launch = Mode::Deferred);

template <class T, class MemSpace>
void Get(Variable<T> variable, Kokkos::View<T *, MemSpace> data,
const Mode launch = Mode::Deferred);
#endif

/**
* Get data associated with a Variable from the Engine
* @param variable contains variable metadata information
Expand Down
28 changes: 28 additions & 0 deletions bindings/CXX11/adios2/cxx11/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ void Engine::Put(const std::string &variableName, const T &datum,
launch);
}

#ifdef ADIOS2_HAVE_KOKKOS
template <class T, class MemSpace>
void Engine::Put(Variable<T> variable, Kokkos::View<T *, MemSpace> data,
const Mode launch)
{
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Put");
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Put");
m_Engine->Put(*variable.m_Variable,
reinterpret_cast<const IOType *>(data.data()), launch);
}
#endif

template <class T>
void Engine::Get(Variable<T> variable, T *data, const Mode launch)
{
Expand Down Expand Up @@ -234,6 +248,20 @@ void Engine::Get(Variable<T> variable, T **data) const
return;
}

#ifdef ADIOS2_HAVE_KOKKOS
template <class T, class MemSpace>
void Engine::Get(Variable<T> variable, Kokkos::View<T *, MemSpace> data,
const Mode launch)
{
adios2::helper::CheckForNullptr(variable.m_Variable,
"for variable in call to Engine::Get");
using IOType = typename TypeInfo<T>::IOType;
adios2::helper::CheckForNullptr(m_Engine, "in call to Engine::Get");
m_Engine->Get(*variable.m_Variable, reinterpret_cast<IOType *>(data.data()),
launch);
}
#endif

template <class T>
std::map<size_t, std::vector<typename Variable<T>::Info>>
Engine::AllStepsBlocksInfo(const Variable<T> variable) const
Expand Down
12 changes: 12 additions & 0 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ if(CMAKE_CUDA_COMPILER AND CUDAToolkit_FOUND)
set(ADIOS2_HAVE_CUDA TRUE)
endif()

# Kokkos
if(ADIOS2_USE_Kokkos)
if(ADIOS2_USE_Kokkos STREQUAL AUTO)
find_package(Kokkos QUIET)
else()
find_package(Kokkos REQUIRED)
endif()
endif()
if(Kokkos_FOUND)
set(ADIOS2_HAVE_Kokkos TRUE)
endif()

# Fortran
if(ADIOS2_USE_Fortran STREQUAL AUTO)
include(CheckLanguage)
Expand Down