MCPcopy Create free account
hub / github.com/MegEngine/MegCC / exec

Method exec

compiler/test/kernel/common/dnn_proxy.h:601–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599 using Base = OprProxyProfilingBase<Opr>;
600 static constexpr int arity = OprTrait<Opr>::arity;
601 void exec(Opr* opr, const TensorNDArray& tensors) {
602 mgb_assert(tensors.size() == arity);
603 if (!Base::W.valid()) {
604 Base::W = WorkspaceWrapper(opr->handle(), 0);
605 }
606
607 TensorLayoutArray layouts;
608 for (auto&& tensor : tensors) {
609 layouts.push_back(tensor.layout);
610 }
611 if (Base::m_profiling && !Base::target_execution_policy.algo.valid()) {
612 size_t min_time = std::numeric_limits<size_t>::max();
613 for (auto algo :
614 AlgoProxy<Opr, arity>::get_all_algorithms_info(opr, layouts)) {
615 opr->execution_policy().algo = algo.desc;
616
617 auto preprocess_tensors = weight_prerocess(opr, tensors, algo.desc);
618 megcoreSynchronize(opr->handle()->megcore_computing_handle());
619 typename Opr::PreprocessedFilter preprocessed_filter{
620 nullptr, *preprocess_tensors};
621
622 auto workspace_size = AlgoProxy<Opr, arity>::get_workspace_in_bytes(
623 opr, layouts, &preprocessed_filter);
624 Base::W.update(workspace_size);
625
626 for (size_t times = 0; times < Base::warmup_times; ++times) {
627 AlgoProxy<Opr, arity>::exec(
628 opr, tensors, &preprocessed_filter, Base::W.workspace());
629 }
630 megcoreSynchronize(opr->handle()->megcore_computing_handle());
631 megcc::test::Timer timer;
632 timer.start();
633 for (size_t times = 0; times < Base::exec_times; ++times) {
634 AlgoProxy<Opr, arity>::exec(
635 opr, tensors, &preprocessed_filter, Base::W.workspace());
636 }
637 megcoreSynchronize(opr->handle()->megcore_computing_handle());
638 timer.stop();
639 printf("%.3fms %s\n", timer.get_time_in_us() / 1e3,
640 algo.desc.name.c_str());
641 if (min_time > timer.get_time_in_us()) {
642 min_time = timer.get_time_in_us();
643 Base::target_execution_policy.algo = algo.desc;
644 }
645 }
646 opr->execution_policy() = Base::target_execution_policy;
647 auto preprocess_tensors =
648 weight_prerocess(opr, tensors, Base::target_execution_policy.algo);
649 megcoreSynchronize(opr->handle()->megcore_computing_handle());
650 typename Opr::PreprocessedFilter preprocessed_filter{
651 nullptr, *preprocess_tensors};
652 auto workspace_size = AlgoProxy<Opr, arity>::get_workspace_in_bytes(
653 opr, layouts, &preprocessed_filter);
654 Base::W.update(workspace_size);
655 }
656 auto preprocess_tensors =
657 weight_prerocess(opr, tensors, Base::target_execution_policy.algo);
658 megcoreSynchronize(opr->handle()->megcore_computing_handle());

Callers

nothing calls this directly

Calls 8

WorkspaceWrapperClass · 0.85
maxFunction · 0.85
validMethod · 0.80
workspaceMethod · 0.80
startMethod · 0.80
stopMethod · 0.80
get_time_in_usMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected