Skip to content

Commit

Permalink
Merge pull request #1236 from DARMA-tasking/1232-collection-data
Browse files Browse the repository at this point in the history
1232 Implement Storable collection trait in support of CUDA streams
  • Loading branch information
lifflander authored Jan 31, 2021
2 parents 4c49014 + 688890b commit f7ce521
Show file tree
Hide file tree
Showing 12 changed files with 740 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set(
vrt/collection/staged_token
vrt/collection/listener
vrt/collection/invoke
vrt/collection/types/storage
vrt/collection/balance
vrt/collection/balance/baselb
vrt/collection/balance/hierarchicallb
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/migrate/migrate_handlers.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ template <typename ColT, typename IndexT>
// auto vc_raw_ptr = ::checkpoint::deserialize<ColT>(
// buf, col_t
// );
auto vc_elm_ptr = std::make_unique<ColT>(std::move(*msg->elm_));
auto vc_elm_ptr = std::unique_ptr<ColT>(msg->elm_);

auto const& migrate_status =
CollectionElmAttorney<ColT,IndexT>::migrateIn(
Expand Down
9 changes: 1 addition & 8 deletions src/vt/vrt/collection/migrate/migrate_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ struct MigrateMsg final : ::vt::Message {
range_(in_range), elm_(in_elm)
{ }

~MigrateMsg() {
if (elm_ and owns_elm_) {
delete elm_;
}
}

VrtElmProxy<ColT, IndexT> getElementProxy() const { return elm_proxy_; }
NodeType getFromNode() const { return from_; }
NodeType getToNode() const { return to_; }
Expand All @@ -83,8 +77,8 @@ struct MigrateMsg final : ::vt::Message {
MessageParentType::serialize(s);
s | elm_proxy_ | from_ | to_ | map_fn_ | range_;
if (s.isUnpacking()) {
// handler always takes ownership of this by constructing a unique_ptr
elm_ = new ColT{};
owns_elm_ = true;
}
s | *elm_;
}
Expand All @@ -95,7 +89,6 @@ struct MigrateMsg final : ::vt::Message {
NodeType to_ = uninitialized_destination;
HandlerType map_fn_ = uninitialized_handler;
IndexT range_;
bool owns_elm_ = false;
public:
ColT* elm_ = nullptr;
};
Expand Down
3 changes: 2 additions & 1 deletion src/vt/vrt/collection/types/migratable.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "vt/vrt/base/base.h"
#include "vt/vrt/collection/types/migrate_hooks.h"
#include "vt/vrt/collection/types/migratable.fwd.h"
#include "vt/vrt/collection/types/storage/storable.h"
#include "vt/vrt/collection/balance/lb_common.h"
#include "vt/vrt/collection/balance/elm_stats.h"

Expand All @@ -60,7 +61,7 @@ namespace balance {
struct NodeStats;
}

struct Migratable : MigrateHookBase {
struct Migratable : MigrateHookBase, storage::Storable {

Migratable();

Expand Down
1 change: 1 addition & 0 deletions src/vt/vrt/collection/types/migratable.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace vt { namespace vrt { namespace collection {
template <typename Serializer>
void Migratable::serialize(Serializer& s) {
MigrateHookBase::serialize(s);
storage::Storable::serialize(s);
s | stats_;
s | stats_elm_id_;
s | temp_elm_id_;
Expand Down
60 changes: 60 additions & 0 deletions src/vt/vrt/collection/types/storage/storable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
//@HEADER
// *****************************************************************************
//
// storable.cc
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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
*/

#include "vt/vrt/collection/types/storage/storable.h"

namespace vt { namespace vrt { namespace collection { namespace storage {

bool Storable::valExists(std::string const& str) const {
return map_.find(str) != map_.end();
}

void Storable::valRemove(std::string const& str) {
auto iter = map_.find(str);
if (iter != map_.end()) {
map_.erase(iter);
}
}

}}}} /* end namespace vt::vrt::collection::storage */
127 changes: 127 additions & 0 deletions src/vt/vrt/collection/types/storage/storable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
//@HEADER
// *****************************************************************************
//
// storable.h
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H
#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H

#include "vt/config.h"
#include "vt/vrt/collection/types/storage/store_elm.h"

#include <unordered_map>
#include <memory>

namespace vt { namespace vrt { namespace collection { namespace storage {

/**
* \struct Storable
*
* \brief Trait for collection elements to store values inside the collection
*/
struct Storable {

Storable() = default;

/**
* \brief Serializer
*
* \param[in] s the serializer
*/
template <typename SerializerT>
void serialize(SerializerT& s);

/**
* \brief Insert a new key/value pair
*
* \param[in] str the key
* \param[in] u the value
*/
template <typename U>
void valInsert(std::string const& str, U&& u);

/**
* \brief Get the value from a key
*
* \param[in] str the key
*
* \return the associated value
*/
template <typename U>
U& valGet(std::string const& str);

/**
* \brief Get the const value from a key
*
* \param[in] str the key
*
* \return the associated, const value
*/
template <typename U>
U const& valGet(std::string const& str) const;

/**
* \brief Check if a key exists
*
* \param[in] str the key
*
* \return whether it exists
*/
bool valExists(std::string const& str) const;

/**
* \brief Remove a key
*
* \param[in] str the key
*/
void valRemove(std::string const& str);

private:
/// Map of type-erased, stored values
std::unordered_map<std::string, std::unique_ptr<StoreElmBase>> map_;
};

}}}} /* end namespace vt::vrt::collection::storage */

#include "vt/vrt/collection/types/storage/storable.impl.h"

#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_H*/
86 changes: 86 additions & 0 deletions src/vt/vrt/collection/types/storage/storable.impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
//@HEADER
// *****************************************************************************
//
// storable.impl.h
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2019 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_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H
#define INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H

#include "vt/vrt/collection/types/storage/storable.h"

namespace vt { namespace vrt { namespace collection { namespace storage {

template <typename SerializerT>
void Storable::serialize(SerializerT& s) {
s | map_;
}

template <typename U>
void Storable::valInsert(std::string const& str, U&& u) {
map_.emplace(
std::piecewise_construct,
std::forward_as_tuple(str),
std::forward_as_tuple(
std::make_unique<StoreElm<typename std::decay<U>::type>>(
std::forward<U>(u)
)
)
);
}

template <typename U>
U& Storable::valGet(std::string const& str) {
vtAssert(valExists(str), "Key must exist in map");
auto iter = map_.find(str);
return iter->second->get<U>();
}

template <typename U>
U const& Storable::valGet(std::string const& str) const {
vtAssert(valExists(str), "Key must exist in map");
auto iter = map_.find(str);
return iter->second->get<U>();
}

}}}} /* end namespace vt::vrt::collection::storage */

#endif /*INCLUDED_VT_VRT_COLLECTION_TYPES_STORAGE_STORABLE_IMPL_H*/
Loading

0 comments on commit f7ce521

Please sign in to comment.