| 531 | }; |
| 532 | |
| 533 | void schedule::apply(module& m) const |
| 534 | { |
| 535 | if(not enable) |
| 536 | return; |
| 537 | |
| 538 | stream_info si; |
| 539 | si.calc_implicit_deps(m); |
| 540 | auto last = std::prev(m.end()); |
| 541 | si.accumulate_weights(last, model); |
| 542 | auto nstreams = si.assign_streams(m, model.concurrency()); |
| 543 | si.sort(m, model.concurrency()); |
| 544 | |
| 545 | if(enabled(MIGRAPHX_TRACE_COMPILE{}) or enabled(MIGRAPHX_TRACE_SCHEDULE{})) |
| 546 | { |
| 547 | m.annotate(std::cout, [&](auto ins) { |
| 548 | if(ins->name() == "@param" and not contains(si.weights, ins)) |
| 549 | return; |
| 550 | |
| 551 | std::cout << ":"; |
| 552 | std::cout << " weight=" << si.weights.at(ins); |
| 553 | std::cout << " input={"; |
| 554 | si.get_streams_from(ins, get_inputs())([&](auto s) { |
| 555 | std::cout << s << ","; |
| 556 | return true; |
| 557 | }); |
| 558 | std::cout << "}"; |
| 559 | if(si.has_stream(ins)) |
| 560 | std::cout << " stream=" << si.get_stream(ins); |
| 561 | }); |
| 562 | std::cout << std::endl; |
| 563 | } |
| 564 | |
| 565 | // No concurrency |
| 566 | if(nstreams < 2) |
| 567 | return; |
| 568 | |
| 569 | // Schedule instructions |
| 570 | std::size_t wait_id = 0; |
| 571 | std::unordered_map<instruction_ref, std::size_t> ins2wait; |
| 572 | std::unordered_map<std::size_t, std::unordered_set<std::size_t>> waited_for; |
| 573 | std::unordered_map<instruction_ref, std::unordered_set<std::size_t>> ins2waited; |
| 574 | ins2wait.reserve(m.size()); |
| 575 | ins2waited.reserve(m.size()); |
| 576 | for(auto ins : iterator_for(m)) |
| 577 | { |
| 578 | // Only schedule instructions that have a stream |
| 579 | if(not si.has_stream(ins)) |
| 580 | continue; |
| 581 | assert(si.weights[ins] > 0); |
| 582 | // Schedule instruction on the stream |
| 583 | auto stream = si.get_stream(ins); |
| 584 | assert(stream < model.concurrency()); |
| 585 | model.sched(m, ins, stream); |
| 586 | // Insert wait instructions |
| 587 | if(si.is_merge_point(ins, stream)) |
| 588 | { |
| 589 | for(auto i : si.get_recorded_instructions(ins)) |
| 590 | { |
no test coverage detected