Skip to content

Commit 91e13e8

Browse files
evaleevdevreal
authored andcommitted
make ttg::buffer and device_coro's value_t serializable by boost
1 parent aeef798 commit 91e13e8

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tests/unit/device_coro.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
#include "ttg.h"
44
#include "ttg/view.h"
55

6+
#include "ttg/serialization.h"
7+
68
#include "cuda_kernel.h"
79

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

1214
template<typename Archive>
13-
void ttg_serialize(Archive& ar) {
15+
void serialize(Archive& ar, const unsigned int version) {
1416
ar& quark;
1517
ar& db; // input:
1618
}
1719
};
1820

21+
#ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
1922
/* devicebuf is non-POD so provide serialization
2023
* information for members not a devicebuf */
2124
namespace madness::archive {
@@ -24,7 +27,7 @@ namespace madness::archive {
2427
static inline void serialize(const Archive& ar, value_t& obj) { ar& obj.quark & obj.db; };
2528
};
2629
} // namespace madness::archive
27-
30+
#endif // TTG_SERIALIZATION_SUPPORTS_MADNESS
2831

2932
TEST_CASE("Device", "coro") {
3033

ttg/ttg/parsec/buffer.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,25 @@ struct buffer {
349349

350350
/* serialization support */
351351

352+
#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
353+
template <typename Archive>
354+
void serialize(Archive& ar, const unsigned int version) {
355+
if constexpr (ttg::detail::is_output_archive_v<Archive>) {
356+
std::size_t s = size();
357+
ar& s;
358+
assert(m_ttg_copy != nullptr); // only tracked objects allowed
359+
m_ttg_copy->iovec_add(ttg::iovec{s*sizeof(T), current_device_ptr()});
360+
} else {
361+
std::size_t s;
362+
ar & s;
363+
/* initialize internal pointers and then reset */
364+
reset(s);
365+
assert(m_ttg_copy != nullptr); // only tracked objects allowed
366+
m_ttg_copy->iovec_add(ttg::iovec{s*sizeof(T), current_device_ptr()});
367+
}
368+
}
369+
#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
370+
352371
#ifdef TTG_SERIALIZATION_SUPPORTS_CEREAL
353372
template <class Archive>
354373
std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, Archive> ||

0 commit comments

Comments
 (0)