| 23 | */ |
| 24 | template <class Opr, typename... Args> |
| 25 | typename Opr::AlgoBase* get_algorithm(Opr* opr, Args&&... args) { |
| 26 | typename Opr::AlgorithmDesc ret; |
| 27 | // first check self configured algorithm |
| 28 | auto set = opr->execution_policy().algo; |
| 29 | if (set.valid()) { |
| 30 | ret = set; |
| 31 | } else { |
| 32 | TensorLayoutArray layouts{{args...}}; |
| 33 | AlgorithmCache::Key key{opr->handle(), opr->get_opr_type(), |
| 34 | layouts.data(), layouts.size(), |
| 35 | &opr->param(), sizeof(opr->param())}; |
| 36 | // then get from global algorithm cache |
| 37 | auto rst = AlgorithmCache::instance().get(key); |
| 38 | if (rst.policy.algo.valid()) { |
| 39 | ret = rst.policy.algo; |
| 40 | } else { |
| 41 | // finally get pre-defined heuristic algorithm |
| 42 | ret = opr->get_algorithm_info_heuristic( |
| 43 | std::forward<Args>(args)..., |
| 44 | std::numeric_limits<size_t>::max(), AlgoAttribute::DEFAULT, |
| 45 | AlgoAttribute::DEFAULT) |
| 46 | .desc; |
| 47 | } |
| 48 | } |
| 49 | return static_cast<typename Opr::AlgoBase*>(opr->get_algorithm_from_desc(ret)); |
| 50 | } |
| 51 | |
| 52 | /*! |
| 53 | * \brief get user-configured algorithm, or heuristic algorithm. used in opencl |
no test coverage detected