Skip to content

Commit

Permalink
Finished initial serilization code for BaseComponents and its derived…
Browse files Browse the repository at this point in the history
… classes.
  • Loading branch information
feldergast committed Apr 17, 2024
1 parent 796079e commit 5fecace
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 46 deletions.
61 changes: 25 additions & 36 deletions src/sst/core/baseComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

namespace SST {

BaseComponent::BaseComponent() : SST::Core::Serialization::serializable() {}

BaseComponent::BaseComponent(ComponentId_t id) :
SST::Core::Serialization::serializable(),
my_info(Simulation_impl::getSimulation()->getComponentInfo(id)),
sim_(Simulation_impl::getSimulation()),
isExtension(false)
Expand Down Expand Up @@ -106,11 +109,9 @@ BaseComponent::pushValidParams(Params& params, const std::string& type)
params.pushAllowedKeys(keyset);
}

TimeConverter*
BaseComponent::registerClock(const std::string& freq, Clock::HandlerBase* handler, bool regAll)
void
BaseComponent::registerClock_impl(TimeConverter* tc, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tc = sim_->registerClock(freq, handler, CLOCKPRIORITY);

// Check to see if there is a profile tool installed
auto tools = sim_->getProfileTool<Profile::ClockHandlerProfileTool>("clock");

Expand All @@ -126,52 +127,30 @@ BaseComponent::registerClock(const std::string& freq, Clock::HandlerBase* handle
setDefaultTimeBaseForLinks(tc);
my_info->defaultTimeBase = tc;
}
}


TimeConverter*
BaseComponent::registerClock(const std::string& freq, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tc = sim_->registerClock(freq, handler, CLOCKPRIORITY);
registerClock_impl(tc, handler, regAll);
return tc;
}

TimeConverter*
BaseComponent::registerClock(const UnitAlgebra& freq, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tc = sim_->registerClock(freq, handler, CLOCKPRIORITY);

// Check to see if there is a profile tool installed
auto tools = sim_->getProfileTool<Profile::ClockHandlerProfileTool>("clock");

for ( auto* tool : tools ) {
ClockHandlerMetaData mdata(my_info->getID(), getName(), getType());
// Add the receive profiler to the handler
handler->addProfileTool(tool, mdata);
}

// if regAll is true set tc as the default for the component and
// for all the links
if ( regAll ) {
setDefaultTimeBaseForLinks(tc);
my_info->defaultTimeBase = tc;
}
registerClock_impl(tc, handler, regAll);
return tc;
}

TimeConverter*
BaseComponent::registerClock(TimeConverter* tc, Clock::HandlerBase* handler, bool regAll)
{
TimeConverter* tcRet = sim_->registerClock(tc, handler, CLOCKPRIORITY);

// Check to see if there is a profile tool installed
auto tools = sim_->getProfileTool<Profile::ClockHandlerProfileTool>("clock");

for ( auto* tool : tools ) {
ClockHandlerMetaData mdata(my_info->getID(), getName(), getType());
// Add the receive profiler to the handler
handler->addProfileTool(tool, mdata);
}

// if regAll is true set tc as the default for the component and
// for all the links
if ( regAll ) {
setDefaultTimeBaseForLinks(tcRet);
my_info->defaultTimeBase = tcRet;
}
registerClock_impl(tcRet, handler, regAll);
return tcRet;
}

Expand Down Expand Up @@ -832,4 +811,14 @@ BaseComponent::getComponentProfileTools(const std::string& point)
return sim_->getProfileTool<Profile::ComponentProfileTool>(point);
}

void
BaseComponent::serialize_order(SST::Core::Serialization::serializer& ser)
{
ser& my_info;
ser& isExtension;

if ( ser.mode() == SST::Core::Serialization::serializer::UNPACK ) { sim_ = Simulation_impl::getSimulation(); }
}


} // namespace SST
22 changes: 18 additions & 4 deletions src/sst/core/baseComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class UnitAlgebra;
/**
* Main component object for the simulation.
*/
class BaseComponent
class BaseComponent : public SST::Core::Serialization::serializable
{

friend class Component;
friend class ComponentExtension;
friend class ComponentInfo;
friend class SubComponent;
Expand All @@ -61,6 +62,9 @@ class BaseComponent
BaseComponent*, Statistics::StatisticProcessingEngine*, const std::string& /*type*/,
const std::string& /*name*/, const std::string& /*subId*/, Params&)>;

// For serialization only
BaseComponent();

public:
BaseComponent(ComponentId_t id);
virtual ~BaseComponent();
Expand Down Expand Up @@ -353,6 +357,16 @@ class BaseComponent
}

private:
ImplementSerializable(SST::BaseComponent)
void serialize_order(SST::Core::Serialization::serializer& ser) override;


/**
Handles the profile points, default time base, handler tracking
and checkpointing.
*/
void registerClock_impl(TimeConverter* tc, Clock::HandlerBase* handler, bool regAll);

template <typename T>
Statistics::Statistic<T>*
createStatistic(SST::Params& params, StatisticId_t id, const std::string& name, const std::string& statSubId)
Expand Down Expand Up @@ -870,9 +884,9 @@ class BaseComponent
std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(const std::string& point);

