1#ifndef __COMMON_HAS_SERIALIZE_HPP__
2#define __COMMON_HAS_SERIALIZE_HPP__
4#include "biocma_cst_config.hpp"
5#include <Kokkos_Core.hpp>
9#define IF_ENABLE_CEREAL_SERDE \
10 typename std::enable_if<AutoGenerated::FlagCompileTime::use_cereal_serde>::type
13 template <
typename,
typename T>
struct __has_serialize
15 static_assert(std::integral_constant<T, false>::value,
16 "Second template parameter needs to be of function type.");
21 template <
typename C,
typename Ret,
typename... Args>
struct __has_serialize<C, Ret(Args...)>
25 static constexpr auto check(T*) ->
26 typename std::is_same<decltype(std::declval<T>().serialize(std::declval<Args>()...)),
29 template <
typename>
static constexpr std::false_type check(...);
31 using type =
decltype(check<C>(0));
34 static constexpr bool value = type::value;
37template <
class C,
typename T>
consteval bool has_serialize()
39 return __has_serialize<C, void(T&)>::value;
45template <
class ViewType>
48 typename std::enable_if<ViewType::rank == 1 &&
49 AutoGenerated::FlagCompileTime::use_cereal_serde>::type>
51 template <
class Archive>
52 static void serialize(Archive& ar,
const ViewType& view, std::size_t n_used_elements)
54 using T =
typename ViewType::value_type;
55 auto temp_host = Kokkos::create_mirror_view_and_copy(Kokkos::DefaultHostExecutionSpace(), view);
56 std::vector<T> data_vector(temp_host.data(), temp_host.data() + n_used_elements);
60 template <
class Archive>
static void deserialize(Archive& ar, ViewType& view)
62 using T =
typename ViewType::value_type;
64 std::vector<T> data_vector;
67 view = ViewType(
"deser", data_vector.size());
69 auto tmpdata = ViewType(data_vector.data(), data_vector.size());
70 Kokkos::deep_copy(view, tmpdata);
75template <
class ViewType>
78 typename std::enable_if<ViewType::rank == 2 &&
79 AutoGenerated::FlagCompileTime::use_cereal_serde>::type>
81 template <
class Archive>
82 static void serialize(Archive& ar,
const ViewType& view, std::size_t n_used_elements)
84 (void)n_used_elements;
85 using T =
typename ViewType::value_type;
86 auto temp_host = Kokkos::create_mirror_view_and_copy(Kokkos::DefaultHostExecutionSpace(), view);
87 const auto rows = view.extent(0);
88 const auto cols = view.extent(1);
91 std::vector<T> data_vector(temp_host.data(), temp_host.data() + rows * cols);
95 template <
class Archive>
static void deserialize(Archive& ar, ViewType& view)
97 using T =
typename ViewType::value_type;
98 using L =
typename ViewType::array_layout;
101 std::vector<T> data_vector;
104 view = ViewType(
"deser", rows, cols);
105 auto tmpdata = ViewType(data_vector.data(), L(rows, cols));
107 Kokkos::deep_copy(view, tmpdata);
111template <
class Archive,
class ViewType>
void serialize_view(Archive& archive,
const ViewType& view)
117template <
class Archive,
class ViewType>
void deserialize_view(Archive& archive, ViewType& view)
static void serialize(Archive &ar, const ViewType &view, std::size_t n_used_elements)
Definition has_serialize.hpp:52
static void deserialize(Archive &ar, ViewType &view)
Definition has_serialize.hpp:60
static void serialize(Archive &ar, const ViewType &view, std::size_t n_used_elements)
Definition has_serialize.hpp:82
static void deserialize(Archive &ar, ViewType &view)
Definition has_serialize.hpp:95
Definition has_serialize.hpp:42