MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / search_refine

Method search_refine

src/core/impl/graph/seq_sublinear_memory.cpp:764–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764void SeqModifierForSublinearMemory::ActionSearcherSingleCN::search_refine() {
765 size_t lower_bound = static_cast<size_t>(m_par_modifier->m_config->lb_memory_mb)
766 << 20;
767 if (m_min_bottleneck >= lower_bound)
768 return;
769 OprFootprint footprint;
770 ThinHashSet<OperatorNodeBase*> dup_oprs_set;
771 auto get_computation = [&](OperatorNodeBase* opr) {
772 return footprint.get_computation(opr);
773 };
774 auto cmp = [&](size_t idx_a, size_t idx_b) {
775 auto a = m_cur_opr_seq->at(idx_a);
776 auto b = m_cur_opr_seq->at(idx_b);
777 return get_computation(a) > get_computation(b);
778 };
779 for (auto&& i : m_action) {
780 for (auto&& opr : i.second) {
781 dup_oprs_set.insert(opr);
782 }
783 }
784 std::vector<size_t> opr_idx;
785 for (size_t idx = 0; idx < m_cur_opr_seq->size(); ++idx)
786 if (dup_oprs_set.count(m_cur_opr_seq->at(idx)))
787 opr_idx.push_back(idx);
788 std::sort(opr_idx.begin(), opr_idx.end(), cmp);
789
790 auto split_point_set = make_split_point_set(*m_best_sps);
791 for (size_t i = 0; i < opr_idx.size(); ++i) {
792 bool flag = true;
793 split_point_set->push_back(opr_idx[i]);
794 sort(split_point_set->begin(), split_point_set->end());
795 auto f = [&] {
796 ModifyActionPlanner* planner =
797 m_par_modifier->m_thread2planner.at(std::this_thread::get_id())
798 .get();
799 planner->init_seq(*m_cur_opr_seq);
800 auto cur = planner->get_memory_bottleneck(split_point_set);
801 if (cur >= lower_bound) {
802 planner->get_prev_action(m_action);
803 flag = false;
804 }
805 };
806 m_par_modifier->m_planner_thread_pool.launch(f).get();
807 if (!flag)
808 break;
809 }
810}
811
812const SeqModifierForSublinearMemory::SeqModifyAction& SeqModifierForSublinearMemory::
813 ActionSearcherSingleCN::search(CompNode comp_node, const OprNodeArray* seq) {

Callers

nothing calls this directly

Calls 14

sortFunction · 0.85
get_computationMethod · 0.80
get_memory_bottleneckMethod · 0.80
get_prev_actionMethod · 0.80
atMethod · 0.45
insertMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected