MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / benchmark_impl

Function benchmark_impl

dnn/test/arm_common/pooling_multi_thread.cpp:489–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487namespace {
488template <typename Opr>
489void benchmark_impl(
490 const typename Opr::Param& param, std::vector<SmallVector<TensorShape>> shapes,
491 size_t RUNS, TaskExecutorConfig&& multi_thread_config,
492 TaskExecutorConfig&& single_thread_config, DType data_type) {
493 std::vector<float> multi_thread_times, single_thread_times;
494 {
495 auto multi_thread_hanle = create_cpu_handle(0, true, &multi_thread_config);
496 auto benchmarker = Benchmarker<Opr>(multi_thread_hanle.get());
497 benchmarker.set_times(RUNS).set_display(false).set_param(param);
498 benchmarker.set_dtype(0, data_type);
499 for (auto shape : shapes) {
500 multi_thread_times.push_back(benchmarker.exec(shape) / RUNS);
501 }
502 }
503 {
504 auto single_thread_handle = create_cpu_handle(0, true, &single_thread_config);
505 auto benchmarker = Benchmarker<Opr>(single_thread_handle.get());
506 benchmarker.set_times(RUNS).set_display(false).set_param(param);
507 benchmarker.set_dtype(0, data_type);
508 for (auto shape : shapes) {
509 single_thread_times.push_back(benchmarker.exec(shape) / RUNS);
510 }
511 }
512 printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread);
513 printf("core_ids:");
514 for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) {
515 printf("%zu ", multi_thread_config.affinity_core_set[i]);
516 }
517 printf(", Single thread core_id %zu\n", single_thread_config.affinity_core_set[0]);
518 for (size_t i = 0; i < shapes.size(); i++) {
519 auto shape = shapes[i];
520 printf("Case: ");
521 for (auto sh : shape)
522 printf("%s ", sh.to_string().c_str());
523 printf("%zu threads time: %f,\n single thread time: "
524 "%f. spead up = %f, speedup/cores=%f\n",
525 multi_thread_config.nr_thread, multi_thread_times[i],
526 single_thread_times[i], single_thread_times[i] / multi_thread_times[i],
527 single_thread_times[i] / multi_thread_times[i] /
528 multi_thread_config.nr_thread);
529 }
530}
531} // namespace
532
533TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_POOLING) {

Callers

nothing calls this directly

Calls 6

set_dtypeMethod · 0.80
getMethod · 0.45
push_backMethod · 0.45
execMethod · 0.45
sizeMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected