Skip to content

Commit

Permalink
#1052: epoch: re-write scopes properly embedded with propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Sep 23, 2020
1 parent 7f49d41 commit 40ebed6
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 84 deletions.
59 changes: 33 additions & 26 deletions src/vt/epoch/epoch.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ namespace vt { namespace epoch {
*
* w-1 .............. w-h-1 ...............w-h-c-1 ....................0
* | <EpochHeader> ... | <EpochCategory> ... | <Sequential Epoch ID> |
*
* *where* h = epoch_header_num_bits,
* c = epoch_category_num_bits,
* w = sizeof(EpochType) * 8
* n = sizeof(NodeType) ^ ^ ^
* | .... n .... | ..........|
* <NodeType> <SeqEpochID>
* | \
* *where* h = epoch_header_num_bits, | \
* c = epoch_category_num_bits,| \
* w = sizeof(EpochType) * 8 | \
* n = sizeof(NodeType) ^ 16 ^ 5 ^ [remainder] ^
* / |
* / |
* _______ |
* / \
* | .... n .... | ... scope ... | ...........|
* <NodeType> <EpochScopeType> <SeqEpochID>
*
* +++++++++++++++++++++++++++++++++++++++++++ Rooted Extended Layout ++
*
* <EpochHeader> = <IsRooted> <HasCategory> <IsScoped>
* ....3 bits... = ..bit 1.. ...bit 2... ..bit 3..
* <EpochHeader> = <IsRooted> <HasCategory>
* ....3 bits... = ..bit 1.. ...bit 2...
*
* =======================================================================
* \endverbatim
Expand All @@ -83,16 +87,13 @@ namespace vt { namespace epoch {
*/
enum struct eEpochHeader : int8_t {
RootedEpoch = 1,
CategoryEpoch = 2,
ScopedEpoch = 3
CategoryEpoch = 2
};

/// Number of bits for root flag
static constexpr BitCountType const epoch_root_num_bits = 1;
/// Number of bits for category flag
static constexpr BitCountType const epoch_hcat_num_bits = 1;
/// Number of bits for scope flag
static constexpr BitCountType const epoch_scop_num_bits = 1;

/**
* Important: if you add new types of epoch headers to the preceding enum, you
Expand Down Expand Up @@ -127,11 +128,25 @@ inline std::ostream& operator<<(std::ostream& os, eEpochCategory const& cat) {
*/
static constexpr BitCountType const epoch_category_num_bits = 2;

/// Holds a epoch scope ID (collectively generated)
using EpochScopeType = uint64_t;

/// The default, global epoch scope
static constexpr EpochScopeType const global_epoch_scope = 0;

/// The number of bits assigned for epoch scopes
static constexpr EpochScopeType const scope_bits = 5;

/// The limit on number of live scopes at a given time
static constexpr EpochScopeType const scope_limit = 1<<scope_bits;

/// The total number of bits remaining the sequential part of the \c EpochType
static constexpr BitCountType const epoch_seq_num_bits = sizeof(EpochType) * 8 -
(epoch_root_num_bits +
epoch_hcat_num_bits + epoch_scop_num_bits +
epoch_category_num_bits + node_num_bits);
epoch_hcat_num_bits +
epoch_category_num_bits +
node_num_bits +
scope_bits);

/**
* \brief Epoch layout enum to help with manipuating the bits
Expand All @@ -141,10 +156,10 @@ static constexpr BitCountType const epoch_seq_num_bits = sizeof(EpochType) * 8 -
*/
enum eEpochLayout {
EpochSequential = 0,
EpochNode = eEpochLayout::EpochSequential + epoch_seq_num_bits,
EpochScope = eEpochLayout::EpochSequential + epoch_seq_num_bits,
EpochNode = eEpochLayout::EpochScope + scope_bits,
EpochCategory = eEpochLayout::EpochNode + node_num_bits,
EpochScope = eEpochLayout::EpochCategory + epoch_category_num_bits,
EpochHasCategory = eEpochLayout::EpochScope + epoch_scop_num_bits,
EpochHasCategory = eEpochLayout::EpochCategory + epoch_category_num_bits,
EpochIsRooted = eEpochLayout::EpochHasCategory + epoch_hcat_num_bits,
EpochSentinelEnd = eEpochLayout::EpochIsRooted
};
Expand All @@ -159,14 +174,6 @@ static constexpr NodeType const default_epoch_node = uninitialized_destination;
static constexpr eEpochCategory const default_epoch_category =
eEpochCategory::NoCategoryEpoch;

/// Holds a epoch scope ID (collectively generated)
using EpochScopeType = uint64_t;

/// The default, global epoch scope
static constexpr EpochScopeType const global_epoch_scope = 0;

/// The limit on number of live scopes at a given time
static constexpr EpochScopeType const scope_limit = 1<<5;

}} //end namespace vt::epoch

Expand Down
40 changes: 22 additions & 18 deletions src/vt/epoch/epoch_manip.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "vt/config.h"
#include "vt/epoch/epoch.h"
#include "vt/epoch/epoch_scope.h"
#include "vt/termination/epoch_tags.h"
#include "vt/termination/interval/integral_set.h"
#include "vt/utils/bits/bits_common.h"
#include "vt/utils/bits/bits_packer.h"
Expand All @@ -70,6 +71,7 @@ namespace vt { namespace epoch {
* by setting the bit pattern.
*/
struct EpochManip : runtime::component::Component<EpochManip> {
using CapturedContextType = term::SuccessorEpochCapture;

EpochManip();

Expand Down Expand Up @@ -98,16 +100,6 @@ struct EpochManip : runtime::component::Component<EpochManip> {
*/
static bool hasCategory(EpochType const& epoch);

/**
* \brief Gets whether the epoch is a scoped epoch (specifically a
* epoch that is part of a collective scope)
*
* \param[in] epoch the epoch to operate on
*
* \return whether the \c epoch is a scoped epoch
*/
static bool isScope(EpochType const& epoch);

/**
* \brief Gets the \c eEpochCategory of a given epoch
*
Expand All @@ -131,10 +123,22 @@ struct EpochManip : runtime::component::Component<EpochManip> {
*
* \param[in] epoch the epoch to operate on
*
* \note This will include the scope bits which are composed at the top of the
* sequence ID bit field.
*
* \return the sequential number for an \c epoch
*/
static EpochType seq(EpochType const& epoch);

/**
* \brief Gets the scope for an epoch
*
* \param[in] epoch the epoch to operate on
*
* \return the epoch's scope
*/
static EpochScopeType getScope(EpochType const& epoch);

/*
* Epoch setters to manipulate the type and state of EpochType
*/
Expand All @@ -155,14 +159,6 @@ struct EpochManip : runtime::component::Component<EpochManip> {
*/
static void setHasCategory(EpochType& epoch, bool const has_cat );

/**
* \brief Set whether the \c epoch is a user epoch or not
*
* \param[in,out] epoch the epoch to modify
* \param[in] is_scoped whether to set the epoch as scoped or not
*/
static void setIsScope(EpochType& epoch, bool const is_scoped);

/**
* \brief Set the category for the \c epoch
*
Expand All @@ -187,6 +183,14 @@ struct EpochManip : runtime::component::Component<EpochManip> {
*/
static void setSeq(EpochType& epoch, EpochType const seq);

/**
* \brief Set the scope for an \c epoch
*
* \param[in,out] epoch the epoch to modify
* \param[in] scope the scope to set on the epoch
*/
static void setScope(EpochType& epoch, EpochScopeType const scope);

/*
* General (stateless) methods for creating a epoch with certain properties
* based on a current sequence number
Expand Down
11 changes: 7 additions & 4 deletions src/vt/epoch/epoch_manip_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ namespace vt { namespace epoch {
return BitPackerType::boolGetField<eEpochLayout::EpochHasCategory>(epoch);
}

/*static*/ bool EpochManip::isScope(EpochType const& epoch) {
return BitPackerType::boolGetField<eEpochLayout::EpochScope>(epoch);
}

/*static*/ eEpochCategory EpochManip::category(EpochType const& epoch) {
return BitPackerType::getField<
eEpochLayout::EpochCategory, epoch_category_num_bits, eEpochCategory
Expand All @@ -82,4 +78,11 @@ namespace vt { namespace epoch {
>(epoch);
}

/*static*/ EpochScopeType EpochManip::getScope(EpochType const& epoch) {
// constexpr EpochScopeType offset = epoch_seq_num_bits - scope_limit;
return BitPackerType::getField<
eEpochLayout::EpochScope, scope_bits, EpochScopeType
>(epoch);
}

}} /* end namespace vt::epoch */
16 changes: 7 additions & 9 deletions src/vt/epoch/epoch_manip_make.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ EpochManip::EpochManip()
EpochType new_epoch = 0;
bool const& has_category = category != eEpochCategory::NoCategoryEpoch;
EpochManip::setIsRooted(new_epoch, is_rooted);
EpochManip::setIsScope(new_epoch, scope != global_epoch_scope);

// Compose in the high bits of the sequence epoch ID a scope (only actually
// impacts the value if not global scope). Use the \c scope_limit to
// determine how many bits are reserved.
EpochManip::setScope(new_epoch, scope);

EpochManip::setHasCategory(new_epoch, has_category);
if (is_rooted) {
vtAssertExpr(root_node != uninitialized_destination);
Expand Down Expand Up @@ -123,14 +128,7 @@ EpochType EpochManip::nextSeq(EpochScopeType scope, bool is_collective) {
if (is_collective) {
auto& scope_map = scope_collective_;
if (scope_map.find(scope) == scope_map.end()) {
EpochType new_ep = first_epoch;
// Compose in the high bits of the sequence epoch ID a scope (only actually
// impacts the value if not global scope). Use the \c scope_limit to
// determine how many bits are reserved.
constexpr EpochScopeType scope_offset = epoch_seq_num_bits - scope_limit;
BitPackerType::setField<scope_offset, scope_limit>(new_ep, scope);
vtAssertExpr(scope != global_epoch_scope || new_ep == first_epoch);
scope_map[scope] = new_ep;
scope_map[scope] = first_epoch;
}
auto const seq = scope_map[scope];
scope_map[scope]++;
Expand Down
6 changes: 2 additions & 4 deletions src/vt/epoch/epoch_manip_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ void EpochManip::setHasCategory(EpochType& epoch, bool const has_cat) {
}

/*static*/
void EpochManip::setIsScope(EpochType& epoch, bool const is_scoped) {
BitPackerType::boolSetField<eEpochLayout::EpochScope,1,EpochType>(
epoch,is_scoped
);
void EpochManip::setScope(EpochType& epoch, EpochScopeType const scope) {
BitPackerType::setField<eEpochLayout::EpochScope,scope_bits>(epoch,scope);
}

/*static*/
Expand Down
19 changes: 16 additions & 3 deletions src/vt/termination/termination.cc
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,12 @@ void TerminationDetector::finishedEpoch(EpochType const& epoch) {
EpochType TerminationDetector::makeEpochRootedWave(
SuccessorEpochCapture successor, std::string const& label
) {
auto const epoch = theEpoch()->getNextRootedEpoch();
auto scope = epoch::global_epoch_scope;
if (successor != no_epoch) {
scope = epoch::EpochManip::getScope(scope);
}
auto const no_cat = epoch::eEpochCategory::NoCategoryEpoch;
auto const epoch = theEpoch()->getNextRootedEpoch(no_cat, scope);
initializeRootedWaveEpoch(epoch, successor, label);
return epoch;

Expand Down Expand Up @@ -1014,8 +1019,12 @@ void TerminationDetector::initializeRootedWaveEpoch(
EpochType TerminationDetector::makeEpochRootedDS(
SuccessorEpochCapture successor, std::string const& label
) {
auto scope = epoch::global_epoch_scope;
if (successor != no_epoch) {
scope = epoch::EpochManip::getScope(scope);
}
auto const ds_cat = epoch::eEpochCategory::DijkstraScholtenEpoch;
auto const epoch = theEpoch()->getNextRootedEpoch(ds_cat);
auto const epoch = theEpoch()->getNextRootedEpoch(ds_cat, scope);
initializeRootedDSEpoch(epoch, successor, label);
return epoch;
}
Expand Down Expand Up @@ -1102,7 +1111,11 @@ EpochType TerminationDetector::makeEpochCollective(
EpochType TerminationDetector::makeEpochCollective(
std::string const& label, SuccessorEpochCapture successor
) {
auto const epoch = theEpoch()->getNextCollectiveEpoch();
auto scope = epoch::global_epoch_scope;
if (successor != no_epoch) {
scope = epoch::EpochManip::getScope(scope);
}
auto const epoch = theEpoch()->getNextCollectiveEpoch(scope);
initializeCollectiveEpoch(epoch, label, successor);
return epoch;
}
Expand Down
Loading

0 comments on commit 40ebed6

Please sign in to comment.