1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
24 #include "mkldnn_memory.hpp"
26 #include "rnn/rnn.hpp"
30 void perf_report(const rnn_prb_t *p, const res_t *r, const char *pstr) {
31 const auto &t = r->timer;
32 const int max_len = 400;
33 int rem_len = max_len - 1;
34 char buffer[max_len], *buf = buffer;
36 # define DPRINT(...) do { \
37 int l = snprintf(buf, rem_len, __VA_ARGS__); \
38 buf += l; rem_len -= l; \
41 auto modifier2mode = [](char c) {
42 if (c == '-') return benchdnn_timer_t::min;
43 if (c == '0') return benchdnn_timer_t::avg;
44 if (c == '+') return benchdnn_timer_t::max;
45 return benchdnn_timer_t::min;
48 auto modifier2unit = [](char c) {
49 if (c == 'K') return 1e3;
50 if (c == 'M') return 1e6;
51 if (c == 'G') return 1e9;
55 const char *pt = perf_template;
58 while ((c = *pt++) != '\0') {
59 if (c != '%') { *buf++ = c; rem_len--; continue; }
63 benchdnn_timer_t::mode_t mode = benchdnn_timer_t::min;
66 if (c == '-' || c == '0' || c == '+') {
67 mode = modifier2mode(c);
71 if (c == 'K' || c == 'M' || c == 'G') {
72 unit = modifier2unit(c);
75 // cellkind:activation:direction:l d mb
76 if (c == 'd') DPRINT("%s_%s_%s_l%dd%dt%dmb%d_slc%dsic%ddic%d",
77 alg2str(p->alg), activation2str(p->activation), direction2str(p->direction),
78 p->n_layer, p->n_directions(), p->n_iter, p->mb, p->slc, p->sic, p->dic);
82 DPRINT("%s", p->name);
84 DPRINT("%s", prop2str(p->prop));
86 DPRINT("%g", t.ticks(mode) / t.ms(mode) / unit * 1e3);
88 DPRINT("%g", t.ms(mode) / unit);
90 DPRINT("%g", t.ticks(mode) / unit);
92 []() { SAFE(FAIL, CRIT); return 0; }();
99 print(0, "%s\n", buffer);