| 35 | |
| 36 | template <typename Opr> |
| 37 | PerformanceResultPair Benchmarker<Opr>::exec(TensorLayoutArray all_layouts) { |
| 38 | using CCProxy = CCOprProxy<Opr>; |
| 39 | auto dnn_handle = Runner<Opr>::get_dnn_handle(); |
| 40 | auto opr = dnn_handle->template create_operator<Opr>(); |
| 41 | opr->param() = m_param; |
| 42 | m_dnn_proxy.deduce_layout(opr.get(), all_layouts); |
| 43 | |
| 44 | auto tensor_array_storage = dnn_alloc_tensors(dnn_handle, all_layouts, 0); |
| 45 | auto tensor_array_naive_storage = dnn_alloc_tensors(dnn_handle, all_layouts, 0); |
| 46 | auto tensor_array_dnn = *tensor_array_naive_storage; |
| 47 | auto tensor_array = *tensor_array_storage; |
| 48 | Runner<Opr>::init_tensor(tensor_array_dnn, m_rng); |
| 49 | dnn_copy_tensors(tensor_array, tensor_array_dnn); |
| 50 | PerformanceResultPair res; |
| 51 | std::stringstream ss; |
| 52 | for (auto& tensor : tensor_array) { |
| 53 | ss << tensor.layout.to_string(); |
| 54 | } |
| 55 | res.args = ss.str(); |
| 56 | //! test mode |
| 57 | CCProxy cc_proxy; |
| 58 | std::unordered_map<std::string, CCAttr> proxy_attr; |
| 59 | fix_addition_attr_map<Opr>(proxy_attr, m_dnn_proxy, tensor_array_dnn); |
| 60 | auto megcc_perf = cc_proxy.exec( |
| 61 | opr.get(), tensor_array, m_arch, m_benchmark_option, m_kernel_symbol, |
| 62 | proxy_attr, false); |
| 63 | if (m_benchmark_option.valid_megcc_performance) { |
| 64 | auto workload = WorkloadOprProxy<Opr>::get_workload(opr.get(), tensor_array); |
| 65 | fill_performance_result(megcc_perf, workload); |
| 66 | res.megcc_performance = megcc_perf; |
| 67 | } |
| 68 | #if !MEGCC_TEST_GEN |
| 69 | if (m_benchmark_option.disable_check && !m_benchmark_option.valid_dnn_performance) { |
| 70 | //! fast return; |
| 71 | return res; |
| 72 | } |
| 73 | auto dnn_opr = dnn_handle->template create_operator<Opr>(); |
| 74 | dnn_opr->param() = m_param; |
| 75 | if (m_has_set_dnn_param) { |
| 76 | dnn_opr->param() = m_dnn_param; |
| 77 | } |
| 78 | //! run dnn |
| 79 | if (m_before_exec_callback) { |
| 80 | m_before_exec_callback(dnn_opr.get(), tensor_array_dnn); |
| 81 | } |
| 82 | m_dnn_proxy.exec(dnn_opr.get(), tensor_array_dnn); |
| 83 | if (m_benchmark_option.valid_dnn_performance) { |
| 84 | for (int i = 0; i < m_benchmark_option.warmup_iter; ++i) { |
| 85 | m_dnn_proxy.exec(dnn_opr.get(), tensor_array_dnn); |
| 86 | } |
| 87 | mgb_assert(m_benchmark_option.test_iter > 0); |
| 88 | Timer timer; |
| 89 | timer.start(); |
| 90 | for (int i = 0; i < m_benchmark_option.test_iter; ++i) { |
| 91 | m_dnn_proxy.exec(dnn_opr.get(), tensor_array_dnn); |
| 92 | } |
| 93 | timer.stop(); |
| 94 | PerformanceResult dnn_perf; |
nothing calls this directly
no test coverage detected