private:
ComponentInfo* my_info = nullptr;
Simulation_impl* sim_ = nullptr;
bool isExtension;
ComponentInfo* my_info = nullptr;
Simulation_impl* sim_ = nullptr;
bool isExtension = false;

void addSelfLink(const std::string& name);
Link* getLinkFromParentSharedPort(const std::string& port);
Expand Down
10 changes: 10 additions & 0 deletions src/sst/core/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ Component::primaryComponentOKToEndSim()
Simulation_impl::getSimulation()->getExit()->refDec(getId(), thread);
}


void
Component::serialize_order(SST::Core::Serialization::serializer& ser)
{
BaseComponent::serialize_order(ser);
}

// For serialization only
Component::Component() : BaseComponent() {}

} // namespace SST
7 changes: 7 additions & 0 deletions src/sst/core/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Component : public BaseComponent

protected:
friend class SubComponent;

private:
// For Serialization only
Component();

ImplementSerializable(SST::Component)
void serialize_order(SST::Core::Serialization::serializer& ser) override;
};

} // namespace SST
Expand Down
9 changes: 9 additions & 0 deletions src/sst/core/componentExtension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ ComponentExtension::ComponentExtension(ComponentId_t id) : BaseComponent(id)
isExtension = true;
}

void
ComponentExtension::serialize_order(SST::Core::Serialization::serializer& ser)
{
BaseComponent::serialize_order(ser);
}

// For serialization only
ComponentExtension::ComponentExtension() : BaseComponent() {}

} // namespace SST
7 changes: 7 additions & 0 deletions src/sst/core/componentExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ComponentExtension : public BaseComponent
ComponentExtension(ComponentId_t id);

virtual ~ComponentExtension() {};

private:
// For serialization only
ComponentExtension();

ImplementSerializable(SST::ComponentExtension)
void serialize_order(SST::Core::Serialization::serializer& ser) override;
};

} // namespace SST
Expand Down
4 changes: 2 additions & 2 deletions src/sst/core/componentInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ ComponentInfo::serialize_order(SST::Core::Serialization::serializer& ser)
ser& parent_info;
ser& const_cast<std::string&>(name);
ser& const_cast<std::string&>(type);
// ser& link_map;
// ser& component;
ser& link_map;
ser& component;

// Not used after construction, no need to serialize
// ser& params;
Expand Down
9 changes: 9 additions & 0 deletions src/sst/core/linkMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class LinkMap
// const std::vector<std::string> * allowedPorts;
std::vector<std::string> selfPorts;

friend class SST::Core::Serialization::serialize_impl<LinkMap*>;

void serialize_order(SST::Core::Serialization::serializer& ser)
{
ser& linkMap;
ser& selfPorts;
}


// bool checkPort(const char *def, const char *offered) const
// {
// const char * x = def;
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/simulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ Simulation_impl::checkpoint()
{
sim_output.output("Checkpoint triggered at time %" PRIu64 "\n", currentSimCycle);

printf("Printing original TV, size = %zu\n", timeVortex->getCurrentDepth());
printf("Printing original TV, size = %" PRIu64 "\n", timeVortex->getCurrentDepth());
timeVortex->dbg_print(sim_output);

SST::Core::Serialization::serializer ser;
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/stopAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StopAction : public Action
out.output("%s StopAction to be delivered at %" PRIu64 "\n", header.c_str(), getDeliveryTime());
}

void serialize_order(SST::Core::Serialization::serializer& ser)
void serialize_order(SST::Core::Serialization::serializer& ser) override
{
Action::serialize_order(ser);
ser& message;
Expand Down
9 changes: 9 additions & 0 deletions src/sst/core/subcomponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ SST_ELI_DEFINE_CTOR_EXTERN(SubComponent)

SubComponent::SubComponent(ComponentId_t id) : BaseComponent(id) {}

void
SubComponent::serialize_order(SST::Core::Serialization::serializer& ser)
{
BaseComponent::serialize_order(ser);
}

// For serialization only
SubComponent::SubComponent() : BaseComponent() {}

} // namespace SST
6 changes: 6 additions & 0 deletions src/sst/core/subcomponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class SubComponent : public BaseComponent

private:
friend class Component;

// For serialization only
SubComponent();

ImplementSerializable(SST::SubComponent)
void serialize_order(SST::Core::Serialization::serializer& ser) override;
};

namespace SUBCOMPONENT {
Expand Down
5 changes: 3 additions & 2 deletions src/sst/core/testElements/coreTest_Serialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,13 @@ coreTestSerialization::coreTestSerialization(ComponentId_t id, Params& params) :
else if ( test == "atomic" ) {
std::atomic<int32_t> atom(12);

auto buffer = SST::Comms::serialize(atom);
auto buffer = SST::Comms::serialize(atom);
std::atomic<int32_t> result;
SST::Comms::deserialize(buffer, result);
passed = (atom.load() == result.load()) ? true : false;
if ( !passed ) out.output("ERROR: std::atomic<int32_t> did not serialize/deserialize properly\n");
} else {
}
else {
out.fatal(CALL_INFO_LONG, 1, "ERROR: Unknown serialization test specified: %s\n", test.c_str());
}
}
Expand Down

0 comments on commit 5fecace

Please sign in to comment.