| 142 | } |
| 143 | |
| 144 | MatrixMul::Algorithm* MatrixMulImpl::get_algorithm_heuristic( |
| 145 | const TensorLayout& A, const TensorLayout& B, const TensorLayout& C, |
| 146 | size_t workspace_limit_in_bytes, const AlgoAttribute& positive_attr, |
| 147 | const AlgoAttribute& negative_attr) { |
| 148 | auto kern_size_param = make_kern_size_param(A, B, C); |
| 149 | if (auto algo = static_cast<AlgoBase*>( |
| 150 | get_algorithm_from_desc(execution_policy().algo))) { |
| 151 | megdnn_assert(algo->get_workspace(kern_size_param) < workspace_limit_in_bytes); |
| 152 | auto cur = megdnn::get_algo_match_attribute<MatrixMulImpl>( |
| 153 | algo, positive_attr, negative_attr); |
| 154 | if (cur) |
| 155 | return cur; |
| 156 | megdnn_throw(ssprintf( |
| 157 | "require algorithm without attribute(%s) with " |
| 158 | "attribute(%s), but given algorithm with " |
| 159 | "attribute(%s)", |
| 160 | Algorithm::attribute_str(negative_attr).c_str(), |
| 161 | Algorithm::attribute_str(positive_attr).c_str(), |
| 162 | Algorithm::attribute_str(algo->attribute()).c_str())); |
| 163 | } |
| 164 | AlgoTypePack algo_type; |
| 165 | algo_type.data_type = kern_size_param.deduce_algo_data_type(); |
| 166 | algo_type.format = kern_size_param.format; |
| 167 | auto algos = select_algo_type(algo_type); |
| 168 | Algorithm* heuristic_algo = nullptr; |
| 169 | Algorithm* usable_algo = nullptr; |
| 170 | for (auto&& algo : algos) { |
| 171 | if (static_cast<AlgoBase*>(algo)->usable(kern_size_param) && |
| 172 | static_cast<AlgoBase*>(algo)->get_workspace(kern_size_param) <= |
| 173 | workspace_limit_in_bytes) { |
| 174 | if (static_cast<AlgoBase*>(algo)->preferred_attribute( |
| 175 | kern_size_param, positive_attr, negative_attr)) { |
| 176 | //! use gemv algo if it's prefered |
| 177 | if (algo->algoset() == AlgoBase::AlgoSet::ALGO_TYPE_GEMV) { |
| 178 | return algo; |
| 179 | } else if (!heuristic_algo) { |
| 180 | heuristic_algo = algo; |
| 181 | } |
| 182 | } else if (!usable_algo) { |
| 183 | usable_algo = algo; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | if (!heuristic_algo) |
| 188 | heuristic_algo = usable_algo; |
| 189 | megdnn_assert(heuristic_algo, "No usable algorithm found"); |
| 190 | return heuristic_algo; |
| 191 | } |
| 192 | |
| 193 | MatrixMulImpl::KernSizeParam MatrixMulImpl::make_kern_size_param( |
| 194 | const TensorLayout& A, const TensorLayout& B, const TensorLayout& C) { |
nothing calls this directly
no test coverage detected