Skip to content

Commit

Permalink
Rough demo of serialization mapping mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
feldergast committed Sep 21, 2024
1 parent 95aed59 commit f6096db
Show file tree
Hide file tree
Showing 40 changed files with 2,143 additions and 81 deletions.
3 changes: 3 additions & 0 deletions src/sst/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ nobase_dist_sst_HEADERS = \
serialization/serializable_base.h \
serialization/serialize.h \
serialization/serialize_impl_fwd.h \
serialization/objectMap.h \
serialization/impl/serialize_array.h \
serialization/impl/serialize_atomic.h \
serialization/impl/ser_buffer_accessor.h \
serialization/impl/serialize_deque.h \
serialization/impl/serialize_list.h \
serialization/impl/serialize_map.h \
serialization/impl/serialize_multiset.h \
serialization/impl/mapper.h \
serialization/impl/packer.h \
serialization/impl/serialize_priority_queue.h \
serialization/impl/serialize_set.h \
Expand Down Expand Up @@ -213,6 +215,7 @@ sst_core_sources = \
ssthandler.cc \
sstpart.cc \
timeVortex.cc \
serialization/objectMap.cc \
serialization/serializable_base.cc \
serialization/serializable.cc \
serialization/serializer.cc \
Expand Down
40 changes: 37 additions & 3 deletions src/sst/core/baseComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "sst/core/timeLord.h"
#include "sst/core/unitAlgebra.h"
#include "sst/core/warnmacros.h"
#include "sst/core/serialization/serialize.h"

#include <string>

Expand Down Expand Up @@ -853,6 +854,9 @@ BaseComponent::serialize_order(SST::Core::Serialization::serializer& ser)
}
break;
}
case SST::Core::Serialization::serializer::MAP:
// Add your code here
break;
}
}

Expand All @@ -863,15 +867,15 @@ namespace pvt {
static const long null_ptr_id = -1;

void
size_basecomponent(serializable_base* s, serializer& ser)
SerializeBaseComponentHelper::size_basecomponent(serializable_base* s, serializer& ser)
{
long dummy = 0;
ser.size(dummy);
if ( s ) { s->serialize_order(ser); }
}

void
pack_basecomponent(serializable_base* s, serializer& ser)
SerializeBaseComponentHelper::pack_basecomponent(serializable_base* s, serializer& ser)
{
if ( s ) {
long cls_id = s->cls_id();
Expand All @@ -885,7 +889,7 @@ pack_basecomponent(serializable_base* s, serializer& ser)
}

void
unpack_basecomponent(serializable_base*& s, serializer& ser)
SerializeBaseComponentHelper::unpack_basecomponent(serializable_base*& s, serializer& ser)
{
long cls_id;
ser.unpack(cls_id);
Expand All @@ -897,6 +901,36 @@ unpack_basecomponent(serializable_base*& s, serializer& ser)
}
}

void
SerializeBaseComponentHelper::map_basecomponent(serializable_base*& s, serializer& ser, const char* name)
{
if ( s ) {
BaseComponent* comp = static_cast<BaseComponent*>(s);
ObjectMapClass* obj_map = new ObjectMapClass(s, s->cls_name());
ser.report_object_map(obj_map);
ser.mapper().map_hierarchy_start(name, obj_map);

// Put in any subcomponents first
for ( auto it = comp->my_info->subComponents.begin(); it != comp->my_info->subComponents.end(); ++it ) {
sst_map_object(ser, it->second.component, it->second.getShortName().c_str());
it->second.serialize_comp(ser);
}

// Put in ComponentInfo data
ObjectMap* my_info_dir = new ObjectMapHierarchyOnly();
ser.mapper().map_hierarchy_start("my_info", my_info_dir);
ser.mapper().setNextObjectReadOnly();
sst_map_object(ser, const_cast<ComponentId_t&>(comp->my_info->id), "id");
ser.mapper().setNextObjectReadOnly();
sst_map_object(ser, const_cast<std::string&>(comp->my_info->type), "type");
sst_map_object(ser, comp->my_info->defaultTimeBase, "defaultTimeBase");
ser.mapper().map_hierarchy_end(); // for my_info_dir

s->serialize_order(ser);
ser.mapper().map_hierarchy_end(); // obj_map
}
}

} // namespace pvt
} // namespace Serialization
} // namespace Core
Expand Down
41 changes: 35 additions & 6 deletions src/sst/core/baseComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ class SubComponentSlotInfo;
class TimeConverter;
class UnitAlgebra;


namespace Core {
namespace Serialization {
namespace pvt {
class SerializeBaseComponentHelper;
} // namespace pvt
} // namespace Serialization
} // namespace Core

/**
* Main component object for the simulation.
*/
Expand Down Expand Up @@ -878,6 +887,9 @@ class BaseComponent : public SST::Core::Serialization::serializable_base
std::vector<Profile::ComponentProfileTool*> getComponentProfileTools(const std::string& point);

private:
friend class Core::Serialization::pvt::SerializeBaseComponentHelper;


