Skip to content

Commit

Permalink
Added support for PortModules. (#1201)
Browse files Browse the repository at this point in the history
* Added support for PortModules.

Also made some fixes to serialization:
- Made string* serializable
- Changed base serialize function to handle nullptrs
- Added new serialization tests for pointers to pod.

---------

Co-authored-by: @bpswenson
  • Loading branch information
feldergast authored Feb 5, 2025
1 parent 969f846 commit 1d2562c
Show file tree
Hide file tree
Showing 42 changed files with 2,465 additions and 80 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ WhitespaceSensitiveMacros:
- SST_ELI_REGISTER_SUBCOMPONENT_DERIVED
- SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API
- SST_ELI_REGISTER_REALTIME_ACTION
- SST_ELI_REGISTER_PORTMODULE
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
Expand Down
2 changes: 2 additions & 0 deletions src/sst/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ nobase_dist_sst_HEADERS = \
output.h \
params.h \
pollingLinkQueue.h \
portModule.h \
profile.h \
profile/profiletool.h \
profile/clockHandlerProfileTool.h \
Expand Down Expand Up @@ -203,6 +204,7 @@ sst_core_sources = \
output.cc \
params.cc \
pollingLinkQueue.cc \
portModule.cc \
profile/profiletool.cc \
profile/clockHandlerProfileTool.cc \
profile/eventHandlerProfileTool.cc \
Expand Down
25 changes: 16 additions & 9 deletions src/sst/core/activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ class Activity : public SST::Core::MemPoolItem
virtual void printTrackingInfo(const std::string& UNUSED(header), Output& UNUSED(out)) const {}
#endif

/** Set a new Queue order */
void setQueueOrder(uint64_t order) { queue_order = order; }

virtual void copyAllDeliveryInfo(const Activity* act)
{
delivery_time = act->delivery_time;
priority_order = act->priority_order;
queue_order = act->queue_order;
}

protected:
/** Set the priority of the Activity */
void setPriority(uint64_t priority) { priority_order = (priority_order & 0x00000000FFFFFFFFul) | (priority << 32); }
Expand All @@ -197,6 +207,7 @@ class Activity : public SST::Core::MemPoolItem
return buf.str();
}


// Function used by derived classes to serialize data members.
// This class is not serializable, because not all class that
// inherit from it need to be serializable.
Expand All @@ -206,24 +217,20 @@ class Activity : public SST::Core::MemPoolItem
ser& priority_order;
ser& queue_order;
}
ImplementVirtualSerializable(SST::Activity)


/** Set a new Queue order */
void setQueueOrder(uint64_t order)
{
queue_order = order;
}
ImplementVirtualSerializable(SST::Activity);

private:
// Data members
SimTime_t delivery_time;

// This will hold both the priority (high bits) and the link order
// (low_bits)
uint64_t priority_order;
uint64_t priority_order;

// Used for TimeVortex implementations that don't naturally keep
// the insertion order
uint64_t queue_order;
uint64_t queue_order;
};

} // namespace SST
Expand Down
57 changes: 54 additions & 3 deletions src/sst/core/baseComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sst/core/factory.h"
#include "sst/core/link.h"
#include "sst/core/linkMap.h"
#include "sst/core/portModule.h"
#include "sst/core/profile/clockHandlerProfileTool.h"
#include "sst/core/profile/eventHandlerProfileTool.h"
#include "sst/core/serialization/serialize.h"
Expand Down Expand Up @@ -88,6 +89,11 @@ BaseComponent::~BaseComponent()
"Warning: BaseComponent destructor failed to remove ComponentInfo from parent.\n");
}
}

// Delete any portModules
for ( auto port : portModules ) {
delete port;
}
}

void
Expand Down Expand Up @@ -221,7 +227,7 @@ BaseComponent::isPortConnected(const std::string& name) const
// child and remove it from my linkmap. The child will insert it into
// their link map.
Link*
BaseComponent::getLinkFromParentSharedPort(const std::string& port)
BaseComponent::getLinkFromParentSharedPort(const std::string& port, std::vector<ConfigPortModule>& port_modules)
{
LinkMap* myLinks = my_info->getLinkMap();

Expand All @@ -237,6 +243,16 @@ BaseComponent::getLinkFromParentSharedPort(const std::string& port)
// it from my link map and return it to the child.
if ( !tmp->isConfigured() ) {
myLinks->removeLink(port);
// Need to see if there are any associated PortModules
if ( my_info->portModules != nullptr ) {
auto it = my_info->portModules->find(port);
if ( it != my_info->portModules->end() ) {
// Found PortModules, swap them into
// port_modules and remove from my map
port_modules.swap(it->second);
my_info->portModules->erase(it);
}
}
return tmp;
}
}
Expand All @@ -246,7 +262,9 @@ BaseComponent::getLinkFromParentSharedPort(const std::string& port)
// parent shared with me and if so, call
// getLinkFromParentSharedPort on them

