Skip to content

Commit

Permalink
make ttg::buffer and device_coro's value_t serializable by boost
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev authored and devreal committed Jun 9, 2023
1 parent aeef798 commit 91e13e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/unit/device_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
#include "ttg.h"
#include "ttg/view.h"

#include "ttg/serialization.h"

#include "cuda_kernel.h"

struct value_t {
ttg::buffer<double> db; // TODO: rename
int quark;

template<typename Archive>
void ttg_serialize(Archive& ar) {
void serialize(Archive& ar, const unsigned int version) {
ar& quark;
ar& db; // input:
}
};

#ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
/* devicebuf is non-POD so provide serialization
* information for members not a devicebuf */
namespace madness::archive {
Expand All @@ -24,7 +27,7 @@ namespace madness::archive {
static inline void serialize(const Archive& ar, value_t& obj) { ar& obj.quark & obj.db; };
};
} // namespace madness::archive

#endif // TTG_SERIALIZATION_SUPPORTS_MADNESS

TEST_CASE("Device", "coro") {

Expand Down
19 changes: 19 additions & 0 deletions ttg/ttg/parsec/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,25 @@ struct buffer {

/* serialization support */

#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
template <typename Archive>
void serialize(Archive& ar, const unsigned int version) {
if constexpr (ttg::detail::is_output_archive_v<Archive>) {
std::size_t s = size();
ar& s;
assert(m_ttg_copy != nullptr); // only tracked objects allowed
m_ttg_copy->iovec_add(ttg::iovec{s*sizeof(T), current_device_ptr()});
} else {
std::size_t s;
ar & s;
/* initialize internal pointers and then reset */
reset(s);
assert(m_ttg_copy != nullptr); // only tracked objects allowed
m_ttg_copy->iovec_add(ttg::iovec{s*sizeof(T), current_device_ptr()});
}
}
#endif // TTG_SERIALIZATION_SUPPORTS_BOOST

#ifdef TTG_SERIALIZATION_SUPPORTS_CEREAL
template <class Archive>
std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, Archive> ||
Expand Down

0 comments on commit 91e13e8

Please sign in to comment.