Caffe2 - C++ API
A deep learning, cross platform ML framework
benchmark.cc
1 #include "caffe2/core/init.h"
2 #include "caffe2/predictor/emulator/std_output_formatter.h"
3 
4 #include "benchmark.h"
5 
6 // Basic benchmark params
7 C10_DEFINE_int(warmup, 10000, "The number of iterations to warm up.");
8 C10_DEFINE_int(iter, 10000000, "The number of iterations to run.");
9 C10_DEFINE_int(threads, 32, "The number of threads to run.");
10 C10_DEFINE_int(runs, 10, "The number of independent runs.");
11 
12 // Benchmark setup params
13 C10_DEFINE_int(
14  num_loading_threads,
15  56,
16  "The number of threads to build predictors.");
17 
18 // Benchmark model params
19 C10_DEFINE_string(run_net, "", "The given net to benchmark.");
20 C10_DEFINE_string(init_net, "", "The given net to initialize.");
21 C10_DEFINE_string(data_net, "", "The given net to get input data.");
22 C10_DEFINE_string(
23  input_dims,
24  "",
25  "The path of the file that "
26  "stores input dimesions of all the operators in the run net. "
27  "Each element of the array is a mapping from "
28  "operator index to its input dimension.");
29 C10_DEFINE_string(
30  input_types,
31  "",
32  "The path of the file that "
33  "stores input types of all the operators in the run net. "
34  "Each element of the array is a mapping from "
35  "operator index to its input types.");
36 
37 namespace caffe2 {
38 namespace emulator {
39 
40 void BenchmarkRunner::benchmark(const BenchmarkParam& param) {
41  param.emulator->init();
42  std::vector<float> durations_ms;
43  for (size_t run = 0; run < FLAGS_runs; ++run) {
44  LOG(WARNING) << "Starting run " << run + 1;
45  LOG(INFO) << "Warming up " << FLAGS_threads << " threads with "
46  << FLAGS_warmup << " iterations...";
47  param.emulator->run(FLAGS_warmup);
48 
49  LOG(INFO) << "Starting benchmark with " << FLAGS_iter << " iterations...";
50  pre_benchmark_setup();
51  const auto duration_ms =
52  param.profiler->profile([&]() { param.emulator->run(FLAGS_iter); });
53 
54  durations_ms.emplace_back(duration_ms);
55  auto throughput = FLAGS_iter / (duration_ms / MS_IN_SECOND);
56  LOG(INFO) << "Benchmark run finished in " << duration_ms / MS_IN_SECOND
57  << " seconds.\n"
58  << "Throughput:\t\t" << throughput << " iterations/s\n";
59 
60  post_benchmark_cleanup();
61  LOG(INFO) << "Run " << run + 1 << " finished";
62  }
63  LOG(WARNING) << param.formatter->format(
64  durations_ms, FLAGS_threads, FLAGS_iter);
65 }
66 
67 } // namespace emulator
68 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13