ComponentInfo* my_info = nullptr;
Simulation_impl* sim_ = nullptr;
bool isExtension = false;
Expand Down Expand Up @@ -1094,13 +1106,21 @@ namespace Serialization {

namespace pvt {

void size_basecomponent(serializable_base* s, serializer& ser);
class SerializeBaseComponentHelper
{
public:
static void size_basecomponent(serializable_base* s, serializer& ser);

static void pack_basecomponent(serializable_base* s, serializer& ser);

void pack_basecomponent(serializable_base* s, serializer& ser);
static void unpack_basecomponent(serializable_base*& s, serializer& ser);

void unpack_basecomponent(serializable_base*& s, serializer& ser);
static void map_basecomponent(serializable_base*& s, serializer& ser, const char* name);
};

} // namespace pvt


template <class T>
class serialize_impl<T*, typename std::enable_if<std::is_base_of<SST::BaseComponent, T>::value>::type>
{
Expand All @@ -1111,17 +1131,26 @@ class serialize_impl<T*, typename std::enable_if<std::is_base_of<SST::BaseCompon
serializable_base* sp = static_cast<serializable_base*>(s);
switch ( ser.mode() ) {
case serializer::SIZER:
pvt::size_basecomponent(sp, ser);
pvt::SerializeBaseComponentHelper::size_basecomponent(sp, ser);
break;
case serializer::PACK:
pvt::pack_basecomponent(sp, ser);
pvt::SerializeBaseComponentHelper::pack_basecomponent(sp, ser);
break;
case serializer::UNPACK:
pvt::unpack_basecomponent(sp, ser);
pvt::SerializeBaseComponentHelper::unpack_basecomponent(sp, ser);
break;
case serializer::MAP:
// Add your code here
break;
}
s = static_cast<T*>(sp);
}

void operator()(T*& s, serializer& ser, const char* name)
{
serializable_base* sp = static_cast<serializable_base*>(s);
pvt::SerializeBaseComponentHelper::map_basecomponent(sp, ser, name);
}
};

} // namespace Serialization
Expand Down
3 changes: 3 additions & 0 deletions src/sst/core/componentInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ ComponentInfo::serialize_order(SST::Core::Serialization::serializer& ser)
}
break;
}
case SST::Core::Serialization::serializer::MAP:
// Add your code here
break;
}

// Only the parent Component will call serialize_comp directly.
Expand Down
15 changes: 15 additions & 0 deletions src/sst/core/componentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class ConfigStatistic;
class Simulation_impl;
class TimeConverter;

namespace Core {
namespace Serialization {
namespace pvt {
class SerializeBaseComponentHelper;
} // namespace pvt
} // namespace Serialization
} // namespace Core

class ComponentInfo
{

Expand All @@ -55,6 +63,7 @@ class ComponentInfo
friend class Simulation_impl;
friend class BaseComponent;
friend class ComponentInfoMap;
friend class Core::Serialization::pvt::SerializeBaseComponentHelper;

/**
Component ID.
Expand Down Expand Up @@ -204,6 +213,12 @@ class ComponentInfo
return real_comp->getName();
}

/**
Get the short name for this SubComponent (name not including
any parents, so just slot_name[index])
*/
inline std::string getShortName() const { return name.substr(name.find_last_of(':')+1); }

inline const std::string& getSlotName() const { return slot_name; }

inline int getSlotNum() const { return slot_num; }
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/interfaces/TestEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Interfaces {
/** Test Event
* Useful for early-testing of components.
*/
class TestEvent : public SST::Event, public SST::Core::Serialization::serializable_type<TestEvent>
class TestEvent : public SST::Event
{
public:
TestEvent();
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/interfaces/simpleNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SimpleNetwork : public SubComponent
/**
* Represents both network sends and receives
*/
class Request : public SST::Core::Serialization::serializable, SST::Core::Serialization::serializable_type<Request>
class Request : public SST::Core::Serialization::serializable
{

public:
Expand Down
20 changes: 15 additions & 5 deletions src/sst/core/link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core:
// If I'm a polling link, I need to serialize my
// pair's send_queue. For HANDLER and SYNC links, the
// send_queue will be reinitialized after restart
PollingLinkQueue* queue = dynamic_cast<PollingLinkQueue*>(s->pair_link->send_queue);
ser& queue;
// TODO: Fix PollingLinkQueue serialization
// PollingLinkQueue* queue = dynamic_cast<PollingLinkQueue*>(s->pair_link->send_queue);
// ser& queue;
}

// My delivery_info is stored in my pair_link.
Expand Down Expand Up @@ -232,9 +233,10 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core:
// pair's send_queue. For now, I will store it in my
// own send_queue variable and swap once we have both
// links.
PollingLinkQueue* queue;
ser& queue;
s->send_queue = queue;
// TODO - Fix PollingLinkQueue serialization
// PollingLinkQueue* queue;
// ser& queue;
// s->send_queue = queue;
}
else {
s->send_queue = Simulation_impl::getSimulation()->getTimeVortex();
Expand Down Expand Up @@ -276,9 +278,17 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core:
// ser & s->profile_tools;
}
break;
case serializer::MAP:
// Add your code here
break;
}
}

void
SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, SST::Core::Serialization::serializer& ser, const char* name)
{
// TODO: Implement Link mapping mode
}

/**
* Null Event. Used when nullptr is passed into any of the send
Expand Down
1 change: 1 addition & 0 deletions src/sst/core/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SST::Core::Serialization::serialize_impl<Link*>
friend class serialize;
// Function implemented in link.cc
void operator()(Link*& s, SST::Core::Serialization::serializer& ser);
void operator()(Link*& s, SST::Core::Serialization::serializer& ser, const char* name);
};


Expand Down
Loading

0 comments on commit f6096db

Please sign in to comment.