Skip to content

Commit

Permalink
#1554: DR: fix some bugs, start adding hint
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Nov 3, 2021
1 parent d39151d commit ac8efc0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
23 changes: 18 additions & 5 deletions src/vt/datarep/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@
#include "vt/configs/types/types_type.h"
#include "vt/configs/types/types_sentinels.h"

namespace vt { namespace datarep { namespace detail {
namespace vt { namespace datarep {

enum struct DataRepEnum : int8_t {
Normal = 0,
PersistentAcrossVersions = 1
};

namespace detail {

struct ReaderBase {};

Expand All @@ -59,31 +66,37 @@ struct DR_Base : ReaderBase {
: handle_(in_handle)
{ }

DR_Base(DataRepIDType in_handle, IndexT in_index, TagType in_tag)
: handle_(in_handle),
DR_Base(
DataRepIDType in_handle, IndexT in_index, TagType in_tag,
DataRepEnum in_hint = DataRepEnum::Normal
) : handle_(in_handle),
tag_(in_tag),
is_proxy_(true),
index_(in_index)
index_(in_index),
hint_(in_hint)
{ }

DataRepIDType getHandleID() const { return handle_; }
TagType getTag() const { return tag_; }
bool isProxy() const { return is_proxy_; }
IndexT getIndex() const { return index_; }
DataRepEnum getHint() const { return hint_; }

template <typename SerializerT>
void serialize(SerializerT& s) {
s | handle_
| tag_
| is_proxy_
| index_;
| index_
| hint_;
}

protected:
DataRepIDType handle_ = no_datarep;
TagType tag_ = no_tag;
bool is_proxy_ = false;
IndexT index_ = {};
DataRepEnum hint_ = DataRepEnum::Normal;
};

}}} /* end namespace vt::datarep::detail */
Expand Down
30 changes: 27 additions & 3 deletions src/vt/datarep/datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include <memory>
#include <unordered_map>
#include <set>

namespace vt { namespace datarep {

Expand All @@ -55,7 +56,9 @@ struct DataStoreBase {

template <typename T, typename IndexT>
struct DataStore final : DataStoreBase {
using VersionMapType = std::unordered_map<DataVersionType, std::shared_ptr<T>>;
using NodeSetType = std::set<NodeType>;
using VersionMapType = std::unordered_map<DataVersionType, std::shared_ptr<T>>;
using VersionNodeType = std::unordered_map<DataVersionType, NodeSetType>;

explicit DataStore(
bool in_is_master, IndexT idx, DataVersionType version,
Expand Down Expand Up @@ -92,23 +95,44 @@ struct DataStore final : DataStoreBase {
if (iter != cache_.end()) {
auto iter2 = iter->second.find(version);
if (iter2 != iter->second.end()) {
iter2->second.erase(iter2);
iter->second.erase(iter2);
}
if (iter->second.size() == 0) {
cache_.erase(iter);
}
}
}

void recordRequest(IndexT idx, DataVersionType version, NodeType requestor) {
request_nodes_[idx][version].insert(requestor);
}

NodeSetType const& getRequestors(IndexT idx, DataVersionType version) const {
auto iter = request_nodes_.find(idx);
if (iter != request_node_.end()) {
auto version_iter = iter->second.find(version);
if (version_iter != iter->second.end()) {
return version_iter->second;
}
}

std::set<NodeType> empty_set;
return empty_set;
}

bool hasVersion(IndexT idx, DataVersionType version) const {
auto iter = cache_.find(idx);
return iter != cache_.end() and
iter->second.find(version) != iter->second.end();
}

private:
/// Whether this is the master copy or not
bool is_master = false;
std::unordered_map<IndexT, VersionMapType> cache_ = {};
/// The actual data (either cached or the original copy)
std::unordered_map<IndexT, VersionMapType> cache_ = {};
/// Information about nodes that requested the data for each version
std::unordered_map<IndexT, VersionNodeType> request_nodes_ = {};
};

}} /* end namespace vt::datarep */
Expand Down
6 changes: 5 additions & 1 deletion src/vt/datarep/dr.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ struct DataReplicator : runtime::component::Component<DataReplicator> {

template <typename T, typename ProxyType>
DR<T, typename ProxyType::IndexType> makeIndexedHandle(
ProxyType proxy, TagType tag = no_tag
ProxyType proxy, DataRepEnum hint = DataRepEnum::Normal,
TagType tag = no_tag
);

template <typename T>
Expand Down Expand Up @@ -144,6 +145,9 @@ struct DataReplicator : runtime::component::Component<DataReplicator> {
);

private:
template <typename T, typename IndexT>
void recordAccess(detail::DR_Base<IndexT> dr_base, DataVersionType version);

template <typename T, typename IndexT>
T const& getDataRef(detail::DR_Base<IndexT> dr_base, DataVersionType version) const;

Expand Down
11 changes: 9 additions & 2 deletions src/vt/datarep/dr.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ DR<T> DataReplicator::makeHandle() {

template <typename T, typename ProxyType>
DR<T, typename ProxyType::IndexType> DataReplicator::makeIndexedHandle(
ProxyType proxy, TagType tag
ProxyType proxy, DataRepEnum hint, TagType tag
) {
using IndexType = typename ProxyType::IndexType;

Expand All @@ -90,7 +90,7 @@ DR<T, typename ProxyType::IndexType> DataReplicator::makeIndexedHandle(
);

using TagType = typename DR<T, IndexType>::DR_TAG_CONSTRUCT;
return DR<T, IndexType>{TagType{}, proxy_bits, index, tag};
return DR<T, IndexType>{TagType{}, proxy_bits, index, tag, hint};
}

template <typename T, typename ProxyType>
Expand Down Expand Up @@ -386,6 +386,13 @@ void DataReplicator::dataRequestHandler(
}
}

template <typename T, typename IndexT>
void DataReplicator::recordAccess(
detail::DR_Base<IndexT> dr_base, DataVersionType version
) {

}

}} /* end namespace vt::datarep */

#endif /*INCLUDED_VT_DATAREP_DR_IMPL_H*/
4 changes: 2 additions & 2 deletions src/vt/datarep/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ struct DR : detail::DR_Base<IndexT> {

DR(
DR_TAG_CONSTRUCT, DataRepIDType in_handle, IndexT in_index,
TagType in_tag = no_tag
) : detail::DR_Base<IndexT>(in_handle, in_index, in_tag)
TagType in_tag = no_tag, DataRepEnum in_hint = DataRepEnum::Normal
) : detail::DR_Base<IndexT>(in_handle, in_index, in_tag, in_hint)
{}

friend struct DataReplicator;
Expand Down
5 changes: 4 additions & 1 deletion src/vt/datarep/reader.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ namespace vt { namespace datarep {

template <typename T, typename IndexT>
void Reader<T, IndexT>::fetch(DataVersionType version) {
theDR()->requestData<T, IndexT>(*this, version, this);
version_ = version;
theDR()->requestData<T, IndexT>(*this, version_, this);
}

template <typename T, typename IndexT>
void Reader<T, IndexT>::release(DataVersionType version) {
data_ = nullptr;
version_ = -1;
}

template <typename T, typename IndexT>
std::shared_ptr<T const> Reader<T, IndexT>::get(DataVersionType version) const {
vtAssert(ready_, "Data must be ready to get it");
vtAssert(data_ != nullptr, "Must have data");
vtAssert(version_ == version, "Must have the right version");
return data_;
}

Expand Down

0 comments on commit ac8efc0

Please sign in to comment.