| 766 | #if MEGDNN_WITH_BENCHMARK |
| 767 | namespace { |
| 768 | void benchmark_impl( |
| 769 | const param::ConvBias param, |
| 770 | std::vector<std::pair<SmallVector<TensorShape>, float>>& shapes_and_computation, |
| 771 | const std::string algo_name, size_t RUNS, |
| 772 | TaskExecutorConfig&& multi_thread_config, |
| 773 | TaskExecutorConfig&& single_thread_config, std::vector<DType>& data_type) { |
| 774 | std::vector<float> multi_thread_times, single_thread_times; |
| 775 | { |
| 776 | auto multi_thread_hanle = create_cpu_handle(0, true, &multi_thread_config); |
| 777 | auto benchmarker = Benchmarker<ConvBias>(multi_thread_hanle.get()); |
| 778 | benchmarker.set_times(RUNS) |
| 779 | .set_display(false) |
| 780 | .set_param(param) |
| 781 | .set_dtype(0, data_type[0]) |
| 782 | .set_dtype(1, data_type[1]) |
| 783 | .set_dtype(2, data_type[2]) |
| 784 | .set_dtype(4, data_type[3]) |
| 785 | .set_before_exec_callback( |
| 786 | conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name.c_str())); |
| 787 | for (auto shape : shapes_and_computation) { |
| 788 | multi_thread_times.push_back(benchmarker.exec(shape.first) / RUNS); |
| 789 | } |
| 790 | } |
| 791 | { |
| 792 | auto single_thread_handle = create_cpu_handle(0, true, &single_thread_config); |
| 793 | auto benchmarker = Benchmarker<ConvBias>(single_thread_handle.get()); |
| 794 | benchmarker.set_times(RUNS) |
| 795 | .set_display(false) |
| 796 | .set_param(param) |
| 797 | .set_dtype(0, data_type[0]) |
| 798 | .set_dtype(1, data_type[1]) |
| 799 | .set_dtype(2, data_type[2]) |
| 800 | .set_dtype(4, data_type[3]) |
| 801 | .set_before_exec_callback( |
| 802 | conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name.c_str())); |
| 803 | for (auto shape : shapes_and_computation) { |
| 804 | single_thread_times.push_back(benchmarker.exec(shape.first) / RUNS); |
| 805 | } |
| 806 | } |
| 807 | printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread); |
| 808 | printf("core_ids:"); |
| 809 | for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) { |
| 810 | printf("%zu ", multi_thread_config.affinity_core_set[i]); |
| 811 | } |
| 812 | printf(", Single thread core_id %zu\n", single_thread_config.affinity_core_set[0]); |
| 813 | for (size_t i = 0; i < shapes_and_computation.size(); i++) { |
| 814 | auto shapes = shapes_and_computation[i]; |
| 815 | printf("Bench case: "); |
| 816 | for (auto&& shape : shapes.first) { |
| 817 | printf("%s ", shape.to_string().c_str()); |
| 818 | } |
| 819 | float computations = shapes.second; |
| 820 | printf("%zu threads gflops: %f,\n single thread gflops: " |
| 821 | "%f. spead up = %f, speedup/cores=%f\n", |
| 822 | multi_thread_config.nr_thread, computations / multi_thread_times[i], |
| 823 | computations / single_thread_times[i], |
| 824 | single_thread_times[i] / multi_thread_times[i], |
| 825 | single_thread_times[i] / multi_thread_times[i] / |