-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1236 from DARMA-tasking/1232-collection-data
1232 Implement Storable collection trait in support of CUDA streams
- Loading branch information
Showing
12 changed files
with
740 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/ |
Oops, something went wrong.