Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#123 Implement memory footprint mode #124

Merged
merged 16 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
build/
CMakeFiles/

.dir-locals.el

*.a
*.cmake
*.tcl
2 changes: 1 addition & 1 deletion Dockerfile-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RUN \
cmake -GNinja $kokkos_cmake_str -Dgtest_DIR=$GTEST_BUILD/install -DGTEST_ROOT=$GTEST_BUILD/install -DCHECKPOINT_BUILD_TESTS:BOOL=1 -DCMAKE_INSTALL_PREFIX=$CHECKPOINT_BUILD/install -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC -Ddetector_DIR=$DETECTOR_BUILD/install $CHECKPOINT && \
ninja && \
ninja install && \
ninja test
ctest --output-on-failure

COPY $DETECTOR_BUILD/ $DETECTOR_BUILD
COPY $CHECKPOINT_BUILD/ $CHECKPOINT_BUILD
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# *checkpoint* => serialization and checkpointing library

![Docker Image CI](https://github.com/DARMA-tasking/checkpoint/workflows/Docker%20Image%20CI/badge.svg)
5 changes: 5 additions & 0 deletions src/checkpoint/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@
#include "checkpoint/traits/serializable_traits.h"

#include "checkpoint/container/array_serialize.h"
#include "checkpoint/container/chrono_serialize.h"
#include "checkpoint/container/enum_serialize.h"
#include "checkpoint/container/function_serialize.h"
#include "checkpoint/container/list_serialize.h"
#include "checkpoint/container/map_serialize.h"
#include "checkpoint/container/queue_serialize.h"
#include "checkpoint/container/raw_ptr_serialize.h"
#include "checkpoint/container/shared_ptr_serialize.h"
#include "checkpoint/container/string_serialize.h"
#include "checkpoint/container/tuple_serialize.h"
#include "checkpoint/container/vector_serialize.h"
Expand Down
10 changes: 10 additions & 0 deletions src/checkpoint/checkpoint_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ std::unique_ptr<T> deserialize(SerializedReturnType&& in);
template <typename T>
std::size_t getSize(T& target);

/**
* \brief Get memory footprint of \c target
*
* \param[in] target reference to \c T to measure footprint
*
* \return memory footprint of the \c target
*/
template <typename T>
std::size_t getMemoryFootprint(T& target);

/**
* \brief Serialize \c T to file with filename \c file
*
Expand Down
8 changes: 8 additions & 0 deletions src/checkpoint/checkpoint_api.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ std::size_t getSize(T& target) {
return dispatch::Standard::size<T, Sizer>(target);
}

template <typename T>
std::size_t getMemoryFootprint(T& target) {
return std::max(
dispatch::Standard::footprint<T, Footprinter>(target),
sizeof(target)
);
}

template <typename T>
void serializeToFile(T& target, std::string const& file) {
auto len = getSize<T>(target);
Expand Down
63 changes: 63 additions & 0 deletions src/checkpoint/container/chrono_serialize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
//@HEADER
// *****************************************************************************
//
// chrono_serialize.h
// DARMA Toolkit v. 1.0.0
// DARMA/checkpoint => Serialization Library
//
// Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/

#if !defined INCLUDED_CHECKPOINT_CONTAINER_CHRONO_SERIALIZE_H
#define INCLUDED_CHECKPOINT_CONTAINER_CHRONO_SERIALIZE_H

#include "checkpoint/common.h"

#include <chrono>

namespace checkpoint {

template <typename Serializer, typename Rep, typename Period>
void serialize(Serializer& s, std::chrono::duration<Rep, Period>& d) {
Rep r = d.count();
s | r;
d = std::chrono::duration<Rep, Period>(r);
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_CHRONO_SERIALIZE_H*/
6 changes: 5 additions & 1 deletion src/checkpoint/container/container_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ template <typename Serializer, typename ContainerT>
inline typename ContainerT::size_type
serializeContainerSize(Serializer& s, ContainerT& cont) {
typename ContainerT::size_type cont_size = cont.size();
s | cont_size;
if (s.isFootprinting()) {
s.countBytes(cont);
} else {
s | cont_size;
}
return cont_size;
}

Expand Down
84 changes: 84 additions & 0 deletions src/checkpoint/container/function_serialize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
//@HEADER
// *****************************************************************************
//
// function_serialize.h
// DARMA Toolkit v. 1.0.0
// DARMA/checkpoint => Serialization Library
//
// Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/

#if !defined INCLUDED_CHECKPOINT_CONTAINER_FUNCTION_SERIALIZE_H
#define INCLUDED_CHECKPOINT_CONTAINER_FUNCTION_SERIALIZE_H

#include "checkpoint/common.h"

#include <functional>

namespace checkpoint {

/**
* \brief Serialize function \c func
*
* Only footprinting mode is supported at the moment.
*
* \param[in] serializer serializer to use
* \param[in] func function to serialize
*/
template <typename SerializerT, typename Res, typename... ArgTypes>
void serialize(SerializerT& s, std::function<Res(ArgTypes...)>& fn) {
serializeFunction(s, fn);
}

template <
typename SerializerT,
typename Res,
typename... ArgTypes,
typename = std::enable_if_t<
std::is_same<
SerializerT,
checkpoint::Footprinter
>::value
>
>
void serializeFunction(SerializerT& s, std::function<Res(ArgTypes...)>& fn) {
s.countBytes(fn);
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_FUNCTION_SERIALIZE_H*/
81 changes: 81 additions & 0 deletions src/checkpoint/container/queue_serialize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
//@HEADER
// *****************************************************************************
//
// queue_serialize.h
// DARMA Toolkit v. 1.0.0
// DARMA/checkpoint => Serialization Library
//
// Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact darma@sandia.gov
//
// *****************************************************************************
//@HEADER
*/

#if !defined INCLUDED_CHECKPOINT_CONTAINER_QUEUE_SERIALIZE_H
#define INCLUDED_CHECKPOINT_CONTAINER_QUEUE_SERIALIZE_H

#include "checkpoint/common.h"

#include <queue>

namespace checkpoint {

template <typename Serializer, typename T>
void serialize(Serializer& s, const std::queue<T>& q) {
serializeQueue(s, q);
}

template <typename Serializer, typename T>
void serialize(Serializer& s, const std::priority_queue<T>& q) {
serializeQueue(s, q);
}

template <
typename SerializerT,
typename Q,
typename = std::enable_if_t<
std::is_same<
SerializerT,
checkpoint::Footprinter
>::value
>
>
void serializeQueue(SerializerT& s, const Q& q) {
s.countBytes(q);
s.contiguousBytes(nullptr, sizeof(typename Q::value_type), q.size());
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_QUEUE_SERIALIZE_H*/
Loading