File: std_output_formatter.h

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (45 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "output_formatter.h"

namespace caffe2 {
namespace emulator {

const uint64_t MS_IN_SECOND = 1000;

/*
 * Print the output of the emulator run to stdout.
 */
class StdOutputFormatter : public OutputFormatter {
 private:
  template <typename T>
  static float get_mean(const std::vector<T>& values) {
    float sum = std::accumulate(values.begin(), values.end(), 0.0);
    return sum / values.size();
  }

  template <typename T>
  static float get_stdev(const std::vector<T>& values) {
    auto mean = get_mean(values);
    double sq_sum =
        std::inner_product(values.begin(), values.end(), values.begin(), 0.0);
    return std::sqrt(sq_sum / values.size() - mean * mean);
  }

 public:
  std::string format(
      const std::vector<float>& durations_ms,
      uint64_t threads,
      uint64_t iterations) override {
    auto mean = get_mean(durations_ms);
    auto throughput = iterations / (mean / MS_IN_SECOND);
    return std::string("\n\n====================================\n") +
        "Predictor benchmark finished with " + c10::to_string(threads) +
        " threads.\nThroughput:\t\t" + c10::to_string(throughput) +
        " iterations/s\nVariation:\t\t" +
        c10::to_string(get_stdev(durations_ms) * 100 / mean) +
        "%\n====================================";
  }
};

} // namespace emulator
} // namespace caffe2