SST  13.1.0
Structural Simulation Toolkit
coreTest_SubComponent.h
1 // Copyright 2009-2023 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-2023, 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 <vector>
20 
21 namespace SST {
22 namespace 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 
38 {
39 public:
40  SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestSubComponent::SubCompInterface)
41 
42  SubCompInterface(ComponentId_t id) : SubComponent(id) {}
43  SubCompInterface(ComponentId_t id, Params& UNUSED(params)) : SubComponent(id) {}
44  virtual ~SubCompInterface() {}
45  virtual void clock(SST::Cycle_t) {}
46 };
47 
49 {
50 public:
51  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSlotInterface,
53 
54  SST_ELI_DOCUMENT_PARAMS(
55  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"}
56  )
57 
58  SST_ELI_DOCUMENT_PORTS(
59  {"test", "Just a test port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
60  )
61 
62  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
63  )
64 
65  SubCompSlotInterface(ComponentId_t id) : SubCompInterface(id) {}
66  SubCompSlotInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
67  virtual ~SubCompSlotInterface() {}
68 };
69 
70 /* Our trivial component */
72 {
73 public:
74  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
75  SST_ELI_REGISTER_COMPONENT(
77  "coreTestElement",
78  "SubComponentLoader",
79  SST_ELI_ELEMENT_VERSION(1,0,0),
80  "Demonstrates subcomponents",
81  COMPONENT_CATEGORY_UNCATEGORIZED
82  )
83 
84  SST_ELI_DOCUMENT_PARAMS(
85  {"clock", "Clock Rate", "1GHz"},
86  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
87  {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
88  )
89 
90  SST_ELI_DOCUMENT_STATISTICS(
91  {"totalSent", "# of total messages sent", "", 1},
92  )
93 
94  // This ports will be used only by unnamed SubComponents
95  SST_ELI_DOCUMENT_PORTS(
96  {"port%d", "Sending or Receiving Port(s)", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
97  )
98 
99  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
100  {"mySubComp", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
101  )
102 
103  SubComponentLoader(ComponentId_t id, SST::Params& params);
104 
105 private:
106  bool tick(SST::Cycle_t);
107  std::vector<SubCompInterface*> subComps;
108 };
109 
110 /* Our example subcomponents */
112 {
113 public:
114  SST_ELI_REGISTER_SUBCOMPONENT(
115  SubCompSlot,
116  "coreTestElement",
117  "SubCompSlot",
118  SST_ELI_ELEMENT_VERSION(1,0,0),
119  "Subcomponent which is just a wrapper for the actual SubComponent to be used",
121  )
122 
123  SST_ELI_DOCUMENT_PARAMS(
124  {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""}
125  )
126 
127  // Only used when loading unnamed SubComponents
128  SST_ELI_DOCUMENT_PORTS(
129  {"slot_port%d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
130  )
131 
132  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
133  {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
134  )
135 
136 private:
137  std::vector<SubCompInterface*> subComps;
138 
139 public:
140  SubCompSlot(ComponentId_t id, Params& params);
141  // Direct load
142  SubCompSlot(ComponentId_t id, std::string unnamed_sub);
143 
144  ~SubCompSlot() {}
145  void clock(Cycle_t);
146 };
147 
148 // Add in some extra levels of ELI hierarchy for testing
150 {
151 public:
152  SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSendRecvInterface,
154 
155  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
156  SST_ELI_REGISTER_SUBCOMPONENT(
158  "coreTestElement",
159  "SubCompSendRecv",
160  SST_ELI_ELEMENT_VERSION(1,0,0),
161  "Default Subcomponent for ELI testing only",
163  )
164 
165  SST_ELI_DOCUMENT_PARAMS(
166  {"port_name", "Name of port to connect to", ""},
167  {"sendCount", "Number of Messages to Send", "10"}
168  )
169 
170  SST_ELI_DOCUMENT_PORTS(
171  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
172  // The following port is a test to make sure that when loaded
173  // anonymously, a port that's named the same as one of its
174  // parent's ports doesn't conflict.
175  {"slot_port%d", "This is just a test port that duplicates a port from the SubComponent that will instance it", { "", "" } },
176  )
177 
178  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
179  )
180 
181  SST_ELI_DOCUMENT_STATISTICS(
182  {"numRecv", "# of msgs recv", "", 1},
183  )
184 
185  SubCompSendRecvInterface(ComponentId_t id) : SubCompInterface(id) {}
186  SubCompSendRecvInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
187  virtual ~SubCompSendRecvInterface() {}
188 };
189 
191 {
192 public:
193  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
194  SST_ELI_REGISTER_SUBCOMPONENT(
196  "coreTestElement",
197  "SubCompSender",
198  SST_ELI_ELEMENT_VERSION(1,0,0),
199  "Sending Subcomponent",
201  )
202 
203  SST_ELI_DOCUMENT_PARAMS(
204  )
205 
206  SST_ELI_DOCUMENT_STATISTICS(
207  SST_ELI_DELETE_STAT("numRecv"),
208  {"numSent", "# of msgs sent", "", 1},
209  )
210 
211  SST_ELI_DOCUMENT_PORTS(
212  {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
213  )
214 
215  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
216  {"test_slot", "Test slot", "" }
217  )
218 
219 private:
220  Statistic<uint32_t>* nMsgSent;
221  Statistic<uint32_t>* totalMsgSent;
222  uint32_t nToSend;
223  SST::Link* link;
224 
225 public:
226  SubCompSender(ComponentId_t id, Params& params);
227  // Direct API
228  SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
229  ~SubCompSender() {}
230  void clock(Cycle_t);
231 };
232 
234 {
235 
236 public:
237  // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
238  SST_ELI_REGISTER_SUBCOMPONENT(
240  "coreTestElement",
241  "SubCompReceiver",
242  SST_ELI_ELEMENT_VERSION(1,0,0),
243  "Receiving Subcomponent",
245  )
246 
247  // Optional since there is nothing to document
248  SST_ELI_DOCUMENT_PARAMS(
249  SST_ELI_DELETE_PARAM("sendCount")
250  )
251 
252  SST_ELI_DOCUMENT_STATISTICS(
253  )
254 
255  SST_ELI_DOCUMENT_PORTS(
256  SST_ELI_DELETE_PORT("sendPort"),
257  {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
258  )
259 
260  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
261  SST_ELI_DELETE_SUBCOMPONENT_SLOT("test_slot")
262  )
263 
264 private:
265  Statistic<uint32_t>* nMsgReceived;
266  SST::Link* link;
267 
268  void handleEvent(SST::Event* ev);
269 
270 public:
271  SubCompReceiver(ComponentId_t id, Params& params);
272  SubCompReceiver(ComponentId_t id, std::string port);
273  ~SubCompReceiver() {}
274  void clock(Cycle_t);
275 };
276 
277 } // namespace CoreTestSubComponent
278 } // namespace SST
279 
280 #endif // SST_CORE_CORETEST_SUBCOMPONENT_H
Main component object for the simulation.
Definition: component.h:31
Definition: coreTest_SubComponent.h:38
Definition: coreTest_SubComponent.h:234
Definition: coreTest_SubComponent.h:150
Definition: coreTest_SubComponent.h:191
Definition: coreTest_SubComponent.h:49
Definition: coreTest_SubComponent.h:112
Definition: coreTest_SubComponent.h:72
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:35
Parameter store.
Definition: params.h:56
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29