| 908 | |
| 909 | template <typename Opr> |
| 910 | void AlgoChooser<Opr>::AlgoChooserHelper::profile( |
| 911 | const ExecutionStrategy& selected_strategy) const { |
| 912 | MIDOUT_B(Opr, midout_iv(MGB_HASH_STR("profile"))) |
| 913 | // some sub oprs have beed profiled before |
| 914 | // sub oprs won't be checked at the beginning of choose_by_profile |
| 915 | auto&& rst = get_profile_result_from_cache(selected_strategy); |
| 916 | // rst.first.valid means there exists valid algorithms for current opr, just return |
| 917 | // otherwise need to profile |
| 918 | // in order to avoid reprofile in fastrun |
| 919 | if (rst.first.valid()) |
| 920 | return; |
| 921 | AlgoChooserProfileCache::Result prof_rst; |
| 922 | |
| 923 | auto target_attr = extract_algo_attribute(selected_strategy); |
| 924 | std::string layouts_str = AlgoChooser::format_fixlayouts(m_fastrun_layouts); |
| 925 | double cur_timeout = 0; |
| 926 | |
| 927 | size_t data_size = 0; |
| 928 | for (auto ly : m_fastrun_layouts) |
| 929 | data_size += ly.span().dist_byte(); |
| 930 | |
| 931 | auto workspace_limit = |
| 932 | m_desc.get_workspace_limit(m_cn, m_execution_policy.workspace_limit); |
| 933 | RealTimer timer; |
| 934 | std::unordered_set<std::string> rst_algos; |
| 935 | if (rst.second.valid()) { |
| 936 | std::transform( |
| 937 | rst.second.val().begin(), rst.second.val().end(), |
| 938 | std::inserter(rst_algos, rst_algos.end()), |
| 939 | [](const AlgoChooserProfileCache::ResultEntry& result) { |
| 940 | return result.algo; |
| 941 | }); |
| 942 | } |
| 943 | |
| 944 | for (auto algo : get_all_candidates()) { |
| 945 | std::string desc; |
| 946 | serialize_write_pod(algo.desc, desc); |
| 947 | if (rst_algos.find(desc) != rst_algos.end()) { |
| 948 | continue; |
| 949 | } |
| 950 | Maybe<AlgoChooserProfileCache::ResultEntry> cur_rst; |
| 951 | |
| 952 | ImplExecutionPolicy policy; |
| 953 | policy.algo = algo.desc; |
| 954 | |
| 955 | // skip naive algo, can not using attribute to determine naive algo, thus using |
| 956 | // strcmp |
| 957 | if (algo.desc.name.compare("NAIVE") == 0) { |
| 958 | continue; |
| 959 | } |
| 960 | |
| 961 | //! check negative attribute : skip negative attribute |
| 962 | auto palgo = m_dnn_opr->get_algorithm_from_desc(policy.algo); |
| 963 | if (palgo->contain_attribute_any(target_attr.second)) { |
| 964 | mgb_log_debug( |
| 965 | "skip algo %s, which matches the profile strategy required " |
| 966 | "'not contain attribute(%s).'", |
| 967 | algo.desc.name.c_str(), |
no test coverage detected