Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2030: Cleanup location management code #2031

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/vt/serialization/sizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ struct MsgSizer<
MsgT,
typename std::enable_if_t<true
and ::vt::messaging::msg_defines_serialize_mode<MsgT>::value
and (::vt::messaging::msg_serialization_mode<MsgT>::supported
or ::vt::messaging::msg_serialization_mode<MsgT>::required)
// ::vt::messaging::has_own_serialize<MsgT>
and ::vt::messaging::msg_serialization_mode<MsgT>::required
>
> {
static std::size_t get(MsgT* msg) {
Expand Down
46 changes: 14 additions & 32 deletions src/vt/topos/location/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,53 +229,37 @@ struct EntityLocationCoord : LocationCoord {
*
* \param[in] id the entity ID
* \param[in] home_node home node for entity
* \param[in] m pointer to the message
* \param[in] m message shared pointer
*/
template <typename MessageT, ActiveTypedFnType<MessageT> *f>
void routeMsgHandler(
EntityID const& id, NodeType const& home_node, MessageT *m
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg
);

/**
* \brief Route a serialized message with a custom handler
* \brief Route a message with a custom handler where the element is local
*
* \param[in] id the entity ID
* \param[in] home_node home node for entity
* \param[in] msg pointer to the message
* \param[in] m message shared pointer
*/
template <typename MessageT, ActiveTypedFnType<MessageT> *f>
void routeMsgSerializeHandler(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> msg
);
template <typename MessageT>
void routeMsgHandlerLocal(MsgSharedPtr<MessageT> const& msg);

/**
* \brief Route a message to the default handler
*
* \param[in] id the entity ID
* \param[in] home_node home node for the entity
* \param[in] msg pointer to the message
* \param[in] serialize_msg whether it should be serialized (optional)
* \param[in] from_node the sending node (optional)
*/
template <typename MessageT>
void routeMsg(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> msg,
bool const serialize_msg = false,
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg,
NodeType from_node = uninitialized_destination
);

/**
* \brief Route a message to the default handler
*
* \param[in] id the entity ID
* \param[in] home_node home node for the entity
* \param[in] msg pointer to the message
*/
template <typename MessageT>
void routeMsgSerialize(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> msg
);

/**
* \internal \brief Route a message with non-eager protocol
*
Expand Down Expand Up @@ -357,7 +341,7 @@ struct EntityLocationCoord : LocationCoord {
* \return whether it is of eager size
*/
template <typename MessageT>
bool useEagerProtocol(MsgSharedPtr<MessageT> msg) const;
bool useEagerProtocol(MsgSharedPtr<MessageT> const& msg) const;

private:
/**
Expand Down Expand Up @@ -392,30 +376,28 @@ struct EntityLocationCoord : LocationCoord {
/**
* \internal \brief Route a message to destination with eager protocol
*
* \param[in] is_serialized whether it is serialized
* \param[in] id the entity ID
* \param[in] home_node the home node
* \param[in] msg the message to route
*/
template <typename MessageT>
void routeMsgEager(
bool const is_serialized, EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> msg
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg
);

/**
* \internal \brief Route a message to destination with rendezvous protocol
*
* \param[in] is_serialized whether it is serialized
* \param[in] id the entity ID
* \param[in] home_node the home node
* \param[in] to_node destination node
* \param[in] msg the message to route
*/
template <typename MessageT>
void routeMsgNode(
bool const is_serialized, EntityID const& id, NodeType const& home_node,
NodeType const& to_node, MsgSharedPtr<MessageT> msg
EntityID const& id, NodeType const& home_node, NodeType const& to_node,
MsgSharedPtr<MessageT> const& msg
);

/**
Expand Down
122 changes: 66 additions & 56 deletions src/vt/topos/location/location.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,37 @@ void EntityLocationCoord<EntityID>::clearCache() {
recs_.clearCache();
}

namespace detail {

template <typename MsgT, typename=void>
struct IsSerializable {
static constexpr bool const is_ser = false;
};

template <typename MsgT>
struct IsSerializable<
MsgT,
typename std::enable_if_t<true
and ::vt::messaging::msg_defines_serialize_mode<MsgT>::value
and ::vt::messaging::msg_serialization_mode<MsgT>::required
>
>
{
static constexpr bool const is_ser = true;
};

} /* end namespace detail */

template <typename EntityID>
template <typename MessageT>
bool EntityLocationCoord<EntityID>::useEagerProtocol(MsgSharedPtr<MessageT> msg) const {

bool const is_small = sizeof(*msg) < small_msg_max_size;
bool const is_serialized = msg->getSerialize();
// could change according to entity type or another criterion
return is_small and not is_serialized;
bool EntityLocationCoord<EntityID>::useEagerProtocol(
MsgSharedPtr<MessageT> const& msg
) const {
if (detail::IsSerializable<MessageT>::is_ser) {
return false;
} else {
return sizeof(*msg) < small_msg_max_size;
}
}

template <typename EntityID>
Expand Down Expand Up @@ -313,8 +336,8 @@ void EntityLocationCoord<EntityID>::insertPendingEntityAction(
template <typename EntityID>
template <typename MessageT>
void EntityLocationCoord<EntityID>::routeMsgEager(
bool const is_serialized, EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> msg
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg
) {
auto const& this_node = theContext()->getNode();
NodeType route_to_node = uninitialized_destination;
Expand All @@ -325,8 +348,8 @@ void EntityLocationCoord<EntityID>::routeMsgEager(
vt_debug_print(
normal, location,
"EntityLocationCoord: routeMsgEager: found={}, home_node={}, "
"route_to_node={}, is_serialized={}, id={}\n",
found, home_node, route_to_node, is_serialized, id
"route_to_node={}, id={}\n",
found, home_node, route_to_node, id
);

if (found) {
Expand Down Expand Up @@ -360,11 +383,11 @@ void EntityLocationCoord<EntityID>::routeMsgEager(
vt_debug_print(
normal, location,
"EntityLocationCoord: routeMsgEager: home_node={}, route_node={}, "
"is_serialized={}, id={}\n",
home_node, route_to_node, is_serialized, id
"id={}\n",
home_node, route_to_node, id
);

return routeMsgNode<MessageT>(is_serialized,id,home_node,route_to_node,msg);
return routeMsgNode<MessageT>(id, home_node, route_to_node, msg);
}

template <typename EntityID>
Expand Down Expand Up @@ -481,17 +504,17 @@ void EntityLocationCoord<EntityID>::sendEagerUpdate(
template <typename EntityID>
template <typename MessageT>
void EntityLocationCoord<EntityID>::routeMsgNode(
bool const is_serialized, EntityID const& id, NodeType const& home_node,
NodeType const& to_node, MsgSharedPtr<MessageT> msg
EntityID const& id, NodeType const& home_node, NodeType const& to_node,
MsgSharedPtr<MessageT> const& msg
) {
auto const& this_node = theContext()->getNode();
auto const epoch = theMsg()->getEpochContextMsg(msg);

vt_debug_print(
normal, location,
"EntityLocationCoord: routeMsgNode: to_node={}, this_node={}: inst={}, "
"is_serialized={}, home_node={}, id={}, ref={}, from={}, msg={}, epoch={:x}\n",
to_node, this_node, this_inst, is_serialized, home_node, id,
"home_node={}, id={}, ref={}, from={}, msg={}, epoch={:x}\n",
to_node, this_node, this_inst, home_node, id,
envelopeGetRef(msg->env), msg->getLocFromNode(), print_ptr(msg.get()),
epoch
);
Expand All @@ -512,8 +535,9 @@ void EntityLocationCoord<EntityID>::routeMsgNode(
// set the instance on the message to deliver to the correct manager
msg->setLocInst(this_inst);

auto m = msg;
// send to the node discovered by the location manager
theMsg()->sendMsg<MessageT, routedHandler>(to_node, msg);
theMsg()->sendMsg<MessageT, routedHandler>(to_node, m);
} else {
vt_debug_print(
normal, location,
Expand Down Expand Up @@ -609,7 +633,7 @@ void EntityLocationCoord<EntityID>::routeMsgNode(
* typically when an non-migrated registration occurs off the home
* node and messages are buffered, awaiting forwarding information.
*/
routeMsgNode<MessageT>(is_serialized,id_,home_node,resolved,msg);
routeMsgNode<MessageT>(id_, home_node, resolved,msg);
}
theMsg()->popEpoch(epoch);
theTerm()->consume(epoch);
Expand All @@ -630,55 +654,43 @@ void EntityLocationCoord<EntityID>::routeNonEagerAction(
template <typename EntityID>
template <typename MessageT, ActiveTypedFnType<MessageT> *f>
void EntityLocationCoord<EntityID>::routeMsgHandler(
EntityID const& id, NodeType const& home_node, MessageT *m
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg
) {
using auto_registry::HandlerManagerType;

auto handler = auto_registry::makeAutoHandler<MessageT,f>();

# if vt_check_enabled(trace_enabled)
HandlerManagerType::setHandlerTrace(
handler, envelopeGetTraceRuntimeEnabled(m->env)
handler, envelopeGetTraceRuntimeEnabled(msg->env)
);
# endif

m->setHandler(handler);
auto msg = promoteMsg(m);
return routeMsg<MessageT>(id,home_node,msg);
}

template <typename EntityID>
template <typename MessageT, ActiveTypedFnType<MessageT> *f>
void EntityLocationCoord<EntityID>::routeMsgSerializeHandler(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> m
) {
using auto_registry::HandlerManagerType;

auto handler = auto_registry::makeAutoHandler<MessageT,f>();
msg->setHandler(handler);

# if vt_check_enabled(trace_enabled)
HandlerManagerType::setHandlerTrace(
handler, envelopeGetTraceRuntimeEnabled(m->env)
);
# endif

m->setHandler(handler);
return routeMsg<MessageT>(id,home_node,m,true);
if (local_registered_.find(id) == local_registered_.end()) {
return routeMsg<MessageT>(id,home_node,msg);
} else {
return routeMsgHandlerLocal(msg);
}
}

template <typename EntityID>
template <typename MessageT>
void EntityLocationCoord<EntityID>::routeMsgSerialize(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> m
void EntityLocationCoord<EntityID>::routeMsgHandlerLocal(
MsgSharedPtr<MessageT> const& msg
) {
return routeMsg<MessageT>(id,home_node,m,true);
runnable::makeRunnable(msg, true, msg->getHandler(), theContext()->getNode())
.withTDEpochFromMsg()
.run();
}

template <typename EntityID>
template <typename MessageT>
void EntityLocationCoord<EntityID>::routeMsg(
EntityID const& id, NodeType const& home_node, MsgSharedPtr<MessageT> msg,
bool const serialize_msg, NodeType from_node
EntityID const& id, NodeType const& home_node,
MsgSharedPtr<MessageT> const& msg, NodeType from_node
) {
auto const from =
from_node == uninitialized_destination ? theContext()->getNode() :
Expand All @@ -688,7 +700,6 @@ void EntityLocationCoord<EntityID>::routeMsg(
msg->setEntity(id);
msg->setHomeNode(home_node);
msg->setLocFromNode(from);
msg->setSerialize(serialize_msg);

auto const msg_size = sizeof(*msg);
bool const use_eager = useEagerProtocol(msg);
Expand All @@ -697,24 +708,24 @@ void EntityLocationCoord<EntityID>::routeMsg(
vt_debug_print(
verbose, location,
"routeMsg: inst={}, home={}, msg_size={}, is_large_msg={}, eager={}, "
"serialize_msg={}, in_from={}, from={}, msg{}, msg from={}, epoch={:x}\n",
"in_from={}, from={}, msg{}, msg from={}, epoch={:x}\n",
this_inst, home_node, msg_size, msg_size > small_msg_max_size, use_eager,
serialize_msg, from_node, from, print_ptr(msg.get()), msg->getLocFromNode(),
from_node, from, print_ptr(msg.get()), msg->getLocFromNode(),
epoch
);

msg->setLocInst(this_inst);

if (use_eager) {
theMsg()->pushEpoch(epoch);
routeMsgEager<MessageT>(serialize_msg, id, home_node, msg);
routeMsgEager<MessageT>(id, home_node, msg);
theMsg()->popEpoch(epoch);
} else {
theTerm()->produce(epoch);
// non-eager protocol: get location first then send message after resolution
getLocation(id, home_node, [=](NodeType node) {
theMsg()->pushEpoch(epoch);
routeMsgNode<MessageT>(serialize_msg, id, home_node, node, msg);
routeMsgNode<MessageT>(id, home_node, node, msg);
theMsg()->popEpoch(epoch);
theTerm()->consume(epoch);
});
Expand Down Expand Up @@ -787,25 +798,24 @@ template <typename MessageT>
auto const entity_id = msg->getEntity();
auto const home_node = msg->getHomeNode();
auto const inst = msg->getLocInst();
auto const is_serialized = msg->getSerialize();
auto const from_node = msg->getLocFromNode();
auto const epoch = theMsg()->getEpochContextMsg(msg);

msg->incHops();

vt_debug_print(
verbose, location,
"routedHandler: msg={}, ref={}, loc_inst={}, is_serialized={}, id={}, from={}, "
"routedHandler: msg={}, ref={}, loc_inst={}, id={}, from={}, "
"epoch={:x}, hops={}, ask={}\n",
print_ptr(msg.get()), envelopeGetRef(msg->env), inst, is_serialized, entity_id,
print_ptr(msg.get()), envelopeGetRef(msg->env), inst, entity_id,
from_node, epoch, msg->getHops(), msg->getAskNode()
);

theTerm()->produce(epoch);
LocationManager::applyInstance<EntityLocationCoord<EntityID>>(
inst, [=](EntityLocationCoord<EntityID>* loc) {
theMsg()->pushEpoch(epoch);
loc->routeMsg(entity_id, home_node, msg, is_serialized, from_node);
loc->routeMsg(entity_id, home_node, msg, from_node);
theMsg()->popEpoch(epoch);
theTerm()->consume(epoch);
}
Expand Down
Loading