SST 12.1.0
Structural Simulation Toolkit
coreTest_SubComponent.h
1// Copyright 2009-2022 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-2022, NTESS
6// All rights reserved.
7//
8// Portions are copyright of other developers:
9// See the file CONTRIBUTORS.TXT in the top level directory
10// the distribution for more information.
11//
12// This file is part of the SST software package. For license
13// information, see the LICENSE file in the top level directory of the
14// distribution.
15
16#ifndef SST_CORE_CORETEST_SUBCOMPONENT_H
17#define SST_CORE_CORETEST_SUBCOMPONENT_H
18
19#include "sst/core/component.h"
20#include "sst/core/link.h"
21#include "sst/core/subcomponent.h"
22
23#include <vector>
24
25namespace SST {
26namespace CoreTestSubComponent {
27
28/*
29
30 CoreTestSubComponent will test the various ways to use SubComponents.
31 The SubComponents will be loadable as both named and unnamed
32 SubComponets. When an unname SubComponent is used, it inherits the
33 port interface from the BaseComponent that created it. A named
34 SubComponent owns it's own ports and will mask the ports from any
35 BaseComponent higher in the call tree.
36
37 Each BaseComponent will have a port(s) that may or may not be used
38 depending on the configuration.
39 */
40
42{
43public:
44 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestSubComponent::SubCompInterface)
45
46 SubCompInterface(ComponentId_t id) : SubComponent(id) {}
47 SubCompInterface(ComponentId_t id, Params& UNUSED(params)) : SubComponent(id) {}
48 virtual ~SubCompInterface() {}
49 virtual void clock(SST::Cycle_t) {}
50};
51
53{
54public:
55 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSlotInterface,
57
58 SST_ELI_DOCUMENT_PARAMS(
59 {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"}
60 )
61
62 SST_ELI_DOCUMENT_PORTS(
63 {"test", "Just a test port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
64 )
65
66 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
67 )
68
69 SubCompSlotInterface(ComponentId_t id) : SubCompInterface(id) {}
70 SubCompSlotInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
71 virtual ~SubCompSlotInterface() {}
72};
73
74/* Our trivial component */
76{
77public:
78 // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
79 SST_ELI_REGISTER_COMPONENT(
81 "coreTestElement",
82 "SubComponentLoader",
83 SST_ELI_ELEMENT_VERSION(1,0,0),
84 "Demonstrates subcomponents",
85 COMPONENT_CATEGORY_UNCATEGORIZED
86 )
87
88 SST_ELI_DOCUMENT_PARAMS(
89 {"clock", "Clock Rate", "1GHz"},
90 {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""},
91 {"num_subcomps","Number of anonymous SubComponents to load. Ignored if using name SubComponents.","1"},
92 )
93
94 SST_ELI_DOCUMENT_STATISTICS(
95 {"totalSent", "# of total messages sent", "", 1},
96 )
97
98 // This ports will be used only by unnamed SubComponents
99 SST_ELI_DOCUMENT_PORTS(
100 {"port%d", "Sending or Receiving Port(s)", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
101 )
102
103 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
104 {"mySubComp", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
105 )
106
107 SubComponentLoader(ComponentId_t id, SST::Params& params);
108
109private:
110 bool tick(SST::Cycle_t);
111 std::vector<SubCompInterface*> subComps;
112};
113
114/* Our example subcomponents */
116{
117public:
118 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
120 "coreTestElement",
121 "SubCompSlot",
122 SST_ELI_ELEMENT_VERSION(1,0,0),
123 "Subcomponent which is just a wrapper for the actual SubComponent to be used",
125 )
126
127 SST_ELI_DOCUMENT_PARAMS(
128 {"unnamed_subcomponent", "Unnamed SubComponent to load. If empty, then a named subcomponent is loaded", ""}
129 )
130
131 // Only used when loading unnamed SubComponents
132 SST_ELI_DOCUMENT_PORTS(
133 {"slot_port%d", "Port(s) to send or receive on", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
134 )
135
136 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
137 {"mySubCompSlot", "Test slot", "SST::CoreTestSubComponent::SubCompInterface" }
138 )
139
140private:
141 std::vector<SubCompInterface*> subComps;
142
143public:
144 SubCompSlot(ComponentId_t id, Params& params);
145 // Direct load
146 SubCompSlot(ComponentId_t id, std::string unnamed_sub);
147
148 ~SubCompSlot() {}
149 void clock(Cycle_t);
150};
151
152// Add in some extra levels of ELI hierarchy for testing
154{
155public:
156 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED_API(SST::CoreTestSubComponent::SubCompSendRecvInterface,
158
159 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
160 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
162 "coreTestElement",
163 "SubCompSendRecv",
164 SST_ELI_ELEMENT_VERSION(1,0,0),
165 "Default Subcomponent for ELI testing only",
167 )
168
169 SST_ELI_DOCUMENT_PARAMS(
170 {"port_name", "Name of port to connect to", ""},
171 {"sendCount", "Number of Messages to Send", "10"}
172 )
173
174 SST_ELI_DOCUMENT_PORTS(
175 {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
176 // The following port is a test to make sure that when loaded
177 // anonymously, a port that's named the same as one of its
178 // parent's ports doesn't conflict.
179 {"slot_port%d", "This is just a test port that duplicates a port from the SubComponent that will instance it", { "", "" } },
180 )
181
182 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
183 )
184
185 SST_ELI_DOCUMENT_STATISTICS(
186 {"numRecv", "# of msgs recv", "", 1},
187 )
188
189 SubCompSendRecvInterface(ComponentId_t id) : SubCompInterface(id) {}
190 SubCompSendRecvInterface(ComponentId_t id, Params& UNUSED(params)) : SubCompInterface(id) {}
191 virtual ~SubCompSendRecvInterface() {}
192};
193
195{
196public:
197 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
198 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
200 "coreTestElement",
201 "SubCompSender",
202 SST_ELI_ELEMENT_VERSION(1,0,0),
203 "Sending Subcomponent",
205 )
206
207 SST_ELI_DOCUMENT_PARAMS(
208 )
209
210 SST_ELI_DOCUMENT_STATISTICS(
211 SST_ELI_DELETE_STAT("numRecv"),
212 {"numSent", "# of msgs sent", "", 1},
213 )
214
215 SST_ELI_DOCUMENT_PORTS(
216 {"sendPort", "Sending Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
217 )
218
219 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
220 {"test_slot", "Test slot", "" }
221 )
222
223private:
224 Statistic<uint32_t>* nMsgSent;
225 Statistic<uint32_t>* totalMsgSent;
226 uint32_t nToSend;
227 SST::Link* link;
228
229public:
230 SubCompSender(ComponentId_t id, Params& params);
231 // Direct API
232 SubCompSender(ComponentId_t id, uint32_t nToSend, const std::string& port_name);
233 ~SubCompSender() {}
234 void clock(Cycle_t);
235};
236
238{
239
240public:
241 // REGISTER THIS SUB-COMPONENT INTO THE ELEMENT LIBRARY
242 SST_ELI_REGISTER_SUBCOMPONENT_DERIVED(
244 "coreTestElement",
245 "SubCompReceiver",
246 SST_ELI_ELEMENT_VERSION(1,0,0),
247 "Receiving Subcomponent",
249 )
250
251 // Optional since there is nothing to document
252 SST_ELI_DOCUMENT_PARAMS(
253 SST_ELI_DELETE_PARAM("sendCount")
254 )
255
256 SST_ELI_DOCUMENT_STATISTICS(
257 )
258
259 SST_ELI_DOCUMENT_PORTS(
260 SST_ELI_DELETE_PORT("sendPort"),
261 {"recvPort", "Receiving Port", { "coreTestMessageGeneratorComponent.coreTestMessage", "" } },
262 )
263
264 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
265 SST_ELI_DELETE_SUBCOMPONENT_SLOT("test_slot")
266 )
267
268private:
269 Statistic<uint32_t>* nMsgReceived;
270 SST::Link* link;
271
272 void handleEvent(SST::Event* ev);
273
274public:
275 SubCompReceiver(ComponentId_t id, Params& params);
276 SubCompReceiver(ComponentId_t id, std::string port);
278 void clock(Cycle_t);
279};
280
281} // namespace CoreTestSubComponent
282} // namespace SST
283
284#endif // SST_CORE_CORETEST_SUBCOMPONENT_H
Main component object for the simulation.
Definition: component.h:31
Definition: coreTest_SubComponent.h:42
Definition: coreTest_SubComponent.h:238
Definition: coreTest_SubComponent.h:154
Definition: coreTest_SubComponent.h:195
Definition: coreTest_SubComponent.h:53
Definition: coreTest_SubComponent.h:116
Definition: coreTest_SubComponent.h:76
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:35
Parameter store.
Definition: params.h:56
Forms the template defined base class for statistics gathering within SST.
Definition: statbase.h:361
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29