1 | /******************************************************************************* |
2 | * Copyright 2019-2022 Intel Corporation |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | *******************************************************************************/ |
16 | |
17 | #ifndef PERF_REPORT_HPP |
18 | #define PERF_REPORT_HPP |
19 | |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | #include <string.h> |
23 | |
24 | #include <iostream> |
25 | #include <sstream> |
26 | #include <string> |
27 | #include <vector> |
28 | |
29 | #include "oneapi/dnnl/dnnl_types.h" |
30 | |
31 | #include "common.hpp" |
32 | #include "utils/timer.hpp" |
33 | |
34 | struct base_perf_report_t { |
35 | base_perf_report_t(const char *perf_template) : pt_(perf_template) {} |
36 | virtual ~base_perf_report_t() = default; |
37 | |
38 | void report(res_t *res, const char *prb_str) const; |
39 | |
40 | /* truly common types */ |
41 | virtual double ops() const { return 0.; } |
42 | virtual const attr_t *attr() const { return nullptr; } |
43 | virtual const int *axis() const { return nullptr; } |
44 | virtual const std::string *name() const { return nullptr; } |
45 | virtual const int64_t *group() const { return nullptr; } |
46 | virtual const dir_t *dir() const { return nullptr; } |
47 | virtual const dnnl_data_type_t *dt() const { return nullptr; } |
48 | virtual const std::vector<dnnl_data_type_t> *sdt() const { return nullptr; } |
49 | virtual const dnnl_data_type_t *ddt() const { return nullptr; } |
50 | virtual const std::string *tag() const { return nullptr; } |
51 | virtual const std::string *stat_tag() const { return nullptr; } |
52 | virtual const std::vector<std::string> *stag() const { return nullptr; } |
53 | virtual const std::string *dtag() const { return nullptr; } |
54 | virtual const std::string *wtag() const { return nullptr; } |
55 | virtual const dnnl_prop_kind_t *prop() const { return nullptr; } |
56 | virtual const int64_t *user_mb() const { return nullptr; } |
57 | virtual const thr_ctx_t *ctx_init() const { return nullptr; } |
58 | virtual const thr_ctx_t *ctx_exe() const { return nullptr; } |
59 | |
60 | /* designed to be overloaded in reorder only to match verbose output */ |
61 | virtual void dump_engine(std::ostream &s) const; |
62 | |
63 | /* primitive-specific properties (but with common interface) */ |
64 | virtual void dump_alg(std::ostream &) const { SAFE_V(FAIL); } |
65 | virtual void dump_cfg(std::ostream &) const { SAFE_V(FAIL); } |
66 | virtual void dump_desc(std::ostream &) const { SAFE_V(FAIL); } |
67 | virtual void dump_desc_csv(std::ostream &) const { SAFE_V(FAIL); } |
68 | virtual void dump_flags(std::ostream &) const { SAFE_V(FAIL); } |
69 | virtual void dump_rnn_activation(std::ostream &) const { SAFE_V(FAIL); } |
70 | virtual void dump_rnn_direction(std::ostream &) const { SAFE_V(FAIL); } |
71 | |
72 | private: |
73 | const char *pt_; |
74 | |
75 | void handle_option(std::ostream &s, const char *&option, res_t *res, |
76 | const char *prb_str) const; |
77 | |
78 | void () const { |
79 | static bool = false; |
80 | if (!footer_printed) { |
81 | BENCHDNN_PRINT(0, "Output template: %s\n" , pt_); |
82 | footer_printed = true; |
83 | } |
84 | } |
85 | |
86 | static timer::timer_t::mode_t modifier2mode(char c) { |
87 | if (c == '-') return timer::timer_t::min; |
88 | if (c == '0') return timer::timer_t::avg; |
89 | if (c == '+') return timer::timer_t::max; |
90 | return timer::timer_t::min; |
91 | } |
92 | |
93 | static double modifier2unit(char c) { |
94 | if (c == 'K') return 1e3; |
95 | if (c == 'M') return 1e6; |
96 | if (c == 'G') return 1e9; |
97 | return 1e0; |
98 | } |
99 | }; |
100 | |
101 | #endif |
102 | |