Skip to content

Commit

Permalink
sequencer: #4: initial implementation of virtual context sequencing
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Sep 29, 2017
1 parent 2c55ea2 commit b23abc1
Show file tree
Hide file tree
Showing 24 changed files with 902 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/collective/collective.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "trace.h"
#include "transport.h"
#include "context/context_vrtmanager.h"

#include "sequence/sequencer_headers.h"

#include <mpi.h>

Expand Down Expand Up @@ -109,6 +109,7 @@ CollectiveOps::finalizeRuntime() {
theRDMA = std::make_unique<rdma::RDMAManager>();
theParam = std::make_unique<param::Param>();
theSeq = std::make_unique<seq::Sequencer>();
theVrtSeq = std::make_unique<seq::SequencerVirtual>();
theSched = std::make_unique<sched::Scheduler>();
theLocMan = std::make_unique<location::LocationManager>();
theVrtCManager = std::make_unique<vrt::VrtContextManager>();
Expand Down
1 change: 1 addition & 0 deletions src/configs/features/features_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define debug_param(x) x
#define debug_handler(x) x
#define debug_sequence(x) x
#define debug_sequence_vrt(x) x
#define debug_trace(x) x
#define debug_location(x) x
#define debug_vrt(x) x
Expand Down
1 change: 1 addition & 0 deletions src/configs/features/features_featureswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
param, "parameterization", \
handler, "handler", \
sequence, "sequencer", \
sequence_vrt, "sequencer-vrt", \
trace, "trace", \
vrt, "virtual-context", \
location, "location" \
Expand Down
3 changes: 2 additions & 1 deletion src/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "pool.h"
#include "rdma.h"
#include "parameterization.h"
#include "sequencer.h"
#include "sequence/sequencer_headers.h"
#include "trace.h"
#include "scheduler.h"
#include "location.h"
Expand All @@ -27,6 +27,7 @@ std::unique_ptr<pool::Pool> thePool = nullptr;
std::unique_ptr<rdma::RDMAManager> theRDMA = nullptr;
std::unique_ptr<param::Param> theParam = nullptr;
std::unique_ptr<seq::Sequencer> theSeq = nullptr;
std::unique_ptr<seq::SequencerVirtual> theVrtSeq = nullptr;
std::unique_ptr<sched::Scheduler> theSched = nullptr;
std::unique_ptr<location::LocationManager> theLocMan = nullptr;

Expand Down
5 changes: 3 additions & 2 deletions src/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "active.h"
#include "event.h"
#include "termination.h"
#include "sequencer.h"
#include "sequencer_headers.h"

namespace vt { namespace sched {

Expand All @@ -26,10 +26,11 @@ bool Scheduler::schedulerImpl() {
bool const msg_sch = theMsg->scheduler();
bool const event_sch = theEvent->scheduler();
bool const seq_sch = theSeq->scheduler();
bool const vrt_seq_sch = theVrtSeq->scheduler();

checkTermSingleNode();

scheduled_work = msg_sch or event_sch or seq_sch;
scheduled_work = msg_sch or event_sch or seq_sch or vrt_seq_sch;

if (scheduled_work) {
is_idle = false;
Expand Down
29 changes: 29 additions & 0 deletions src/sequence/seq_action_virtual.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#if ! defined __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL__
#define __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL__

#include "config.h"
#include "seq_common.h"
#include "termination.h"

namespace vt { namespace seq {

template <typename MessageT, typename VcT>
struct ActionVirtual {
using ActionType = std::function<void(MessageT*, VcT*)>;
using CallableType = std::function<bool()>;

SeqType const seq_id;
ActionType const action;

ActionVirtual(SeqType const& in_seq_id, ActionType const& in_action);

void runAction(VcT* vc, MessageT* msg, bool const consume = true) const;
CallableType generateCallable(MessageT* msg, VcT* vc) const;
};

}} //end namespace vt::seq

#include "seq_action_virtual.impl.h"

#endif /* __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL__*/
43 changes: 43 additions & 0 deletions src/sequence/seq_action_virtual.impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#if ! defined __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL_IMPL__
#define __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL_IMPL__

#include "config.h"
#include "seq_common.h"
#include "seq_action.h"

namespace vt { namespace seq {

template <typename MessageT, typename VcT>
ActionVirtual<MessageT, VcT>::ActionVirtual(
SeqType const& in_seq_id, ActionType const& in_action
) : seq_id(in_seq_id), action(in_action)
{ }

template <typename MessageT, typename VcT>
void ActionVirtual<MessageT, VcT>::runAction(
VcT* vc, MessageT* msg, bool consume
) const {
auto const callable = [this, consume, msg, vc]() -> bool {
if (consume) {
theTerm->consume();
}
action(msg, vc);
return false;
};

contextualExecutionVirtual(seq_id, false, callable);
}

template <typename MessageT, typename VcT>
typename ActionVirtual<MessageT, VcT>::CallableType
ActionVirtual<MessageT, VcT>::generateCallable(MessageT* msg, VcT* vc) const {
return [msg,vc,this](){
runAction(vc, msg);
return false;
};
}

}} //end namespace vt::seq

#endif /* __RUNTIME_TRANSPORT_SEQ_ACTION_VIRTUAL_IMPL__*/
15 changes: 12 additions & 3 deletions src/sequence/seq_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "config.h"
#include "registry_function.h"
#include "context/context_vrt_fwd.h"

namespace vt { namespace seq {

Expand All @@ -22,12 +23,18 @@ using ForIndex = int32_t;
using UserSeqFunIndexType = std::function<void(ForIndex idx)>;
using FuncIndexType = UserSeqFunIndexType;

// Regular sequence triggers for active message handlers
template <typename MessageT>
using SeqNonMigratableTriggerType = std::function<void(MessageT*)>;

template <typename MessageT>
using SeqMigratableTriggerType = ActiveAnyFunctionType<MessageT>;

// Specialized virtual context sequence triggers for VC active message handlers
template <typename MessageT, typename VcT>
using SeqNonMigratableVrtTriggerType = std::function<void(MessageT*, VcT*)>;
template <typename MessageT, typename VcT>
using SeqMigratableVrtTriggerType = ActiveVCFunctionType<MessageT, VcT>;

using SeqContinuation = std::function<void()>;

enum class eSeqConstructType : int8_t {
Expand All @@ -46,13 +53,15 @@ enum class eSeqConstructType : int8_t {
using SeqCallableType = std::function<bool()>;

static constexpr SeqType const initial_seq = 0;
static SeqType next_seq_id = initial_seq;
static constexpr SeqType const no_seq = -1;

bool contextualExecution(
SeqType const& seq, bool const& is_sequenced, SeqCallableType&& callable
);
void enqueue_action(ActionType const& action);
bool contextualExecutionVirtual(
SeqType const& seq, bool const& is_sequenced, SeqCallableType&& callable
);
void enqueueAction(SeqType const& id, ActionType const& action);

static constexpr bool const seq_skip_queue = false;

Expand Down
67 changes: 67 additions & 0 deletions src/sequence/seq_matcher_virtual.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#if ! defined __RUNTIME_TRANSPORT_SEQ_MATCHER_VIRTUAL__
#define __RUNTIME_TRANSPORT_SEQ_MATCHER_VIRTUAL__

#include "config.h"
#include "registry_function.h"
#include "message.h"
#include "seq_common.h"
#include "seq_action.h"
#include "seq_state_virtual.h"
#include "seq_action_virtual.h"

#include <list>
#include <unordered_map>

namespace vt { namespace seq {

template <typename VcT, typename MsgT, ActiveVCFunctionType<MsgT, VcT> *f>
struct SeqMatcherVirtual {
using SeqActionType = ActionVirtual<MsgT, VcT>;
using MatchFuncType = ActiveVCFunctionType<MsgT, VcT>;
using SeqMsgStateType = SeqMsgStateVirtual<VcT, MsgT, f>;

template <typename T>
using SeqStateContType = typename SeqMsgStateType::template ContainerType<T>;

template <typename T>
using SeqStateTaggedContType = typename SeqMsgStateType::template TagContainerType<T>;

template <typename T>
static bool hasFirstElem(T& lst);
template <typename T>
static auto getFirstElem(T& lst);

template <typename T>
static bool hasMatchingAnyNoTag(SeqStateContType<T>& lst);
template <typename T>
static auto getMatchingAnyNoTag(SeqStateContType<T>& lst);

template <typename T>
static bool hasMatchingAnyTagged(
SeqStateTaggedContType<T>& tagged_lst, TagType const& tag
);
template <typename T>
static auto getMatchingAnyTagged(
SeqStateTaggedContType<T>& tagged_lst, TagType const& tag
);

static bool hasMatchingAction(TagType const& tag);
static SeqActionType getMatchingAction(TagType const& tag);

static bool hasMatchingMsg(TagType const& tag);
static MsgT* getMatchingMsg(TagType const& tag);

// Buffer messages and actions that do not match
static void bufferUnmatchedMessage(MsgT* msg, TagType const& tag);
template <typename FnT>
static void bufferUnmatchedAction(
FnT action, SeqType const& seq_id, TagType const& tag
);
};

}} //end namespace vt::seq

#include "seq_matcher_virtual.impl.h"

#endif /* __RUNTIME_TRANSPORT_SEQ_MATCHER_VIRTUAL__*/
Loading

0 comments on commit b23abc1

Please sign in to comment.