SST 16.0.0
Structural Simulation Toolkit
simpleNetwork.h
1// -*- mode: c++ -*-
2// Copyright 2009-2026 NTESS. Under the terms
3// of Contract DE-NA0003525 with NTESS, the U.S.
4// Government retains certain rights in this software.
5//
6// Copyright (c) 2009-2026, NTESS
7// All rights reserved.
8//
9// This file is part of the SST software package. For license
10// information, see the LICENSE file in the top level directory of the
11// distribution.
12//
13
14#ifndef SST_CORE_INTERFACES_SIMPLENETWORK_H
15#define SST_CORE_INTERFACES_SIMPLENETWORK_H
16
17#include "sst/core/params.h"
18#include "sst/core/serialization/serializable.h"
19#include "sst/core/sst_types.h"
20#include "sst/core/ssthandler.h"
21#include "sst/core/subcomponent.h"
22#include "sst/core/warnmacros.h"
23
24#include <cstdint>
25#include <string>
26#include <unordered_map>
27
28namespace SST {
29class Component;
30class Event;
31class Link;
32} // namespace SST
33
34namespace SST::Interfaces {
35
36/**
37 * Generic network interface
38 */
39class SimpleNetwork : public SubComponent
40{
41public:
42 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::Interfaces::SimpleNetwork, int)
43
44 /** All Addresses can be 64-bit */
45 using nid_t = int64_t;
46#define PRI_NID PRIi64
47
48 static const nid_t INIT_BROADCAST_ADDR;
49
50 /**
51 * Represents both network sends and receives
52 */
54 {
55
56 public:
57 nid_t dest; /*!< Node ID of destination */
58 nid_t src; /*!< Node ID of source */
59 int vn; /*!< Virtual network of packet */
60 size_t size_in_bits; /*!< Size of packet in bits */
61 bool head; /*!< True if this is the head of a stream */
62 bool tail; /*!< True if this is the tail of a steram */
63 bool allow_adaptive; /*!< Indicates whether adaptive routing is allowed or not. */
64
65 private:
66 Event* payload; /*!< Payload of the request */
67
68 public:
69 /**
70 Sets the payload field for this request
71 @param payload_in Event to set as payload.
72 */
73 inline void givePayload(Event* event) { payload = event; }
74
75 /**
76 Returns the payload for the request. This will also set
77 the payload to nullptr, so the call will only return valid
78 data one time after each givePayload call.
79 @return Event that was set as payload of the request.
80 */
82 {
83 Event* ret = payload;
84 payload = nullptr;
85 return ret;
86 }
87
88 /**
89 Returns the payload for the request for inspection. This
90 call does not set the payload to nullptr, so deleting the
91 request will also delete the payload. If the request is
92 going to be deleted, use takePayload instead.
93 @return Event that was set as payload of the request.
94 */
95 inline Event* inspectPayload() { return payload; }
96
97 /**
98 * Trace types
99 */
101 NONE, /*!< No tracing enabled */
102 ROUTE, /*!< Trace route information only */
103 FULL /*!< Trace all movements of packets through network */
104 };
105
106 /** Constructor */
108 dest(0),
109 src(0),
110 size_in_bits(0),
111 head(false),
112 tail(false),
113 allow_adaptive(true),
114 payload(nullptr),
115 trace(NONE),
116 traceID(0)
117 {}
118
119 Request(nid_t dest, nid_t src, size_t size_in_bits, bool head, bool tail, Event* payload = nullptr) :
120 dest(dest),
121 src(src),
123 head(head),
124 tail(tail),
125 allow_adaptive(true),
126 payload(payload),
127 trace(NONE),
128 traceID(0)
129 {}
130
131 virtual ~Request()
132 {
133 if ( payload != nullptr ) delete payload;
134 }
135
136 inline Request* clone()
137 {
138 Request* req = new Request(*this);
139 // Copy constructor only makes a shallow copy, need to
140 // clone the event.
141 if ( payload != nullptr ) req->payload = payload->clone();
142 return req;
143 }
144
145 void setTraceID(int id) { traceID = id; }
146 void setTraceType(TraceType type) { trace = type; }
147 int getTraceID() { return traceID; }
148 TraceType getTraceType() { return trace; }
149
150 void serialize_order(SST::Core::Serialization::serializer& ser) override
151 {
152 SST_SER(dest);
153 SST_SER(src);
154 SST_SER(vn);
155 SST_SER(size_in_bits);
156 SST_SER(head);
157 SST_SER(tail);
158 SST_SER(payload);
159 SST_SER(trace);
160 SST_SER(traceID);
161 SST_SER(allow_adaptive);
162 }
163
164 protected:
165 TraceType trace;
166 int traceID;
167
168 private:
169 ImplementSerializable(SST::Interfaces::SimpleNetwork::Request)
170 };
171 /**
172 Class used to inspect network requests going through the network.
173 */
174 class NetworkInspector : public SubComponent
175 {
176
177 public:
178 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::Interfaces::SimpleNetwork::NetworkInspector,std::string)
179
180 explicit NetworkInspector(ComponentId_t id) :
181 SubComponent(id)
182 {}
183
184 explicit NetworkInspector() :
185 SubComponent()
186 {}
187
188 virtual ~NetworkInspector() {}
189
190 virtual void inspectNetworkData(Request* req) = 0;
191 };
192
193 /**
194 Base handler for event delivery.
195 */
197
198 /**
199 Used to create checkpointable handlers to notify the endpoint
200 when the SimpleNetwork sends or recieves a packet.. The
201 callback function is expected to be in the form of:
202
203 bool func(int vn)
204
205 In which case, the class is created with:
206
207 new SimpleNetwork::Handler<classname, &classname::function_name>(this)
208
209 Or, to add static data, the callback function is:
210
211 bool func(int vn, dataT data)
212
213 and the class is created with:
214
215 new SimpleNetwork::Handler<classname, &classname::function_name, dataT>(this, data)
216
217 In both cases, the boolean that's returned indicates whether
218 the handler should be kept in the list or not. On return
219 of true, the handler will be kept. On return of false, the
220 handler will be removed from the clock list.
221 */
222 template <typename classT, auto funcT, typename dataT = void>
224
225 /**
226 Used to create checkpointable handlers to notify the endpoint
227 when the SimpleNetwork sends or recieves a packet.. The
228 callback function is expected to be in the form of:
229
230 bool func(int vn)
231
232 In which case, the class is created with:
233
234 new SimpleNetwork::Handler<classname, &classname::function_name>(this)
235
236 Or, to add static data, the callback function is:
237
238 bool func(int vn, dataT data)
239
240 and the class is created with:
241
242 new SimpleNetwork::Handler<classname, &classname::function_name, dataT>(this, data)
243
244 In both cases, the boolean that's returned indicates whether
245 the handler should be kept in the list or not. On return
246 of true, the handler will be kept. On return of false, the
247 handler will be removed from the clock list.
248 */
249 template <typename classT, auto funcT, typename dataT = void>
250 using Handler2 [[deprecated(
251 "The name Handler2 has been deprecated and will be removed in SST 17. Please rename Handler2 to Handler.")]]
253
254
255public:
256 /** Constructor, designed to be used via 'loadUserSubComponent or loadAnonymousSubComponent'. */
257 explicit SimpleNetwork(SST::ComponentId_t id) :
258 SubComponent(id)
259 {}
260
261 SimpleNetwork() :
263 {} // For serialization
264
265 /**
266 * Sends a network request during untimed phases (init() and
267 * complete()).
268 * @see SST::Link::sendUntimedData()
269 */
270 virtual void sendUntimedData(Request* req) = 0;
271
272 /**
273 * Receive any data during untimed phases (init() and complete()).
274 * @see SST::Link::recvUntimedData()
275 */
276 virtual Request* recvUntimedData() = 0;
277
278 // /**
279 // * Returns a handle to the underlying SST::Link
280 // */
281 // virtual Link* getLink() const = 0;
282
283 /**
284 * Send a Request to the network.
285 */
286 virtual bool send(Request* req, int vn) = 0;
287
288 /**
289 * Receive a Request from the network.
290 *
291 * Use this method for polling-based applications.
292 * Register a handler for push-based notification of responses.
293 *
294 * @param vn Virtual network to receive on
295 * @return nullptr if nothing is available.
296 * @return Pointer to a Request response (that should be deleted)
297 */
298 virtual Request* recv(int vn) = 0;
299
300 virtual void setup() override {}
301 virtual void init(unsigned int UNUSED(phase)) override {}
302 virtual void complete(unsigned int UNUSED(phase)) override {}
303 virtual void finish() override {}
304
305 /**
306 * Checks if there is sufficient space to send on the specified
307 * virtual network
308 * @param vn Virtual network to check
309 * @param num_bits Minimum size in bits required to have space
310 * to send
311 * @return true if there is space in the output, false otherwise
312 */
313 virtual bool spaceToSend(int vn, int num_bits) = 0;
314
315 /**
316 * Checks if there is a waiting network request request pending in
317 * the specified virtual network.
318 * @param vn Virtual network to check
319 * @return true if a network request is pending in the specified
320 * virtual network, false otherwise
321 */
322 virtual bool requestToReceive(int vn) = 0;
323
324 /**
325 * Registers a functor which will fire when a new request is
326 * received from the network. Note, the actual request that
327 * was received is not passed into the functor, it is only a
328 * notification that something is available.
329 * @param functor Functor to call when request is received
330 */
331 virtual void setNotifyOnReceive(HandlerBase* functor) = 0;
332 /**
333 * Registers a functor which will fire when a request is
334 * sent to the network. Note, this only tells you when data
335 * is sent, it does not guarantee any specified amount of
336 * available space.
337 * @param functor Functor to call when request is sent
338 */
339 virtual void setNotifyOnSend(HandlerBase* functor) = 0;
340
341 /**
342 * Check to see if network is initialized. If network is not
343 * initialized, then no other functions other than init() can
344 * can be called on the interface.
345 * @return true if network is initialized, false otherwise
346 */
347 virtual bool isNetworkInitialized() const = 0;
348
349 /**
350 * Returns the endpoint ID. Cannot be called until after the
351 * network is initialized.
352 * @return Endpoint ID
353 */
354 virtual nid_t getEndpointID() const = 0;
355
356 /**
357 * Returns the final BW of the link managed by the simpleNetwork
358 * instance. Cannot be called until after the network is
359 * initialized.
360 * @return Link bandwidth of associated link
361 */
362 virtual const UnitAlgebra& getLinkBW() const = 0;
363
364 void serialize_order(SST::Core::Serialization::serializer& ser) override { SubComponent::serialize_order(ser); }
365 ImplementVirtualSerializable(SST::Interfaces::SimpleNetwork)
366};
367
368} // namespace SST::Interfaces
369
370#endif // SST_CORE_INTERFACES_SIMPLENETWORK_H
Main component object for the simulation.
Definition component.h:32
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Base class for Events - Items sent across links to communicate between components.
Definition event.h:41
virtual Event * clone()
Clones the event in for the case of a broadcast.
Definition event.cc:34
Class used to inspect network requests going through the network.
Definition simpleNetwork.h:175
Represents both network sends and receives.
Definition simpleNetwork.h:54
Event * takePayload()
Returns the payload for the request.
Definition simpleNetwork.h:81
int vn
Definition simpleNetwork.h:59
Event * inspectPayload()
Returns the payload for the request for inspection.
Definition simpleNetwork.h:95
bool head
Definition simpleNetwork.h:61
bool allow_adaptive
Definition simpleNetwork.h:63
size_t size_in_bits
Definition simpleNetwork.h:60
TraceType
Trace types.
Definition simpleNetwork.h:100
@ ROUTE
Definition simpleNetwork.h:102
@ NONE
Definition simpleNetwork.h:101
@ FULL
Definition simpleNetwork.h:103
nid_t dest
Definition simpleNetwork.h:57
Request()
Constructor.
Definition simpleNetwork.h:107
nid_t src
Definition simpleNetwork.h:58
bool tail
Definition simpleNetwork.h:62
void givePayload(Event *event)
Sets the payload field for this request.
Definition simpleNetwork.h:73
Generic network interface.
Definition simpleNetwork.h:40
virtual void setNotifyOnReceive(HandlerBase *functor)=0
Registers a functor which will fire when a new request is received from the network.
virtual void setNotifyOnSend(HandlerBase *functor)=0
Registers a functor which will fire when a request is sent to the network.
virtual Request * recv(int vn)=0
Receive a Request from the network.
virtual bool isNetworkInitialized() const =0
Check to see if network is initialized.
SSTHandlerBase< bool, int > HandlerBase
Base handler for event delivery.
Definition simpleNetwork.h:196
SimpleNetwork(SST::ComponentId_t id)
Constructor, designed to be used via 'loadUserSubComponent or loadAnonymousSubComponent'.
Definition simpleNetwork.h:257
virtual void complete(unsigned int UNUSED(phase)) override
Used during the complete phase after the end of simulation.
Definition simpleNetwork.h:302
virtual Request * recvUntimedData()=0
Receive any data during untimed phases (init() and complete()).
virtual bool send(Request *req, int vn)=0
Returns a handle to the underlying SST::Link.
virtual const UnitAlgebra & getLinkBW() const =0
Returns the final BW of the link managed by the simpleNetwork instance.
virtual void sendUntimedData(Request *req)=0
Sends a network request during untimed phases (init() and complete()).
virtual void finish() override
Called after simulation completes, but before objects are destroyed.
Definition simpleNetwork.h:303
virtual void init(unsigned int UNUSED(phase)) override
Used during the init phase.
Definition simpleNetwork.h:301
virtual bool spaceToSend(int vn, int num_bits)=0
Checks if there is sufficient space to send on the specified virtual network.
int64_t nid_t
All Addresses can be 64-bit.
Definition simpleNetwork.h:45
virtual void setup() override
Called after all components have been constructed and initialization has completed,...
Definition simpleNetwork.h:300
SSTHandler< bool, int, classT, dataT, funcT > Handler
Used to create checkpointable handlers to notify the endpoint when the SimpleNetwork sends or recieve...
Definition simpleNetwork.h:223
virtual nid_t getEndpointID() const =0
Returns the endpoint ID.
virtual bool requestToReceive(int vn)=0
Checks if there is a waiting network request request pending in the specified virtual network.
Base template for handlers which take a class defined argument.
Definition ssthandler.h:79
Base template for the class.
Definition ssthandler.h:1102
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29
Performs Unit math in full precision.
Definition unitAlgebra.h:107