From 402274672e9656ffe4dd67e10fea922ddd5e1bb8 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Wed, 31 Oct 2018 22:22:25 -0700 Subject: [PATCH] #1: kokkos: impleemnt serialization for DynamicView --- src/container/view_serialize.h | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/container/view_serialize.h b/src/container/view_serialize.h index dbfdd588..030502e3 100644 --- a/src/container/view_serialize.h +++ b/src/container/view_serialize.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -158,6 +159,66 @@ inline void serializeLayout(SerdesT& s, int dim, Kokkos::LayoutRight& layout) { } } +// template +// using DynamicViewType = Kokkos::Experimental::DynamicView; + +template +inline std::string serializeViewLabel(SerializerT& s, ViewT& view) { + static constexpr auto const is_managed = ViewT::traits::is_managed; + + // Serialize the label of the view + std::string view_label = view.label(); + if (is_managed) { + s | view_label; + } else { + assert(0 && "Unmanaged not handled currently"); + } + + return view_label; +} + +template +inline void serialize( + SerializerT& s, Kokkos::Experimental::DynamicView& view +) { + using ViewType = Kokkos::Experimental::DynamicView; + + // serialize the label + auto const label = serializeViewLabel(s,view); + + std::cout << "label:" << label << std::endl; + + // serialize the min chunk size and extent which is used to recreate this + std::size_t chunk_size = 0; + std::size_t max_extent = 0; + std::size_t view_size = 0; + + if (!s.isUnpacking()) { + chunk_size = view.chunk_size(); + max_extent = view.allocation_extent(); + view_size = view.size(); + } + + s | chunk_size; + s | max_extent; + s | view_size; + + // std::cout << "chunk_size:" << chunk_size << std::endl; + // std::cout << "max_extent:" << max_extent << std::endl; + // std::cout << "view_size:" << view_size << std::endl; + + if (s.isUnpacking()) { + unsigned min_chunk_size = static_cast(chunk_size); + unsigned max_alloc_extent = static_cast(max_extent); + view = apply( + label, nullptr, std::make_tuple(min_chunk_size,max_alloc_extent) + ); + view.resize_serial(view_size); + } + + TraverseManual::apply(s,view); +} + template inline void serialize(SerializerT& s, Kokkos::View& view) { using ViewType = Kokkos::View;