Skip to content

Commit

Permalink
#373: update View of Views usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Oct 24, 2024
1 parent 5cb4118 commit e0e8328
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
24 changes: 7 additions & 17 deletions src/checkpoint/container/view_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,33 @@
#define INCLUDED_SRC_CHECKPOINT_CONTAINER_VIEW_SERIALIZE_H

#include "checkpoint/common.h"
#include "checkpoint/serializers/serializers_headers.h"
#include "checkpoint/container/view_traits_extract.h"
#include "checkpoint/container/view_traverse_manual.h"
#include "checkpoint/container/view_traverse_ndim.h"

#if MAGISTRATE_KOKKOS_ENABLED

#include <Kokkos_Core.hpp>
#include <Kokkos_DynamicView.hpp>
#include <Kokkos_DynRankView.hpp>

#if KOKKOS_VERSION > 30699L
#define CHECKPOINT_KOKKOS_WITHOUTINIT Kokkos::WithoutInitializing,
#else
#define CHECKPOINT_KOKKOS_WITHOUTINIT
#endif

#if MAGISTRATE_KOKKOS_KERNELS_ENABLED
#include <Kokkos_StaticCrsGraph.hpp>
#include <KokkosSparse_CrsMatrix.hpp>
#endif

#include <array>
#include <cassert>
#include <tuple>
#include <type_traits>
#include <utility>
#include <cstdio>
#include <tuple>
#include <type_traits>

#define CHECKPOINT_DEBUG_ENABLED 0

// I am shutting the n-dim traversal off by default for now, due to the extra
// template complexity that needs to be tested more extensively on different
// compiler versions
#define CHECKPOINT_KOKKOS_NDIM_TRAVERSE 0
#if CHECKPOINT_KOKKOS_NDIM_TRAVERSE
#include "checkpoint/container/view_traverse_ndim.h"
#endif

#define CHECKPOINT_DEBUG_ENABLED 0

#if CHECKPOINT_DEBUG_ENABLED
#define DEBUG_PRINT_CHECKPOINT(ser, str, ...) do { \
Expand Down Expand Up @@ -192,7 +182,7 @@ inline void serialize(

// Kokkos::deep_copy between DynamicView instances is not yet implemented
#if 0
auto host_view = Kokkos::create_mirror_view(CHECKPOINT_KOKKOS_WITHOUTINIT view);
auto host_view = Kokkos::create_mirror_view(Kokkos::WithoutInitializing, view);
if (s.isPacking()) {
deepCopyWithLocalFence(host_view, view);
}
Expand Down Expand Up @@ -282,7 +272,7 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView<T,Args...>& view)
s | init;

if (init) {
auto host_view = Kokkos::create_mirror_view(CHECKPOINT_KOKKOS_WITHOUTINIT view);
auto host_view = Kokkos::create_mirror_view(Kokkos::WithoutInitializing, view);
using HostViewType = decltype(host_view);

if (s.isPacking()) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_kokkos_serialize_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
//@HEADER
*/

#include <Kokkos_Array.hpp>
#if MAGISTRATE_KOKKOS_ENABLED
#include <Kokkos_Array.hpp>

#include "test_commons.h"

Expand Down
29 changes: 18 additions & 11 deletions tests/unit/test_kokkos_serialize_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
//@HEADER
*/
#if MAGISTRATE_KOKKOS_ENABLED

#include "test_harness.h"
#include "test_commons.h"
#include <Kokkos_Core.hpp>

#include "test_kokkos_integration_commons.h"

Expand Down Expand Up @@ -89,16 +87,25 @@ struct KokkosViewOfVIewTest : KokkosBaseTest { };

TEST_F(KokkosViewOfVIewTest, test_view_of_view_init_1) {
using namespace checkpoint;
using ViewType = Kokkos::View<Kokkos::View<double*>[3]>;
using Kokkos::view_alloc;
using InnerViewType = Kokkos::View<double*>;
using OuterViewType = Kokkos::View<InnerViewType*>;
constexpr int size_outer = 3;

// Default construct
ViewType test_data = Kokkos::View<Kokkos::View<double*>[3]>("test");
test_data(0) = Kokkos::View<double*>();
test_data(1) = Kokkos::View<double*>();
test_data(2) = Kokkos::View<double*>();

auto ret = serialize<ViewType>(test_data);
deserialize<ViewType>(std::move(ret));
OuterViewType test_data = OuterViewType( view_alloc("outer", Kokkos::WithoutInitializing), size_outer);
new (&test_data(0)) InnerViewType(view_alloc("inner-0", Kokkos::WithoutInitializing), 4);
new (&test_data(1)) InnerViewType(view_alloc("inner-1", Kokkos::WithoutInitializing), 4);
new (&test_data(2)) InnerViewType(view_alloc("inner-2", Kokkos::WithoutInitializing), 4);

auto ret = serialize<OuterViewType>(test_data);
deserialize<OuterViewType>(std::move(ret));

Kokkos::fence();
for (int i = 0; i < size_outer; i++) {
test_data(i).~InnerViewType();
}
test_data = OuterViewType();
}

TEST_F(KokkosViewOfVIewTest, test_view_of_view_init_2) {
Expand Down

0 comments on commit e0e8328

Please sign in to comment.