if ( my_info->sharesPorts() ) { return my_info->parent_info->component->getLinkFromParentSharedPort(port); }
if ( my_info->sharesPorts() ) {
return my_info->parent_info->component->getLinkFromParentSharedPort(port, port_modules);
}
else {
return nullptr;
}
Expand All @@ -266,7 +284,8 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
// with parents if sharing is turned on
if ( nullptr == tmp ) {
if ( my_info->sharesPorts() ) {
tmp = my_info->parent_info->component->getLinkFromParentSharedPort(name);
std::vector<ConfigPortModule> port_modules;
tmp = my_info->parent_info->component->getLinkFromParentSharedPort(name, port_modules);
// If I got a link from my parent, I need to put it in my
// link map
if ( nullptr != tmp ) {
Expand All @@ -277,6 +296,15 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
myLinks->insertLink(name, tmp);
// Need to set the link's defaultTimeBase to nullptr
tmp->setDefaultTimeBase(nullptr);

// Need to see if I got any port_modules, if so, need
// to add them to my_info->portModules
if ( port_modules.size() > 0 ) {
if ( nullptr == my_info->portModules ) {
my_info->portModules = new std::map<std::string, std::vector<ConfigPortModule>>();
}
(*my_info->portModules)[name].swap(port_modules);
}
}
}
}
Expand All @@ -301,6 +329,29 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
if ( tool->profileSends() ) tmp->attachTool(tool, mdata);
}
}

// Check for PortModules
if ( my_info->portModules != nullptr ) {
auto it = my_info->portModules->find(name);
if ( it != my_info->portModules->end() ) {
EventHandlerMetaData mdata(my_info->getID(), getName(), getType(), name);
for ( auto& portModule : it->second ) {
auto* pm = Factory::getFactory()->CreateWithParams<PortModule>(
portModule.type, portModule.params, portModule.params);
pm->setComponent(this);
if ( pm->installOnSend() ) tmp->attachTool(pm, mdata);
if ( pm->installOnReceive() ) {
if ( handler )
handler->attachInterceptTool(pm, mdata);
else
fatal(
CALL_INFO_LONG, 1, "ERROR: Trying to install a receive PortModule on a Polling Link\n");
}
portModules.push_back(pm);
}
}
}

if ( nullptr != time_base )
tmp->setDefaultTimeBase(time_base);
else
Expand Down
32 changes: 23 additions & 9 deletions src/sst/core/baseComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sst/core/event.h"
#include "sst/core/factory.h"
#include "sst/core/oneshot.h"
#include "sst/core/portModule.h"
#include "sst/core/profile/componentProfileTool.h"
#include "sst/core/serialization/serializable_base.h"
#include "sst/core/serialization/serialize.h"
Expand Down Expand Up @@ -145,15 +146,27 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
/** Return the base simulation Output class instance */
Output& getSimulationOutput() const;

/** return the time since the simulation began in units specified by
the parameter.
@param tc TimeConverter specifying the units */
SimTime_t getCurrentSimTime(TimeConverter* tc) const;
/** return the time since the simulation began in the default timebase */
/**
Return the simulated time since the simulation began in units specified by
the parameter.
@param tc TimeConverter specifying the units
*/
SimTime_t getCurrentSimTime(TimeConverter* tc) const;

/**
Return the simulated time since the simulation began in the
default timebase
*/
inline SimTime_t getCurrentSimTime() const { return getCurrentSimTime(my_info->defaultTimeBase); }
/** return the time since the simulation began in timebase specified
@param base Timebase frequency in SI Units */
SimTime_t getCurrentSimTime(const std::string& base) const;

/**
Return the simulated time since the simulation began in
timebase specified
@param base Timebase frequency in SI Units
*/
SimTime_t getCurrentSimTime(const std::string& base) const;

/** Utility function to return the time since the simulation began in nanoseconds */
SimTime_t getCurrentSimTimeNano() const;
Expand Down Expand Up @@ -901,10 +914,11 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
std::vector<Clock::HandlerBase*> clock_handlers;

void addSelfLink(const std::string& name);
Link* getLinkFromParentSharedPort(const std::string& port);
Link* getLinkFromParentSharedPort(const std::string& port, std::vector<ConfigPortModule>& port_modules);

using StatNameMap = std::map<std::string, std::map<std::string, Statistics::StatisticBase*>>;

