| 513 | using Base = OprProxyProfilingBase<Opr>; |
| 514 | static constexpr int arity = OprTrait<Opr>::arity; |
| 515 | void exec(Opr* opr, const TensorNDArray& tensors) override { |
| 516 | megdnn_assert(tensors.size() == arity); |
| 517 | if (!Base::W.valid()) { |
| 518 | Base::W = WorkspaceWrapper(opr->handle(), 0); |
| 519 | } |
| 520 | |
| 521 | TensorLayoutArray layouts; |
| 522 | for (auto&& tensor : tensors) { |
| 523 | layouts.push_back(tensor.layout); |
| 524 | } |
| 525 | if (Base::m_profiling && !Base::target_execution_policy.algo.valid()) { |
| 526 | size_t min_time = std::numeric_limits<size_t>::max(); |
| 527 | for (auto algo : |
| 528 | AlgoProxy<Opr, arity>::get_all_algorithms_info_safe(opr, layouts)) { |
| 529 | opr->execution_policy().algo = algo.desc; |
| 530 | |
| 531 | auto preprocess_tensors = weight_prerocess(opr, tensors, algo.desc); |
| 532 | megcoreSynchronize(opr->handle()->megcore_computing_handle()); |
| 533 | typename Opr::PreprocessedFilter preprocessed_filter{ |
| 534 | nullptr, *preprocess_tensors}; |
| 535 | |
| 536 | auto workspace_size = AlgoProxy<Opr, arity>::get_workspace_in_bytes( |
| 537 | opr, layouts, &preprocessed_filter); |
| 538 | Base::W.update(workspace_size); |
| 539 | |
| 540 | for (size_t times = 0; times < Base::warmup_times; ++times) { |
| 541 | AlgoProxy<Opr, arity>::exec( |
| 542 | opr, tensors, &preprocessed_filter, Base::W.workspace()); |
| 543 | } |
| 544 | megcoreSynchronize(opr->handle()->megcore_computing_handle()); |
| 545 | Timer timer; |
| 546 | timer.start(); |
| 547 | for (size_t times = 0; times < Base::exec_times; ++times) { |
| 548 | AlgoProxy<Opr, arity>::exec( |
| 549 | opr, tensors, &preprocessed_filter, Base::W.workspace()); |
| 550 | } |
| 551 | megcoreSynchronize(opr->handle()->megcore_computing_handle()); |
| 552 | timer.stop(); |
| 553 | printf("%.3fms %s\n", timer.get_time_in_us() / 1e3, |
| 554 | algo.desc.name.c_str()); |
| 555 | if (min_time > timer.get_time_in_us()) { |
| 556 | min_time = timer.get_time_in_us(); |
| 557 | Base::target_execution_policy.algo = algo.desc; |
| 558 | } |
| 559 | } |
| 560 | opr->execution_policy() = Base::target_execution_policy; |
| 561 | auto preprocess_tensors = |
| 562 | weight_prerocess(opr, tensors, Base::target_execution_policy.algo); |
| 563 | megcoreSynchronize(opr->handle()->megcore_computing_handle()); |
| 564 | typename Opr::PreprocessedFilter preprocessed_filter{ |
| 565 | nullptr, *preprocess_tensors}; |
| 566 | auto workspace_size = AlgoProxy<Opr, arity>::get_workspace_in_bytes( |
| 567 | opr, layouts, &preprocessed_filter); |
| 568 | Base::W.update(workspace_size); |
| 569 | } |
| 570 | auto preprocess_tensors = |
| 571 | weight_prerocess(opr, tensors, Base::target_execution_policy.algo); |
| 572 | megcoreSynchronize(opr->handle()->megcore_computing_handle()); |
nothing calls this directly
no test coverage detected