| 209 | } |
| 210 | |
| 211 | Microseconds GreedyScheduler::ComputeSchedule( |
| 212 | std::vector<Microseconds>* start_times) { |
| 213 | // Initialize pending_count |
| 214 | std::vector<int> pending_count(graph_->num_node_ids()); |
| 215 | InitializePending(graph_, &pending_count); |
| 216 | |
| 217 | // Initialize event queue |
| 218 | std::priority_queue<Event> event_queue; |
| 219 | Event src_event; |
| 220 | src_event.node = graph_->source_node(); |
| 221 | src_event.time = 0; |
| 222 | src_event.is_completion = true; |
| 223 | event_queue.push(src_event); |
| 224 | Microseconds max_completion = Microseconds(0); |
| 225 | |
| 226 | while (!event_queue.empty()) { |
| 227 | Event event = event_queue.top(); |
| 228 | event_queue.pop(); |
| 229 | if (event.is_completion) { |
| 230 | Sim* sim = device_states_[event.node->assigned_device_name()]; |
| 231 | --sim->num_running; |
| 232 | |
| 233 | if (event.time > max_completion) { |
| 234 | max_completion = event.time; |
| 235 | } |
| 236 | |
| 237 | for (const Edge* out_edge : event.node->out_edges()) { |
| 238 | Microseconds copy_time(0); |
| 239 | const Node* out = out_edge->dst(); |
| 240 | if (!out_edge->IsControlEdge() && |
| 241 | event.node->assigned_device_name() != out->assigned_device_name()) { |
| 242 | // TODO(yuanbyu): Use below with the real cost model. |
| 243 | // int index = out_edge->src_output(); |
| 244 | // Bytes nb = cost_model_->SizeEstimate(event.node, index); |
| 245 | // copy_time = CostModel::CopyTimeEstimate(nb); |
| 246 | copy_time = 10; |
| 247 | } |
| 248 | if ((*start_times)[out->id()] < event.time + copy_time) { |
| 249 | (*start_times)[out->id()] = event.time + copy_time; |
| 250 | } |
| 251 | |
| 252 | bool is_ready = UpdatePending(out_edge, &pending_count); |
| 253 | if (is_ready) { |
| 254 | Event e{out, (*start_times)[out->id()], false}; |
| 255 | event_queue.push(e); |
| 256 | } |
| 257 | } |
| 258 | } else { |
| 259 | Sim* sim = device_states_[event.node->assigned_device_name()]; |
| 260 | sim->ready_nodes.push_back(event.node); |
| 261 | } |
| 262 | |
| 263 | for (auto& x : device_states_) { |
| 264 | Sim* sim = x.second; |
| 265 | while (sim->num_running < sim->degree_parallelism && |
| 266 | !sim->ready_nodes.empty()) { |
| 267 | Event e; |
| 268 | e.node = GetNodeWithHighestPriority(sim->ready_nodes); |
nothing calls this directly
no test coverage detected