SST 15.0
Structural Simulation Toolkit
componentInfo.h
1// Copyright 2009-2025 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2025, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_COMPONENTINFO_H
13#define SST_CORE_COMPONENTINFO_H
14
15#include "sst/core/params.h"
16#include "sst/core/serialization/serializer_fwd.h"
17#include "sst/core/sst_types.h"
18#include "sst/core/timeConverter.h"
19
20#include <functional>
21#include <map>
22#include <string>
23#include <unordered_set>
24
25namespace SST {
26
27class BaseComponent;
29class LinkMap;
30
32class ConfigComponent;
33class ConfigStatistic;
34
35class Simulation_impl;
36
37namespace Core::Serialization::pvt {
39} // namespace Core::Serialization::pvt
40
41class ComponentInfo
42{
43
44public:
45 using statEnableList_t = std::vector<ConfigStatistic>; /*!< List of Enabled Statistics */
46
47 // Share Flags for SubComponent loading
48 static const uint64_t SHARE_PORTS = 0x1;
49 static const uint64_t SHARE_STATS = 0x2;
50 static const uint64_t INSERT_STATS = 0x4;
51 static const uint64_t SHARE_NONE = 0x0;
52
53private:
54 // Mask to make sure users are only setting the flags that are
55 // available to them
56 static const uint64_t USER_FLAGS = 0x7;
57
58 // Friend classes
59 friend class Simulation_impl;
60 friend class BaseComponent;
61 friend class ComponentInfoMap;
63
64 /**
65 Component ID.
66
67 SubComponents share the lower bits (defined by macros in
68 sst_types.h) with their Component parent. However, every
69 SubComponent has a unique ID.
70 */
71 const ComponentId_t id_;
72
73 ComponentInfo* parent_info;
74 /**
75 Name of the Component/SubComponent.
76 */
77 const std::string name;
78
79 /**
80 Type of the Component/SubComponent.
81 */
82 const std::string type;
83
84 /**
85 LinkMap containing the links assigned to this
86 Component/SubComponent in the python file.
87
88 This field is not used for SubComponents loaded with
89 loadAnonymousSubComponent().
90 */
91 LinkMap* link_map;
92
93 /**
94 Pointer to the Component created using this ComponentInfo.
95 */
96 BaseComponent* component;
97
98 /**
99 SubComponents loaded into the Component/SubComponent.
100 */
101 std::map<ComponentId_t, ComponentInfo> subComponents;
102
103 /**
104 Parameters defined in the python file for the (Sub)Component.
105
106 This field is used for only a short time while loading
107 SubComponents via loadUserSubComponent().
108
109 This pointer is invalid after simulation wire-up.
110 */
111 Params* params;
112
113 TimeConverter defaultTimeBase;
114
115 std::map<std::string, std::vector<ConfigPortModule>>* portModules = nullptr;
116 std::map<StatisticId_t, ConfigStatistic>* stat_configs_ = nullptr;
117 std::map<std::string, StatisticId_t>* enabled_stat_names_ = nullptr;
118 bool enabled_all_stats_ = false;
119 ConfigStatistic* all_stat_config_ = nullptr;
120
121 uint8_t statLoadLevel;
122
123 std::vector<double> coordinates;
124
125 uint64_t subIDIndex;
126
127 // Variables only used by SubComponents
128
129 /**
130 Name of the slot this SubComponent was loaded into. This field
131 is not used for Components.
132 */
133 const std::string slot_name;
134
135 /**
136 Index in the slot this SubComponent was loaded into. This field
137 is not used for Components.
138 */
139 int slot_num;
140
141 /**
142 Sharing flags.
143
144 Determines whether various data is shared from parent to child.
145 */
146 uint64_t share_flags;
147
148 bool sharesPorts() { return (share_flags & SHARE_PORTS) != 0; }
149
150 bool sharesStatistics() { return (share_flags & SHARE_STATS) != 0; }
151
152 bool canInsertStatistics() { return (share_flags & INSERT_STATS) != 0; }
153
154 inline void setComponent(BaseComponent* comp) { component = comp; }
155 // inline void setParent(BaseComponent* comp) { parent = comp; }
156
157 /* Lookup Key style constructor */
158 ComponentInfo(ComponentId_t id, const std::string& name);
159 void finalizeLinkConfiguration() const;
160 void prepareForComplete() const;
161
162 ComponentId_t addAnonymousSubComponent(ComponentInfo* parent_info, const std::string& type,
163 const std::string& slot_name, int slot_num, uint64_t share_flags);
164
165public:
166 /**
167 Constructor used only for serialization
168 */
170
171 /**
172 Function used to serialize the class
173 */
174 void serialize_order(SST::Core::Serialization::serializer& ser);
175 void serialize_comp(SST::Core::Serialization::serializer& ser);
176
177 /* Old ELI Style subcomponent constructor */
178 ComponentInfo(const std::string& type, const Params* params, const ComponentInfo* parent_info);
179
180 /* Anonymous SubComponent */
181 ComponentInfo(ComponentId_t id, ComponentInfo* parent_info, const std::string& type, const std::string& slot_name,
182 int slot_num, uint64_t share_flags /*, const Params& params_in*/);
183
184 /* New ELI Style */
185 ComponentInfo(ConfigComponent* ccomp, const std::string& name, ComponentInfo* parent_info, LinkMap* link_map);
186 ComponentInfo(ComponentInfo&& o);
187 ~ComponentInfo();
188
189 bool isAnonymous() { return COMPDEFINED_SUBCOMPONENT_ID_MASK(id_); }
190
191 bool isUser() { return !COMPDEFINED_SUBCOMPONENT_ID_MASK(id_); }
192
193 inline ComponentId_t getID() const { return id_; }
194
195 inline const std::string& getName() const
196 {
197 if ( name.empty() && parent_info ) return parent_info->getName();
198 return name;
199 }
200
201 inline const std::string& getParentComponentName() const
202 {
203 // First, get the actual component (parent pointer will be
204 // nullptr).
205 const ComponentInfo* real_comp = this;
206 while ( real_comp->parent_info != nullptr )
207 real_comp = real_comp->parent_info;
208 return real_comp->getName();
209 }
210
211 /**
212 Get the short name for this SubComponent (name not including
213 any parents, so just slot_name[index])
214 */
215 inline std::string getShortName() const { return name.substr(name.find_last_of(':') + 1); }
216
217 inline const std::string& getSlotName() const { return slot_name; }
218
219 inline int getSlotNum() const { return slot_num; }
220
221 inline const std::string& getType() const { return type; }
222
223 inline BaseComponent* getComponent() const { return component; }
224
225 LinkMap* getLinkMap();
226
227 inline const Params* getParams() const { return params; }
228
229 // inline std::map<std::string, ComponentInfo>& getSubComponents() { return subComponents; }
230 inline std::map<ComponentId_t, ComponentInfo>& getSubComponents() { return subComponents; }
231
232 ComponentInfo* findSubComponent(const std::string& slot, int slot_num);
233 ComponentInfo* findSubComponent(ComponentId_t id);
234 bool hasLinks() const;
235
236 uint8_t getStatisticLoadLevel() { return statLoadLevel; }
237
238 struct HashName
239 {
240 size_t operator()(const ComponentInfo* info) const
241 {
242 std::hash<std::string> hash;
243 return hash(info->name);
244 }
245 };
246
248 {
249 bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->name == rhs->name; }
250 };
251
252 struct HashID
253 {
254 size_t operator()(const ComponentInfo* info) const
255 {
256 std::hash<ComponentId_t> hash;
257 return hash(info->id_);
258 }
259 };
260
261 struct EqualsID
262 {
263 bool operator()(const ComponentInfo* lhs, const ComponentInfo* rhs) const { return lhs->id_ == rhs->id_; }
264 };
265
266 //// Functions used only for testing, they will not create valid
267 //// ComponentInfos for simulation
268
269 /**
270 (DO NOT USE) Constructor used only for serialization testing
271 */
273 ComponentId_t id, const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
274
275 ComponentInfo* test_addSubComponentInfo(
276 const std::string& name, const std::string& slot_name, TimeConverter tv = TimeConverter());
277
278 void test_printComponentInfoHierarchy(int index = 0);
279};
280
281class ComponentInfoMap
282{
283private:
284 std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID> dataByID;
285
286public:
287 using const_iterator =
288 std::unordered_set<ComponentInfo*, ComponentInfo::HashID, ComponentInfo::EqualsID>::const_iterator;
289
290 const_iterator begin() const { return dataByID.begin(); }
291
292 const_iterator end() const { return dataByID.end(); }
293
294 ComponentInfoMap() {}
295
296 void insert(ComponentInfo* info) { dataByID.insert(info); }
297
298 ComponentInfo* getByID(const ComponentId_t key) const
299 {
300 ComponentInfo infoKey(COMPONENT_ID_MASK(key), "");
301 auto value = dataByID.find(&infoKey);
302 if ( value == dataByID.end() ) return nullptr;
303 if ( SUBCOMPONENT_ID_MASK(key) != 0 ) {
304 // Looking for a subcomponent
305 return (*value)->findSubComponent(key);
306 }
307 return *value;
308 }
309
310 bool empty() { return dataByID.empty(); }
311
312 void clear()
313 {
314 for ( auto i : dataByID ) {
315 delete i;
316 }
317 dataByID.clear();
318 }
319
320 size_t size() { return dataByID.size(); }
321};
322
323} // namespace SST
324
325#endif // SST_CORE_COMPONENTINFO_H
Main component object for the simulation.
Definition baseComponent.h:62
Definition componentInfo.h:282
Definition componentInfo.h:42
std::vector< ConfigStatistic > statEnableList_t
Definition componentInfo.h:45
std::string getShortName() const
Get the short name for this SubComponent (name not including any parents, so just slot_name[index])
Definition componentInfo.h:215
void serialize_order(SST::Core::Serialization::serializer &ser)
Function used to serialize the class.
Definition componentInfo.cc:206
ComponentInfo()
Constructor used only for serialization.
Definition componentInfo.cc:44
Represents the configuration of a generic component.
Definition configGraph.h:263
Class that represents a PortModule in ConfigGraph.
Definition configGraph.h:241
Definition configGraph.h:134
Maps port names to the Links that are connected to it.
Definition linkMap.h:29
Parameter store.
Definition params.h:58
Main control class for a SST Simulation.
Definition simulation_impl.h:87
A class to convert between a component's view of time and the core's view of time.
Definition timeConverter.h:28
Definition componentInfo.h:262
Definition componentInfo.h:248
Definition componentInfo.h:253
Definition componentInfo.h:239