Skip to content

Commit

Permalink
#156: footprinting: use dispatch::serializeArray
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 21, 2020
1 parent 327947e commit e91b3dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/checkpoint/container/vector_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,6 @@ void serialize(Serializer& s, std::vector<bool, VectorAllocator>& vec) {
}
}

template <
typename SerializerT,
typename T,
typename VectorAllocator,
typename = std::enable_if_t<
not SerializableTraits<T, SerializerT>::has_serialize_function and
not SerializableTraits<T, SerializerT>::is_bytecopyable
>
>
void serialize(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
s.countBytes(vec);
s.addBytes(vec.capacity() * sizeof(T));
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_VECTOR_SERIALIZE_H*/
11 changes: 11 additions & 0 deletions src/checkpoint/dispatch/dispatch.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) {
}
}

template <
typename Serializer,
typename T,
typename = std::enable_if_t<
not SerializableTraits<T>::is_footprintable_v
>
>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) {
// count bytes
}

template <typename T>
buffer::ImplReturnType packBuffer(
T& target, SerialSizeType size, BufferObtainFnType fn
Expand Down
8 changes: 8 additions & 0 deletions src/checkpoint/traits/serializable_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ struct SerializableTraits {
*/
static constexpr auto const is_serializable =
has_serialize_function and is_constructible;

using is_footprintable = std::is_same<
std::size_t,
decltype(checkpoint::getMemoryFootprint(std::declval<T&>()))
>;

static constexpr auto const is_footprintable_v =
is_footprintable::value;
};

} // end namespace checkpoint
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <atomic>
#include <thread>
#include <checkpoint/checkpoint.h>
#include <checkpoint/traits/serializable_traits.h>

struct ompi_communicator_t;
struct ompi_group_t;
Expand Down Expand Up @@ -600,6 +601,12 @@ struct TestNoSerialize {
TEST_F(TestFootprinter, test_no_serialize) {
std::vector<TestNoSerialize> v(7);

std::cout << std::boolalpha;
std::cout << SerializableTraits<int>::is_footprintable_v << std::endl;
std::cout << SerializableTraits<Test1>::is_footprintable_v << std::endl;
std::cout << SerializableTraits<TestNoSerialize>::is_footprintable_v << std::endl;
// all 3 return 'true'

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(TestNoSerialize)
Expand Down

0 comments on commit e91b3dd

Please sign in to comment.