std::vector<PortModule*> portModules;
std::map<StatisticId_t, Statistics::StatisticBase*> m_explicitlyEnabledSharedStats;
std::map<StatisticId_t, StatNameMap> m_explicitlyEnabledUniqueStats;
StatNameMap m_enabledAllStats;
Expand Down
5 changes: 5 additions & 0 deletions src/sst/core/componentInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ComponentInfo::ComponentInfo(ComponentId_t id, const std::string& name) :
component(nullptr),
params(nullptr),
defaultTimeBase(nullptr),
portModules(nullptr),
statConfigs(nullptr),
enabledStatNames(nullptr),
enabledAllStats(false),
Expand All @@ -49,6 +50,7 @@ ComponentInfo::ComponentInfo() :
component(nullptr),
params(nullptr),
defaultTimeBase(nullptr),
portModules(nullptr),
statConfigs(nullptr),
enabledStatNames(nullptr),
enabledAllStats(false),
Expand Down Expand Up @@ -89,6 +91,7 @@ ComponentInfo::ComponentInfo(
component(nullptr),
params(/*new Params()*/ nullptr),
defaultTimeBase(nullptr),
portModules(nullptr),
statConfigs(nullptr),
enabledStatNames(nullptr),
enabledAllStats(false),
Expand All @@ -113,6 +116,7 @@ ComponentInfo::ComponentInfo(
component(nullptr),
params(&ccomp->params),
defaultTimeBase(nullptr),
portModules(&ccomp->portModules),
statConfigs(&ccomp->statistics),
enabledStatNames(&ccomp->enabledStatNames),
enabledAllStats(ccomp->enabledAllStats),
Expand Down Expand Up @@ -157,6 +161,7 @@ ComponentInfo::ComponentInfo(ComponentInfo&& o) :
subComponents(std::move(o.subComponents)),
params(o.params),
defaultTimeBase(o.defaultTimeBase),
portModules(o.portModules),
statConfigs(o.statConfigs),
allStatConfig(o.allStatConfig),
statLoadLevel(o.statLoadLevel),
Expand Down
10 changes: 6 additions & 4 deletions src/sst/core/componentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BaseComponent;
class ComponentInfoMap;
class LinkMap;

class ConfigPortModule;
class ConfigComponent;
class ConfigStatistic;

Expand Down Expand Up @@ -116,10 +117,11 @@ class ComponentInfo

TimeConverter* defaultTimeBase;

std::map<StatisticId_t, ConfigStatistic>* statConfigs;
std::map<std::string, StatisticId_t>* enabledStatNames;
bool enabledAllStats;
const ConfigStatistic* allStatConfig;
std::map<std::string, std::vector<ConfigPortModule>>* portModules;
std::map<StatisticId_t, ConfigStatistic>* statConfigs;
std::map<std::string, StatisticId_t>* enabledStatNames;
bool enabledAllStats;
const ConfigStatistic* allStatConfig;

uint8_t statLoadLevel;

Expand Down
6 changes: 6 additions & 0 deletions src/sst/core/configGraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ ConfigComponent::findStatistic(StatisticId_t sid) const
}
}

void
ConfigComponent::addPortModule(const std::string& port, const std::string& type, const Params& params)
{
portModules[port].emplace_back(type, params);
}

std::vector<LinkId_t>
ConfigComponent::allLinks() const
{
Expand Down
30 changes: 27 additions & 3 deletions src/sst/core/configGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@ class ConfigStatOutput : public SST::Core::Serialization::serializable

typedef SparseVectorMap<LinkId_t, ConfigLink*> ConfigLinkMap_t;

/**
Class that represents a PortModule in ConfigGraph
*/
class ConfigPortModule : public SST::Core::Serialization::serializable
{
public:
std::string type;
Params params;

ConfigPortModule() = default;
ConfigPortModule(const std::string& type, const Params& params) : type(type), params(params) {}

void serialize_order(SST::Core::Serialization::serializer& ser) override
{
ser& type;
ser& params;
}
ImplementSerializable(SST::ConfigPortModule)
};


/** Represents the configuration of a generic component */
class ConfigComponent : public SST::Core::Serialization::serializable
{
Expand All @@ -231,9 +252,10 @@ class ConfigComponent : public SST::Core::Serialization::serializable
uint8_t statLoadLevel; /*!< Statistic load level for this component */
// std::vector<ConfigStatistic> enabledStatistics; /*!< List of subcomponents */

std::map<std::string, StatisticId_t> enabledStatNames;
bool enabledAllStats;
ConfigStatistic allStatConfig;
std::map<std::string, std::vector<ConfigPortModule>> portModules;
std::map<std::string, StatisticId_t> enabledStatNames;
bool enabledAllStats;
ConfigStatistic allStatConfig;

std::vector<ConfigComponent*> subComponents; /*!< List of subcomponents */
std::vector<double> coords;
Expand Down Expand Up @@ -290,6 +312,7 @@ class ConfigComponent : public SST::Core::Serialization::serializable
std::vector<std::string> getParamsLocalKeys() const { return params.getLocalKeys(); }
std::vector<std::string> getSubscribedGlobalParamSets() const { return params.getSubscribedGlobalParamSets(); }

void addPortModule(const std::string& port, const std::string& type, const Params& params);

std::vector<LinkId_t> allLinks() const;

Expand All @@ -311,6 +334,7 @@ class ConfigComponent : public SST::Core::Serialization::serializable
ser& enabledStatNames;
ser& enabledAllStats;
ser& statistics;
ser& portModules;
ser& enabledAllStats;
ser& allStatConfig;
ser& statLoadLevel;
Expand Down
8 changes: 8 additions & 0 deletions src/sst/core/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class Event : public Activity

bool isEvent() final { return true; }

void copyAllDeliveryInfo(const Activity* act) final
{
Activity::copyAllDeliveryInfo(act);
const Event* ev = static_cast<const Event*>(act);
delivery_info = ev->delivery_info;
}


void serialize_order(SST::Core::Serialization::serializer& ser) override
{
Activity::serialize_order(ser);
Expand Down
Loading

0 comments on commit 1d2562c

Please sign in to comment.