/home/runner/work/charm/charm/src/ck-ldb/CentralLB.h
Line | Count | Source |
1 | | /** |
2 | | * \addtogroup CkLdb |
3 | | */ |
4 | | /*@{*/ |
5 | | |
6 | | #ifndef CENTRALLB_H |
7 | | #define CENTRALLB_H |
8 | | |
9 | | #include "BaseLB.h" |
10 | | #include "CentralLB.decl.h" |
11 | | |
12 | | #include <vector> |
13 | | #include "pup_stl.h" |
14 | | #include "manager.h" |
15 | | extern CkGroupID loadbalancer; |
16 | | |
17 | | void CreateCentralLB(); |
18 | | |
19 | | class CLBStatsMsg; |
20 | | class LBSimulation; |
21 | | |
22 | | /// for backward compatibility |
23 | | typedef LBMigrateMsg CLBMigrateMsg; |
24 | | |
25 | | class LBInfo |
26 | | { |
27 | | public: |
28 | | LBRealType *peLoads; // total load: object + background |
29 | | LBRealType *objLoads; // total obj load |
30 | | LBRealType *comLoads; // total comm load |
31 | | LBRealType *bgLoads; // background load |
32 | | int numPes; |
33 | | int msgCount; // total non-local communication |
34 | | CmiUInt8 msgBytes; // total non-local communication |
35 | | LBRealType minObjLoad, maxObjLoad; |
36 | | LBInfo(): peLoads(NULL), objLoads(NULL), comLoads(NULL), |
37 | | bgLoads(NULL), numPes(0), msgCount(0), |
38 | 0 | msgBytes(0), minObjLoad(0.0), maxObjLoad(0.0) {} |
39 | | LBInfo(LBRealType *pl, int count): peLoads(pl), objLoads(NULL), |
40 | | comLoads(NULL), bgLoads(NULL), numPes(count), msgCount(0), |
41 | 0 | msgBytes(0), minObjLoad(0.0), maxObjLoad(0.0) {} |
42 | | LBInfo(int count); |
43 | | ~LBInfo(); |
44 | | void getInfo(BaseLB::LDStats* stats, int count, int considerComm); |
45 | | void clear(); |
46 | | void print(); |
47 | | void getSummary(LBRealType &maxLoad, LBRealType &maxCpuLoad, LBRealType &totalLoad); |
48 | | }; |
49 | | |
50 | | /** added by Abhinav |
51 | | * class for computing the parent and children of a processor |
52 | | */ |
53 | | class SpanningTree |
54 | | { |
55 | | public: |
56 | | int arity; |
57 | | int parent; |
58 | | int numChildren; |
59 | | SpanningTree(); |
60 | | void calcParent(int n); |
61 | | void calcNumChildren(int n); |
62 | | }; |
63 | | |
64 | | class CentralLB : public CBase_CentralLB |
65 | | { |
66 | | private: |
67 | | CLBStatsMsg *statsMsg; |
68 | | int count_msgs; |
69 | | void initLB(const CkLBOptions &); |
70 | | public: |
71 | | CkMarshalledCLBStatsMessage bufMsg; |
72 | | SpanningTree st; |
73 | 100 | CentralLB(const CkLBOptions & opt) : CBase_CentralLB(opt), concurrent(false) { initLB(opt); |
74 | | #if CMK_SHRINK_EXPAND |
75 | | manager_init(); |
76 | | #endif |
77 | 100 | } _ZN9CentralLBC2ERK11CkLBOptions Line | Count | Source | 73 | 100 | CentralLB(const CkLBOptions & opt) : CBase_CentralLB(opt), concurrent(false) { initLB(opt); | 74 | | #if CMK_SHRINK_EXPAND | 75 | | manager_init(); | 76 | | #endif | 77 | 100 | } |
Unexecuted instantiation: _ZN9CentralLBC1ERK11CkLBOptions |
78 | 0 | CentralLB(CkMigrateMessage *m) : CBase_CentralLB(m), concurrent(false) { |
79 | | #if CMK_SHRINK_EXPAND |
80 | | manager_init(); |
81 | | #endif |
82 | 0 | } |
83 | | #if defined(TEMP_LDB) |
84 | | float getTemp(int); |
85 | | FILE* logFD; |
86 | | int physicalCoresPerNode; |
87 | | int logicalCoresPerNode,numSockets; |
88 | | int logicalCoresPerChip; |
89 | | #endif |
90 | | |
91 | | virtual ~CentralLB(); |
92 | | |
93 | | void pup(PUP::er &p); |
94 | | |
95 | | void SetPESpeed(int); |
96 | | int GetPESpeed(); |
97 | 0 | inline void setConcurrent(bool c) { concurrent = c; } |
98 | | |
99 | | void InvokeLB(); // Everything is at the PE barrier |
100 | | // Second half of InvokeLB on a CUDA build: runs once the process's |
101 | | // per-object GPU loads for this round exist. |
102 | | void gpuLoadsReady(); |
103 | | void ProcessAtSync(void); // Receive a message from AtSync to avoid |
104 | | // making projections output look funny |
105 | | void SendStats(); |
106 | | void ReceiveCounts(int *counts, int n); |
107 | | void ReceiveStats(CkMarshalledCLBStatsMessage &&msg); // Receive stats on PE 0 |
108 | | void ReceiveStatsViaTree(CkMarshalledCLBStatsMessage &&msg); // Receive stats using a tree structure |
109 | | void ReceiveStatsFromRoot(CkMarshalledCLBStatsMessage &&msg); |
110 | | |
111 | | void depositData(CLBStatsMsg *m); |
112 | | void LoadBalance(void); |
113 | | void t_LoadBalance(void); |
114 | | void ApplyDecision(void); |
115 | | void ResumeClients(int); // Resuming clients needs |
116 | | |
117 | | void ResumeClients(); // to be resumed via message |
118 | | void InitiateScatter(LBMigrateMsg *msg); |
119 | | void ScatterMigrationResults(LBScatterMsg *); |
120 | | void ReceiveMigration(LBScatterMsg *); |
121 | | void ReceiveMigration(LBMigrateMsg *); // Receive migration data |
122 | | void ProcessMigrationDecision(); |
123 | | void ProcessReceiveMigration(); |
124 | | void MissMigrate(int waitForBarrier); |
125 | | |
126 | | //Shrink-Expand related functions |
127 | | void CheckForRealloc (); |
128 | | void ResumeFromReallocCheckpoint(); |
129 | | void MigrationDoneImpl (int ); |
130 | | void WillIbekilled(std::vector<char> avail, int); |
131 | | void StartCleanup(); |
132 | | |
133 | | // manual start load balancing |
134 | 8 | inline void StartLB() { thisProxy.ProcessAtSync(); } |
135 | | |
136 | | // Migrated-element callback |
137 | | void Migrated(int waitBarrier=1); |
138 | | |
139 | | void MigrationDone(int balancing); // Call when migration is complete |
140 | | void CheckMigrationComplete(); // Call when all migration is complete |
141 | | |
142 | | // IMPLEMENTATION FOR FUTURE PREDICTOR |
143 | | void FuturePredictor(LDStats* stats); |
144 | | |
145 | | struct FutureModel { |
146 | | int cur_stats; // number of statistics currently present |
147 | | int start_stats; // next stat to be written |
148 | | std::vector<LDStats> collection; |
149 | | LBPredictorFunction *predictor; |
150 | | std::vector<std::vector<double>> parameters; |
151 | | std::vector<bool> model_valid; |
152 | | |
153 | 0 | FutureModel() : FutureModel(0, new DefaultFunction()) {} |
154 | | |
155 | 8 | FutureModel(int n) : FutureModel(n, new DefaultFunction()) {} |
156 | | |
157 | | FutureModel(int n, LBPredictorFunction* myfunc) |
158 | 8 | : cur_stats(0), start_stats(0), collection(n), predictor(myfunc) |
159 | 8 | { |
160 | 8 | } |
161 | | |
162 | 0 | ~FutureModel() { |
163 | 0 | delete predictor; |
164 | 0 | } |
165 | | |
166 | | void changePredictor(LBPredictorFunction* new_predictor) |
167 | 0 | { |
168 | 0 | // gain control of the provided predictor |
169 | 0 | delete predictor; |
170 | 0 | predictor = new_predictor; |
171 | 0 |
|
172 | 0 | for (auto& param_list : parameters) |
173 | 0 | { |
174 | 0 | param_list.resize(new_predictor->num_params); |
175 | 0 | } |
176 | 0 | model_valid.assign(model_valid.size(), false); |
177 | 0 | } |
178 | | }; |
179 | | |
180 | | // create new predictor, if one already existing, delete it first |
181 | | // if "pred" == 0 then the default function is used |
182 | 0 | void predictorOn(LBPredictorFunction *pred) { |
183 | 0 | predictorOn(pred, _lb_predict_window); |
184 | 0 | } |
185 | 0 | void predictorOn(LBPredictorFunction *pred, int window_size) { |
186 | 0 | if (predicted_model) { |
187 | 0 | PredictorPrintf("Predictor already allocated\n"); |
188 | 0 | } else { |
189 | 0 | _lb_predict_window = window_size; |
190 | 0 | if (pred) predicted_model = new FutureModel(window_size, pred); |
191 | 0 | else predicted_model = new FutureModel(window_size); |
192 | 0 | _lb_predict = true; |
193 | 0 | } |
194 | 0 | PredictorPrintf("Predictor turned on, window size %d\n",window_size); |
195 | 0 | } Unexecuted instantiation: _ZN9CentralLB11predictorOnEP19LBPredictorFunctioni Unexecuted instantiation: _ZN9CentralLB11predictorOnEP19LBPredictorFunctioni |
196 | | |
197 | | // deallocate the predictor |
198 | 0 | void predictorOff() { |
199 | 0 | if (predicted_model) delete predicted_model; |
200 | 0 | predicted_model = 0; |
201 | 0 | _lb_predict = false; |
202 | 0 | PredictorPrintf("Predictor turned off\n"); |
203 | 0 | } Unexecuted instantiation: _ZN9CentralLB12predictorOffEv Unexecuted instantiation: _ZN9CentralLB12predictorOffEv |
204 | | |
205 | | // change the function of the predictor, at runtime |
206 | | // it will do nothing if it does not exist |
207 | 0 | void changePredictor(LBPredictorFunction *new_predictor) { |
208 | 0 | if (predicted_model) { |
209 | 0 | predicted_model->changePredictor(new_predictor); |
210 | 0 | PredictorPrintf("Predictor model changed\n"); |
211 | 0 | } |
212 | 0 | } Unexecuted instantiation: _ZN9CentralLB15changePredictorEP19LBPredictorFunction Unexecuted instantiation: _ZN9CentralLB15changePredictorEP19LBPredictorFunction |
213 | | // END IMPLEMENTATION FOR FUTURE PREDICTOR |
214 | | |
215 | 0 | LBMigrateMsg* callStrategy(LDStats* stats,int count){ |
216 | 0 | return Strategy(stats); |
217 | 0 | }; |
218 | | |
219 | | int cur_ld_balancer; |
220 | | |
221 | | void readStatsMsgs(const char* filename); |
222 | | void writeStatsMsgs(const char* filename); |
223 | | |
224 | | void removeCommDataOfDeletedObjs(LDStats* stats); |
225 | | void preprocess(LDStats* stats); |
226 | | virtual LBMigrateMsg* Strategy(LDStats* stats); |
227 | | virtual void work(LDStats* stats); |
228 | | virtual void changeFreq(int n); |
229 | | virtual LBMigrateMsg * createMigrateMsg(LDStats* stats); |
230 | | virtual LBMigrateMsg * extractMigrateMsg(LBMigrateMsg *m, int p); |
231 | | |
232 | | // Not to be used -- maintained for legacy applications |
233 | 0 | virtual LBMigrateMsg* Strategy(LDStats* stats, int nprocs) { |
234 | 0 | return Strategy(stats); |
235 | 0 | } |
236 | | |
237 | | protected: |
238 | 0 | virtual bool QueryBalanceNow(int) { return true; }; |
239 | 0 | virtual bool QueryDumpData() { return false; }; |
240 | 385 | virtual void LoadbalanceDone(int balancing) {} |
241 | | |
242 | | void simulationRead(); |
243 | | void simulationWrite(); |
244 | | void findSimResults(LDStats* stats, int count, |
245 | | LBMigrateMsg* msg, LBSimulation* simResults); |
246 | | void removeNonMigratable(LDStats* statsDataList, int count); |
247 | 0 | void loadbalance_with_thread() { use_thread = true; } |
248 | | |
249 | | bool concurrent; |
250 | | private: |
251 | | int myspeed; |
252 | | int stats_msg_count; |
253 | | CLBStatsMsg **statsMsgsList; |
254 | | LDStats *statsData; |
255 | | int migrates_completed; |
256 | | int migrates_expected; |
257 | | int future_migrates_completed; |
258 | | int future_migrates_expected; |
259 | | int lbdone; |
260 | | double start_lb_time; |
261 | | double strat_start_time; |
262 | | LBMigrateMsg *storedMigrateMsg; |
263 | | LBScatterMsg *storedScatterMsg; |
264 | | bool reduction_started; |
265 | | bool use_thread; |
266 | | |
267 | | FutureModel *predicted_model; |
268 | | |
269 | | void BuildStatsMsg(); |
270 | | void buildStats(); |
271 | | void printStrategyStats(LBMigrateMsg *msg); |
272 | | |
273 | | public: |
274 | | int useMem(); |
275 | | }; |
276 | | |
277 | | |
278 | | // CLBStatsMsg is not directly sent in the entry function |
279 | | // CkMarshalledCLBStatsMessage is used instead to use the pup defined here. |
280 | | //class CLBStatsMsg: public CMessage_CLBStatsMsg { |
281 | | class CLBStatsMsg { |
282 | | public: |
283 | | #if defined(TEMP_LDB) |
284 | | float pe_temp; |
285 | | #endif |
286 | | |
287 | | int from_pe; |
288 | | int pe_speed; |
289 | | #if CMK_CUDA |
290 | | // GPU this PE is mapped to and that device's SM count; see |
291 | | // BaseLB::ProcStats, into which these are copied on arrival. |
292 | | uint64_t gpu_device_id; |
293 | | int gpu_total_sms; |
294 | | #endif |
295 | | LBRealType total_walltime; |
296 | | LBRealType idletime; |
297 | | LBRealType bg_walltime; |
298 | | #if CMK_LB_CPUTIMER |
299 | | LBRealType total_cputime; |
300 | | LBRealType bg_cputime; |
301 | | #endif |
302 | | std::vector<LDObjData> objData; |
303 | | std::vector<LDCommData> commData; |
304 | | |
305 | | std::vector<char> avail_vector; |
306 | | int next_lb; |
307 | | |
308 | | public: |
309 | | CLBStatsMsg(int osz, int csz); |
310 | 493 | CLBStatsMsg(): from_pe(0), pe_speed(0), |
311 | | #if CMK_CUDA |
312 | | gpu_device_id((uint64_t)-1), gpu_total_sms(0), |
313 | | #endif |
314 | 493 | total_walltime(0.0), idletime(0.0), |
315 | 493 | bg_walltime(0.0), |
316 | | #if defined(TEMP_LDB) |
317 | | pe_temp(1.0), |
318 | | #endif |
319 | | |
320 | | #if CMK_LB_CPUTIMER |
321 | | total_cputime(0.0), bg_cputime(0.0), |
322 | | #endif |
323 | 493 | next_lb(0) {} |
324 | | ~CLBStatsMsg(); |
325 | | void pup(PUP::er &p); |
326 | | }; |
327 | | |
328 | | |
329 | | // compute load distribution info |
330 | | void getLoadInfo(BaseLB::LDStats* stats, int count, LBInfo &info, int considerComm); |
331 | | |
332 | | #endif /* CENTRALLB_H */ |
333 | | |
334 | | /*@}*/ |
335 | | |
336 | | |