27 #ifndef LBANN_UTILS_SERIALIZATION_ROOTED_ARCHIVE_ADAPTOR_HPP_ 28 #define LBANN_UTILS_SERIALIZATION_ROOTED_ARCHIVE_ADAPTOR_HPP_ 30 #if !(defined __CUDACC__) 41 template <
typename ArchiveT, lbann::utils::WhenTextArchive<ArchiveT> = 1>
46 template <
typename ArchiveT, lbann::utils::WhenNotTextArchive<ArchiveT> = 1>
56 template <
typename OutputArchiveT>
58 :
public cereal::OutputArchive<RootedOutputArchiveAdaptor<OutputArchiveT>>
60 static_assert(lbann::utils::IsBuiltinArchive<OutputArchiveT>,
61 "At this time only built-in Cereal archives are supported.");
62 static_assert(lbann::utils::IsOutputArchive<OutputArchiveT>,
63 "The given archive type must be an \"output\" archive type.");
77 ar_(g.Rank() == root ? std::make_optional<archive_type>(os)
85 El::Int
root() const noexcept {
return root_; }
87 bool am_root() const noexcept {
return (this->root() == grid_->Rank()); }
91 if (name && this->am_root())
102 template <
typename T>
109 template <
typename T>
117 std::optional<archive_type>
ar_;
122 template <
typename InputArchiveT>
124 :
public cereal::InputArchive<RootedInputArchiveAdaptor<InputArchiveT>>
126 static_assert(lbann::utils::IsBuiltinArchive<InputArchiveT>,
127 "At this time only built-in Cereal archives are supported.");
128 static_assert(lbann::utils::IsInputArchive<InputArchiveT>,
129 "The given archive type must be an \"input\" archive type.");
143 ar_(g.Rank() == root ? std::make_optional<archive_type>(is)
151 El::Int
root() const noexcept {
return root_; }
153 bool am_root() const noexcept {
return (this->root() == grid_->Rank()); }
161 template <
typename T>
168 template <
typename T>
175 template <
typename T>
183 std::optional<archive_type>
ar_;
188 #ifdef LBANN_HAS_CEREAL_BINARY_ARCHIVES 189 using RootedBinaryInputArchive =
191 using RootedBinaryOutputArchive =
193 #endif // LBANN_HAS_CEREAL_BINARY_ARCHIVES 195 #ifdef LBANN_HAS_CEREAL_JSON_ARCHIVES 196 using RootedJSONInputArchive =
198 using RootedJSONOutputArchive =
200 #endif // LBANN_HAS_CEREAL_JSON_ARCHIVES 202 #ifdef LBANN_HAS_CEREAL_PORTABLE_BINARY_ARCHIVES 203 using RootedPortableBinaryInputArchive =
205 using RootedPortableBinaryOutputArchive =
207 #endif // LBANN_HAS_CEREAL_PORTABLE_BINARY_ARCHIVES 209 #ifdef LBANN_HAS_CEREAL_XML_ARCHIVES 210 using RootedXMLInputArchive =
212 using RootedXMLOutputArchive =
214 #endif // LBANN_HAS_CEREAL_XML_ARCHIVES 224 template <
typename OutputArchiveT,
typename DataT>
225 h2::meta::EnableWhen<std::is_arithmetic_v<DataT>,
void>
232 template <
typename OutputArchiveT>
240 template <
typename OutputArchiveT,
typename DataT>
243 NameValuePair<DataT>
const& nvp)
251 template <
typename InputArchiveT,
typename DataT>
252 h2::meta::EnableWhen<std::is_arithmetic_v<DataT>,
void>
256 static_assert(!std::is_same_v<DataT, char>,
257 "Don't be a basic char. " 258 "Apparently Hydrogen doesn't support them.");
261 El::mpi::Broadcast(val,
264 El::SyncInfo<El::Device::CPU>{});
267 template <
typename InputArchiveT>
274 El::mpi::Broadcast(val,
277 El::SyncInfo<El::Device::CPU>{});
282 template <
typename ArchiveT,
typename CharT,
typename TraitsT,
typename AllocT>
285 std::basic_string<CharT, TraitsT, AllocT>
const& str)
290 template <
typename ArchiveT,
typename CharT,
typename TraitsT,
typename AllocT>
292 std::basic_string<CharT, TraitsT, AllocT>& str)
295 auto str_len = str.size();
296 El::mpi::Broadcast(str_len,
299 El::SyncInfo<El::Device::CPU>{});
303 El::mpi::Broadcast(reinterpret_cast<El::byte*>(str.data()),
304 str_len *
sizeof(CharT),
307 El::SyncInfo<El::Device::CPU>{});
312 template <
class InputArchiveT,
class DataT>
315 NameValuePair<DataT>& nvp)
321 template <
class ArchiveT,
class T>
323 SizeTag<T>
const& tag)
328 template <
class ArchiveT,
class T>
333 El::mpi::Broadcast(tag.size,
336 El::SyncInfo<El::Device::CPU>{});
342 h2::meta::EnableWhen<
343 !std::is_arithmetic_v<T> &&
344 !::cereal::traits::has_minimal_base_class_serialization<
346 ::cereal::traits::has_minimal_output_serialization,
348 !::cereal::traits::has_minimal_output_serialization<T, ArchiveT>::value,
358 h2::meta::EnableWhen<
359 !std::is_arithmetic_v<T> &&
360 !::cereal::traits::has_minimal_base_class_serialization<
362 ::cereal::traits::has_minimal_output_serialization,
364 !::cereal::traits::has_minimal_output_serialization<T, ArchiveT>::value,
374 h2::meta::EnableWhen<
375 !std::is_arithmetic_v<T> &&
376 !::cereal::traits::has_minimal_base_class_serialization<
378 ::cereal::traits::has_minimal_input_serialization,
380 !::cereal::traits::has_minimal_input_serialization<T, ArchiveT>::value,
390 h2::meta::EnableWhen<
391 !std::is_arithmetic_v<T> &&
392 !::cereal::traits::has_minimal_base_class_serialization<
394 ::cereal::traits::has_minimal_input_serialization,
396 !::cereal::traits::has_minimal_input_serialization<T, ArchiveT>::value,
404 template <
typename ArchiveT,
409 std::basic_string<CharT, TraitsT, AllocatorT>
const&)
412 template <
typename ArchiveT,
417 std::basic_string<CharT, TraitsT, AllocatorT>
const&)
420 template <
typename ArchiveT,
425 std::basic_string<CharT, TraitsT, AllocatorT>
const&)
428 template <
typename ArchiveT,
433 std::basic_string<CharT, TraitsT, AllocatorT>
const&)
438 #ifdef LBANN_HAS_CEREAL_BINARY_ARCHIVES 439 CEREAL_REGISTER_ARCHIVE(
441 CEREAL_REGISTER_ARCHIVE(
443 CEREAL_SETUP_ARCHIVE_TRAITS(
446 #endif // LBANN_HAS_CEREAL_BINARY_ARCHIVES 448 #ifdef LBANN_HAS_CEREAL_JSON_ARCHIVES 449 CEREAL_REGISTER_ARCHIVE(
451 CEREAL_REGISTER_ARCHIVE(
453 CEREAL_SETUP_ARCHIVE_TRAITS(
456 #endif // LBANN_HAS_CEREAL_JSON_ARCHIVES 458 #ifdef LBANN_HAS_CEREAL_PORTABLE_BINARY_ARCHIVES 459 CEREAL_REGISTER_ARCHIVE(
461 CEREAL_REGISTER_ARCHIVE(
463 CEREAL_SETUP_ARCHIVE_TRAITS(
466 #endif // LBANN_HAS_CEREAL_PORTABLE_BINARY_ARCHIVES 468 #ifdef LBANN_HAS_CEREAL_XML_ARCHIVES 469 CEREAL_REGISTER_ARCHIVE(
471 CEREAL_REGISTER_ARCHIVE(
473 CEREAL_SETUP_ARCHIVE_TRAITS(
476 #endif // LBANN_HAS_CEREAL_XML_ARCHIVES 479 #endif // LBANN_UTILS_SERIALIZATION_ROOTED_ARCHIVE_ADAPTOR_HPP_
cereal::OutputArchive< ThisType_ > BaseType_
OutputArchiveT archive_type
bool am_root() const noexcept
void prologue_on_root(T const &data)
T & data(const cnpy::NpyArray &na, const std::vector< size_t > indices)
void save_on_root(T const &data)
El::Int root() const noexcept
void CEREAL_SAVE_FUNCTION_NAME(lbann::RootedOutputArchiveAdaptor< ArchiveT > &ar, SizeTag< T > const &tag)
void epilogue(lbann::RootedInputArchiveAdaptor< ArchiveT > &, std::basic_string< CharT, TraitsT, AllocatorT > const &)
void set_next_name(char const *name)
void epilogue_on_root(T const &data)
void set_next_name(ArchiveT &ar, char const *name)
void CEREAL_LOAD_FUNCTION_NAME(lbann::RootedInputArchiveAdaptor< ArchiveT > &ar, SizeTag< T > &tag)
void prologue(lbann::RootedInputArchiveAdaptor< ArchiveT > &, std::basic_string< CharT, TraitsT, AllocatorT > const &)
std::optional< archive_type > ar_
El::Grid const & grid() const noexcept
RootedOutputArchiveAdaptor(std::ostream &os, El::Grid const &g, El::Int root=0)