00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CORE_INTERFACES_SIMPLENETWORK_H_
00015 #define CORE_INTERFACES_SIMPLENETWORK_H_
00016
00017 #include <string>
00018 #include <unordered_map>
00019
00020 #include <sst/core/sst_types.h>
00021 #include <sst/core/subcomponent.h>
00022 #include <sst/core/params.h>
00023
00024 namespace SST {
00025
00026 class Component;
00027 class Event;
00028 class Link;
00029
00030 namespace Interfaces {
00031
00032
00033
00034
00035
00036 class SimpleNetwork : public SubComponent {
00037
00038 public:
00039
00040 typedef int64_t nid_t;
00041
00042 static const nid_t INIT_BROADCAST_ADDR;
00043
00044
00045
00046
00047 class Request {
00048
00049
00050 public:
00051 nid_t dest;
00052 nid_t src;
00053 int vn;
00054 size_t size_in_bits;
00055 bool head;
00056 bool tail;
00057
00058 private:
00059 Event* payload;
00060
00061 public:
00062
00063
00064
00065
00066
00067 inline void givePayload(Event *event) {
00068 payload = event;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 inline Event* takePayload() {
00078 Event* ret = payload;
00079 payload = NULL;
00080 return ret;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090 inline Event* inspectPayload() {
00091 return payload;
00092 }
00093
00094
00095
00096
00097 typedef enum {
00098 NONE,
00099 ROUTE,
00100 FULL
00101 } TraceType;
00102
00103
00104
00105 Request() :
00106 dest(0), src(0), size_in_bits(0), head(false), tail(false), payload(NULL),
00107 trace(NONE), traceID(0)
00108 {}
00109
00110 Request(nid_t dest, nid_t src, size_t size_in_bits,
00111 bool head, bool tail, Event* payload = NULL) :
00112 dest(dest), src(src), size_in_bits(size_in_bits), head(head), tail(tail), payload(payload),
00113 trace(NONE), traceID(0)
00114 {
00115 }
00116
00117 virtual ~Request()
00118 {
00119 if ( payload != NULL ) delete payload;
00120 }
00121
00122 inline Request* clone() {
00123 Request* req = new Request(*this);
00124
00125
00126 if ( payload != NULL ) req->payload = payload->clone();
00127 return req;
00128 }
00129
00130 void setTraceID(int id) {traceID = id;}
00131 void setTraceType(TraceType type) {trace = type;}
00132 int getTraceID() {return traceID;}
00133 TraceType getTraceType() {return trace;}
00134
00135 protected:
00136 TraceType trace;
00137 int traceID;
00138
00139 private:
00140
00141 friend class boost::serialization::access;
00142 template<class Archive>
00143 void
00144 serialize(Archive & ar, const unsigned int version );
00145
00146 };
00147
00148
00149
00150 class NetworkInspector : public SubComponent {
00151
00152 public:
00153 NetworkInspector(Component* parent) :
00154 SubComponent(parent)
00155 {}
00156
00157 virtual ~NetworkInspector() {}
00158
00159 virtual void inspectNetworkData(Request* req) = 0;
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 virtual void initialize(std::string id) = 0;
00170 };
00171
00172
00173 class HandlerBase {
00174 public:
00175 virtual bool operator()(int) = 0;
00176 virtual ~HandlerBase() {}
00177 };
00178
00179
00180
00181
00182
00183
00184 template <typename classT, typename argT = void>
00185 class Handler : public HandlerBase {
00186 private:
00187 typedef bool (classT::*PtrMember)(int, argT);
00188 classT* object;
00189 const PtrMember member;
00190 argT data;
00191
00192 public:
00193
00194
00195
00196
00197
00198 Handler( classT* const object, PtrMember member, argT data ) :
00199 object(object),
00200 member(member),
00201 data(data)
00202 {}
00203
00204 bool operator()(int vn) {
00205 return (object->*member)(vn,data);
00206 }
00207 };
00208
00209
00210
00211
00212 template <typename classT>
00213 class Handler<classT, void> : public HandlerBase {
00214 private:
00215 typedef bool (classT::*PtrMember)(int);
00216 classT* object;
00217 const PtrMember member;
00218
00219 public:
00220
00221
00222
00223
00224 Handler( classT* const object, PtrMember member ) :
00225 object(object),
00226 member(member)
00227 {}
00228
00229 bool operator()(int vn) {
00230 return (object->*member)(vn);
00231 }
00232 };
00233
00234
00235
00236
00237
00238 class Mapping {
00239 private:
00240 friend class boost::serialization::access;
00241 template<class Archive>
00242 void
00243 serialize(Archive & ar, const unsigned int version );
00244
00245 friend class SimpleNetwork;
00246 std::vector<nid_t>* data;
00247
00248 public:
00249 nid_t operator[](nid_t from) const;
00250 void bind(std::string name);
00251
00252 };
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 static void addMappingEntry(std::string mapName, nid_t from, nid_t to);
00264
00265
00266
00267
00268 static void exchangeMappingData();
00269
00270 private:
00271 static std::map<std::string,std::vector<nid_t> > network_maps;
00272
00273
00274
00275
00276
00277
00278 static std::vector<nid_t>* getMappingVector(std::string mapName);
00279
00280 public:
00281
00282
00283 SimpleNetwork(SST::Component *comp) :
00284 SubComponent(comp)
00285 { }
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 virtual bool initialize(const std::string &portName, const UnitAlgebra& link_bw,
00297 int vns, const UnitAlgebra& in_buf_size,
00298 const UnitAlgebra& out_buf_size) = 0;
00299
00300
00301
00302
00303 virtual void sendInitData(Request *req) = 0;
00304
00305
00306
00307
00308
00309 virtual Request* recvInitData() = 0;
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 virtual bool send(Request *req, int vn) = 0;
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 virtual Request* recv(int vn) = 0;
00332
00333 virtual void setup() {}
00334 virtual void init(unsigned int phase) {}
00335 virtual void finish() {}
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 virtual bool spaceToSend(int vn, int num_bits) = 0;
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 virtual bool requestToReceive( int vn ) = 0;
00356
00357
00358
00359
00360
00361
00362
00363
00364 virtual void setNotifyOnReceive(HandlerBase* functor) = 0;
00365
00366
00367
00368
00369
00370
00371
00372 virtual void setNotifyOnSend(HandlerBase* functor) = 0;
00373
00374
00375
00376
00377
00378
00379
00380 virtual bool isNetworkInitialized() const = 0;
00381
00382
00383
00384
00385
00386
00387 virtual nid_t getEndpointID() const = 0;
00388
00389
00390
00391
00392
00393
00394
00395 virtual const UnitAlgebra& getLinkBW() const = 0;
00396
00397
00398 };
00399
00400 }
00401 }
00402
00403 BOOST_CLASS_EXPORT_KEY(SST::Interfaces::SimpleNetwork::Request);
00404
00405 #endif