SST 15.0
Structural Simulation Toolkit
coreTest_SubComponent.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_CORETEST_SUBCOMPONENT_H
13#define SST_CORE_CORETEST_SUBCOMPONENT_H
14
15#include "sst/core/component.h"
16#include "sst/core/link.h"
17#include "sst/core/subcomponent.h"
18
19#include <cstdint>
20#include <vector>
21
22namespace SST::CoreTestSubComponent {
23
24/*
25
26 CoreTestSubComponent will test the various ways to use SubComponents.
27 The SubComponents will be loadable as both named and unnamed
28 SubComponets. When an unname SubComponent is used, it inherits the
29 port interface from the BaseComponent that created it. A named
30 SubComponent owns it's own ports and will mask the ports from any
31 BaseComponent higher in the call tree.
32
33 Each BaseComponent will have a port(s) that may or may not be used
34 depending on the configuration.
35 */
36
37class SubCompInterface : public SST::SubComponent
38{
39public:
40 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestSubComponent::SubCompInterface)
41
42 explicit SubCompInterface(ComponentId_t id) :
43 SubComponent(id)
44 {}
45 SubCompInterface(ComponentId_t id, Params& UNUSED(params)) :
46 SubComponent(id)
47 {}
48 SubCompInterface() :
49 SubComponent()
50 {}
51 virtual ~SubCompInterface() {}
52 virtual void clock(SST::Cycle_t) {}
53
54 void serialize_order(SST::Core::Serialization::serializer& ser) override
55 {
56 SST::SubComponent::serialize_order(ser);
57 }
59};
60
61class SubCompSlotInterface : public SubCompInterface
62{
63public:
64 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSlotInterface,
66
67 SST_ELI_DOCUMENT_PARAMS(
68 {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"}
69 )
70
71 SST_ELI_DOCUMENT_PORTS(
72 {"test", "Just a test port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
73 )
74
75 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
76 )
77
78 explicit SubCompSlotInterface(ComponentId_t id) :
79 SubCompInterface(id)
80 {}
81 SubCompSlotInterface(ComponentId_t id, Params& UNUSED(params)) :
82 SubCompInterface(id)
83 {}
84 virtual ~SubCompSlotInterface() {}
85
86 SubCompSlotInterface() {}
87 void serialize_order(SST::Core::Serialization::serializer& ser) override { SubCompInterface::serialize_order(ser); }
89};
90
91/* Our trivial component */
92class SubComponentLoader : public Component
93{
94public:
95 // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
96 SST_ELI_REGISTER_COMPONENT(
97 SubComponentLoader,
98 "coreTestElement",
99 "SubComponentLoader",
100 SST_ELI_ELEMENT_VERSION(1,0,0),
101 "Demonstrates subcomponents",
102 COMPONENT_CATEGORY_UNCATEGORIZED
103 )
104
105 SST_ELI_DOCUMENT_PARAMS(
106 {"clock", "Clock Rate", "1GHz"},
107 {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
108 {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
109 {"verbose", "Verbosity level", "0"},
110 )
111
112 SST_ELI_DOCUMENT_STATISTICS(
113 {"totalSent", "# of total messages sent", "", 1},
114 )
115
116 // This ports will be used only by unnamed SubComponents
117 SST_ELI_DOCUMENT_PORTS(
118 {"port%d", "Sending or Receiving Port(s)", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
119 )
120
121 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
122 {"mySubComp", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
123 )
124
125 SubComponentLoader(ComponentId_t id, SST::Params& params);
126
127 SubComponentLoader() {}
128 void serialize_order(SST::Core::Serialization::serializer& ser) override
129 {
130 SST::Component::serialize_order(ser);
131 SST_SER(count);
132 SST_SER(subComps);
133 }
135
136private:
137 uint32_t count = 0;
138 bool tick(SST::Cycle_t);
139 std::vector<SubCompInterface*> subComps;
140};
141
142/* Our example subcomponents */
143class SubCompSlot : public SubCompSlotInterface
144{
145public:
146 SST_ELI_REGISTER_SUBCOMPONENT(
147 SubCompSlot,
148 "coreTestElement",
149 "SubCompSlot",
150 SST_ELI_ELEMENT_VERSION(1,0,0),
151 "Subcomponent which is just a wrapper for the actual SubComponent to be used",
153 )
154
155 SST_ELI_DOCUMENT_PARAMS(
156 {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
157 {"verbose", "Verbosity level", "0"},
158 )
159
160 // Only used when loading unnamed SubComponents
161 SST_ELI_DOCUMENT_PORTS(
162 {"slot_port%d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
163 )
164
165 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
166 {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
167 )
168
169 SubCompSlot() {}
170 void serialize_order(SST::Core::Serialization::serializer& ser) override
171 {
172 SubCompSlotInterface::serialize_order(ser);
173 SST_SER(subComps);
174 }
175 ImplementSerializable(SST::CoreTestSubComponent::SubCompSlot)
176
177private:
178 std::vector<SubCompInterface*> subComps;
179
180public:
181 SubCompSlot(ComponentId_t id, Params& params);
182 // Direct load
183 SubCompSlot(ComponentId_t id, std::string unnamed_sub);
184
185 ~SubCompSlot() {}
186 void clock(Cycle_t) override;
187};
188
189// Add in some extra levels of ELI hierarchy for testing
190class SubCompSendRecvInterface : public SubCompInterface
191{
192public:
193 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSendRecvInterface,
195
196 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
197 SST_ELI_REGISTER_SUBCOMPONENT(
198 SubCompSendRecvInterface,
199 "coreTestElement",
200 "SubCompSendRecv",
201 SST_ELI_ELEMENT_VERSION(1,0,0),
202 "Default Subcomponent for ELI testing only",
204 )
205
206 SST_ELI_DOCUMENT_PARAMS(
207 {"port_name", "Name of port to connect to", ""},
208 {"sendCount", "Number of Messages to Send", "10"},
209 {"verbose", "Verbosity level", "0"}
210 )
211
212 SST_ELI_DOCUMENT_PORTS(
213 {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
214 // The following port is a test to make sure that when loaded
215 // anonymously, a port that's named the same as one of its
216 // parent's ports doesn't conflict.
217 {"slot_port%d", "This is just a test port that duplicates a port from the SubComponent that will instance it", { "", "" } },
218 )
219
220 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
221 )
222
223 SST_ELI_DOCUMENT_STATISTICS(
224 {"numRecv", "# of msgs recv", "", 1},
225 )
226
227
228 explicit SubCompSendRecvInterface(ComponentId_t id) :
229 SubCompInterface(id)
230 {}
231 SubCompSendRecvInterface(ComponentId_t id, Params& UNUSED(params)) :
232 SubCompInterface(id)
233 {}
234 virtual ~SubCompSendRecvInterface() {}
235
236 SubCompSendRecvInterface() {}
237 void serialize_order(SST::Core::Serialization::serializer& ser) override { SubCompInterface::serialize_order(ser); }
239};
240
241class SubCompSender : public SubCompSendRecvInterface
242{
243public:
244 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
245 SST_ELI_REGISTER_SUBCOMPONENT(
246 SubCompSender,
247 "coreTestElement",
248 "SubCompSender",
249 SST_ELI_ELEMENT_VERSION(1,0,0),
250 "Sending Subcomponent",
252 )
253
254 SST_ELI_REGISTER_ALIAS("SubCompSender_alias")
255
256 SST_ELI_DOCUMENT_PARAMS(
257 )
258
259 SST_ELI_DOCUMENT_STATISTICS(
260 SST_ELI_DELETE_STAT("numRecv"),
261 {"numSent", "# of msgs sent", "", 1},
262 )
263
264 SST_ELI_DOCUMENT_PORTS(
265 {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
266 )
267
268 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
269 {"test_slot", "Test slot", "" }
270 )
271
272 SubCompSender() {}
273 void serialize_order(SST::Core::Serialization::serializer& ser) override
274 {
275 SubCompSendRecvInterface::serialize_order(ser);
276 SST_SER(link);
277 SST_SER(nToSend);
278 SST_SER(nMsgSent);
279 SST_SER(totalMsgSent);
280 SST_SER(out);
281 }
282 ImplementSerializable(SST::CoreTestSubComponent::SubCompSender)
283
284private:
285 Statistic<uint32_t>* nMsgSent;
286 Statistic<uint32_t>* totalMsgSent;
287 uint32_t nToSend;
288 SST::Link* link;
289 SST::Output* out;
290
291public:
292 SubCompSender(ComponentId_t id, Params& params);
293 // Direct API
294 SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
295 ~SubCompSender() {}
296 void clock(Cycle_t) override;
297};
298
299class SubCompReceiver : public SubCompSendRecvInterface
300{
301
302public:
303 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
304 SST_ELI_REGISTER_SUBCOMPONENT(
305 SubCompReceiver,
306 "coreTestElement",
307 "SubCompReceiver",
308 SST_ELI_ELEMENT_VERSION(1,0,0),
309 "Receiving Subcomponent",
311 )
312
313 SST_ELI_DOCUMENT_PARAMS(
314 SST_ELI_DELETE_PARAM("sendCount")
315 )
316
317 SST_ELI_DOCUMENT_STATISTICS(
318 )
319
320 SST_ELI_DOCUMENT_PORTS(
321 SST_ELI_DELETE_PORT("sendPort"),
322 {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
323 )
324
325 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
326 SST_ELI_DELETE_SUBCOMPONENT_SLOT("test_slot")
327 )
328
329 SubCompReceiver() {}
330 void serialize_order(SST::Core::Serialization::serializer& ser) override
331 {
332 SubCompSendRecvInterface::serialize_order(ser);
333 SST_SER(link);
334 SST_SER(nMsgReceived);
335 SST_SER(out);
336 SST_SER(numRecv);
337 }
338 ImplementSerializable(SST::CoreTestSubComponent::SubCompReceiver)
339
340private:
341 Statistic<uint32_t>* nMsgReceived;
342 SST::Link* link;
343 SST::Output* out;
344 uint32_t numRecv = 0;
345
346 void handleEvent(SST::Event* ev);
347
348public:
349 SubCompReceiver(ComponentId_t id, Params& params);
350 SubCompReceiver(ComponentId_t id, std::string port);
351 ~SubCompReceiver() {}
352 void clock(Cycle_t) override;
353};
354
355} // namespace SST::CoreTestSubComponent
356
357#endif // SST_CORE_CORETEST_SUBCOMPONENT_H
Definition coreTest_SubComponent.h:38
Definition coreTest_SubComponent.h:300
Definition coreTest_SubComponent.h:191
Definition coreTest_SubComponent.h:242
Definition coreTest_SubComponent.h:62
Definition coreTest_SubComponent.h:144
Definition coreTest_SubComponent.h:93
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45
Base class for Events - Items sent across links to communicate between components.
Definition event.h:35
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file.
Definition output.h:54
Parameter store.
Definition params.h:58
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:373
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29