From a0c3df51b32c7776812fee58be81643c80412ecc Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Tue, 14 Jun 2022 13:18:35 -0700 Subject: [PATCH 1/6] #247: kokkos: add serializer for rank 0 --- src/checkpoint/container/view_serialize.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/checkpoint/container/view_serialize.h b/src/checkpoint/container/view_serialize.h index 7f9a5bbf..44b6bbbe 100644 --- a/src/checkpoint/container/view_serialize.h +++ b/src/checkpoint/container/view_serialize.h @@ -315,7 +315,9 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) // Construct a view with the layout and use operator= to propagate out if (s.isUnpacking()) { - if (dims == 1) { + if (dims == 0) { + view = ViewType{}; + } else if (dims == 1) { view = constructRankedView(label, std::make_tuple(layout)); } else if (dims == 2) { view = constructRankedView(label, std::make_tuple(layout)); @@ -337,6 +339,10 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) } } + if (dims == 0) { + return; + } + // Serialize the total number of elements in the Kokkos::View size_t num_elms = view.size(); s | num_elms; From 64e71acb8e92264c28205326680606537bb5a9ef Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Tue, 14 Jun 2022 13:18:48 -0700 Subject: [PATCH 2/6] #247: tests: write tests for rank 0 --- tests/unit/test_commons.h | 14 ++++++++------ .../unit/test_kokkos_serialize_dynrankview.cc | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_commons.h b/tests/unit/test_commons.h index 79a65542..6d5fe1d6 100644 --- a/tests/unit/test_commons.h +++ b/tests/unit/test_commons.h @@ -163,18 +163,20 @@ struct TestFactory { namespace { template std::unique_ptr serializeAny( - T& view, std::function compare + T& view, std::function compare = nullptr ) { using namespace checkpoint; auto ret = serialize(view); auto out_view = deserialize(ret->getBuffer()); auto const& out_view_ref = *out_view; - #if CHECKPOINT_USE_ND_COMPARE - compareND(view, out_view_ref); - #else - compare(view, out_view_ref); - #endif + if (compare) { + #if CHECKPOINT_USE_ND_COMPARE + compareND(view, out_view_ref); + #else + compare(view, out_view_ref); + #endif + } return out_view; } } //end namespace diff --git a/tests/unit/test_kokkos_serialize_dynrankview.cc b/tests/unit/test_kokkos_serialize_dynrankview.cc index 484d96f9..d0b3190d 100644 --- a/tests/unit/test_kokkos_serialize_dynrankview.cc +++ b/tests/unit/test_kokkos_serialize_dynrankview.cc @@ -44,12 +44,16 @@ #include "test_commons.h" #include "test_harness.h" +#include "test_kokkos_0d_commons.h" #include "test_kokkos_1d_commons.h" #include "test_kokkos_2d_commons.h" #include "test_kokkos_3d_commons.h" #include +template +struct KokkosDynRankViewTestEmpty : KokkosViewTest { }; + template struct KokkosDynRankViewTest1D : KokkosViewTest { }; @@ -59,10 +63,22 @@ struct KokkosDynRankViewTest2D : KokkosViewTest { }; template struct KokkosDynRankViewTest3D : KokkosViewTest { }; +TYPED_TEST_CASE_P(KokkosDynRankViewTestEmpty); TYPED_TEST_CASE_P(KokkosDynRankViewTest1D); TYPED_TEST_CASE_P(KokkosDynRankViewTest2D); TYPED_TEST_CASE_P(KokkosDynRankViewTest3D); +TYPED_TEST_P(KokkosDynRankViewTestEmpty, test_empty_any) { + using namespace checkpoint; + + using DataType = TypeParam; + using ViewType = Kokkos::DynRankView; + + ViewType in_view{}; + auto out_view = serializeAny(in_view); + EXPECT_EQ(out_view->rank(), unsigned(0)); +} + TYPED_TEST_P(KokkosDynRankViewTest1D, test_1d_any) { using namespace checkpoint; @@ -111,12 +127,14 @@ TYPED_TEST_P(KokkosDynRankViewTest3D, test_3d_any) { EXPECT_EQ(out_view->rank(), unsigned(3)); } +REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTestEmpty, test_empty_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest1D, test_1d_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest2D, test_2d_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest3D, test_3d_any); #if DO_UNIT_TESTS_FOR_VIEW +INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_empty , KokkosDynRankViewTestEmpty, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_1, KokkosDynRankViewTest1D, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_2, KokkosDynRankViewTest2D, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_3, KokkosDynRankViewTest3D, DynRankViewTestTypes, ); From e4f06bf54dccf240e0d45ca434f76ab44ebdd98a Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Thu, 16 Jun 2022 11:52:41 -0700 Subject: [PATCH 3/6] #247: view: fix rank 0 serializer with 1 element --- src/checkpoint/container/view_serialize.h | 14 +++++++------ .../unit/test_kokkos_serialize_dynrankview.cc | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/checkpoint/container/view_serialize.h b/src/checkpoint/container/view_serialize.h index 44b6bbbe..f13782fa 100644 --- a/src/checkpoint/container/view_serialize.h +++ b/src/checkpoint/container/view_serialize.h @@ -313,10 +313,16 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) serializeLayout(s, 7, layout_cur); } + // Serialize the total number of elements in the Kokkos::View + size_t num_elms = view.size(); + s | num_elms; + // Construct a view with the layout and use operator= to propagate out if (s.isUnpacking()) { - if (dims == 0) { + if (dims == 0 and num_elms == 0) { view = ViewType{}; + } else if (dims == 0) { + view = constructRankedView(label, std::make_tuple(layout)); } else if (dims == 1) { view = constructRankedView(label, std::make_tuple(layout)); } else if (dims == 2) { @@ -339,14 +345,10 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) } } - if (dims == 0) { + if (dims == 0 and num_elms == 0) { return; } - // Serialize the total number of elements in the Kokkos::View - size_t num_elms = view.size(); - s | num_elms; - // Serialize whether the view is contiguous or not. Is this required? bool is_contig = view.span_is_contiguous(); s | is_contig; diff --git a/tests/unit/test_kokkos_serialize_dynrankview.cc b/tests/unit/test_kokkos_serialize_dynrankview.cc index d0b3190d..55d4ffc5 100644 --- a/tests/unit/test_kokkos_serialize_dynrankview.cc +++ b/tests/unit/test_kokkos_serialize_dynrankview.cc @@ -54,6 +54,9 @@ template struct KokkosDynRankViewTestEmpty : KokkosViewTest { }; +template +struct KokkosDynRankViewTest0D : KokkosViewTest { }; + template struct KokkosDynRankViewTest1D : KokkosViewTest { }; @@ -64,6 +67,7 @@ template struct KokkosDynRankViewTest3D : KokkosViewTest { }; TYPED_TEST_CASE_P(KokkosDynRankViewTestEmpty); +TYPED_TEST_CASE_P(KokkosDynRankViewTest0D); TYPED_TEST_CASE_P(KokkosDynRankViewTest1D); TYPED_TEST_CASE_P(KokkosDynRankViewTest2D); TYPED_TEST_CASE_P(KokkosDynRankViewTest3D); @@ -79,6 +83,21 @@ TYPED_TEST_P(KokkosDynRankViewTestEmpty, test_empty_any) { EXPECT_EQ(out_view->rank(), unsigned(0)); } +TYPED_TEST_P(KokkosDynRankViewTest0D, test_0d_any) { + using namespace checkpoint; + + using DataType = TypeParam; + using ViewType = Kokkos::DynRankView; + + static constexpr size_t const N = 1; + + ViewType in_view("test", N); + + init1d(in_view); + auto out_view = serializeAny(in_view, &compare1d); + EXPECT_EQ(out_view->rank(), unsigned(0)); +} + TYPED_TEST_P(KokkosDynRankViewTest1D, test_1d_any) { using namespace checkpoint; @@ -128,6 +147,7 @@ TYPED_TEST_P(KokkosDynRankViewTest3D, test_3d_any) { } REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTestEmpty, test_empty_any); +REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest0D, test_0d_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest1D, test_1d_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest2D, test_2d_any); REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest3D, test_3d_any); @@ -135,6 +155,7 @@ REGISTER_TYPED_TEST_CASE_P(KokkosDynRankViewTest3D, test_3d_any); #if DO_UNIT_TESTS_FOR_VIEW INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_empty , KokkosDynRankViewTestEmpty, DynRankViewTestTypes, ); +INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_0, KokkosDynRankViewTest0D, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_1, KokkosDynRankViewTest1D, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_2, KokkosDynRankViewTest2D, DynRankViewTestTypes, ); INSTANTIATE_TYPED_TEST_CASE_P(test_dynrank_3, KokkosDynRankViewTest3D, DynRankViewTestTypes, ); From d856bf556b81c92ff79ca3747a6ee7b3c55e5740 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Thu, 16 Jun 2022 12:29:30 -0700 Subject: [PATCH 4/6] #247: view: create rank 0 view --- tests/unit/test_kokkos_serialize_dynrankview.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_kokkos_serialize_dynrankview.cc b/tests/unit/test_kokkos_serialize_dynrankview.cc index 55d4ffc5..f2ccbf00 100644 --- a/tests/unit/test_kokkos_serialize_dynrankview.cc +++ b/tests/unit/test_kokkos_serialize_dynrankview.cc @@ -91,7 +91,9 @@ TYPED_TEST_P(KokkosDynRankViewTest0D, test_0d_any) { static constexpr size_t const N = 1; - ViewType in_view("test", N); + ViewType in_view("test"); + + EXPECT_EQ(in_view.size(), N); init1d(in_view); auto out_view = serializeAny(in_view, &compare1d); From d2134f5f8e1453f5b0972b5c9a7d98711bba8e25 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Fri, 15 Jul 2022 19:32:03 -0400 Subject: [PATCH 5/6] #247: Factor out and name condition for uninitialized DynRankView --- src/checkpoint/container/view_serialize.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/checkpoint/container/view_serialize.h b/src/checkpoint/container/view_serialize.h index f13782fa..f1dc6da5 100644 --- a/src/checkpoint/container/view_serialize.h +++ b/src/checkpoint/container/view_serialize.h @@ -316,10 +316,10 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) // Serialize the total number of elements in the Kokkos::View size_t num_elms = view.size(); s | num_elms; - + bool is_uninitialized = dims == 0 and num_elms == 0; // Construct a view with the layout and use operator= to propagate out if (s.isUnpacking()) { - if (dims == 0 and num_elms == 0) { + if (is_uninitialized) { view = ViewType{}; } else if (dims == 0) { view = constructRankedView(label, std::make_tuple(layout)); @@ -345,7 +345,7 @@ inline void serialize_impl(SerializerT& s, Kokkos::DynRankView& view) } } - if (dims == 0 and num_elms == 0) { + if (is_uninitialized) { return; } From c9d6f9f33e940e5099ab69dca001c095cf6a3080 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Fri, 15 Jul 2022 19:33:26 -0400 Subject: [PATCH 6/6] #247: Check that serialized uninitialized DRV comes out uninitialized --- tests/unit/test_kokkos_serialize_dynrankview.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_kokkos_serialize_dynrankview.cc b/tests/unit/test_kokkos_serialize_dynrankview.cc index f2ccbf00..520b3c81 100644 --- a/tests/unit/test_kokkos_serialize_dynrankview.cc +++ b/tests/unit/test_kokkos_serialize_dynrankview.cc @@ -81,6 +81,7 @@ TYPED_TEST_P(KokkosDynRankViewTestEmpty, test_empty_any) { ViewType in_view{}; auto out_view = serializeAny(in_view); EXPECT_EQ(out_view->rank(), unsigned(0)); + EXPECT_EQ(out_view->size(), unsigned(0)); } TYPED_TEST_P(KokkosDynRankViewTest0D, test_0d_any) {