-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadyAndGo.cc
49 lines (43 loc) · 1.31 KB
/
ReadyAndGo.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "SwitchML_m.h"
#include <unordered_map>
using namespace omnetpp;
/**
* No scheduling, only synchronize among workers
*/
class ReadyAndGo: public cSimpleModule {
private:
std::unordered_map<TensorKey, std::vector<CollectiveOperationRequest*>> queue { };
void initialize() override;
void handleMessage(cMessage *msg) override;
};
Define_Module(ReadyAndGo);
void ReadyAndGo::initialize() {
}
void ReadyAndGo::handleMessage(cMessage *msg) {
switch (msg->getKind()) {
case 0: {
// AllreduceRequest from TrainingProcess
auto request = check_and_cast<CollectiveOperationRequest*>(msg);
auto &requests = queue[request->getTensor_key()];
requests.push_back(request);
if (requests.size() == request->getNum_workers_allocated()) {
for (auto req : requests) {
auto worker = this->getSimulation()->getModule(
req->getWorker_id());
this->sendDirect(req, worker, "directin");
}
queue.erase(request->getTensor_key());
}
break;
}
case 2: {
// CollectiveOperationRequest from Worker, meaning allreduce is done
delete msg;
break;
}
default:
delete msg;
EV_FATAL << "got unexpected message" << endl;
break;
}
}