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 *******************************************************************************/
25 #include "mkldnn_common.hpp"
26 #include "mkldnn_debug.hpp"
27 #include "mkldnn_memory.hpp"
29 #include "rnn/rnn.hpp"
33 /* global driver parameters */
34 mkldnn_prop_kind_t prop = mkldnn_forward;
35 alg_t alg = VANILLA_RNN;
36 mkldnn_rnn_direction_t direction = mkldnn_unidirectional_left2right;
37 activation_t activation = RELU;
38 const char *perf_template = "perf,%n,%d,%GO,%GF,%-t,%-Gp,%0t,%0Gp";
39 const dt_conf_t *cfg = conf_f32;
40 policy_t scale_policy = NONE;
42 bool allow_unimpl = false;
45 void reset_parameters() {
48 prop = mkldnn_forward;
50 direction = mkldnn_unidirectional_left2right;
57 int bench(int argc, char **argv, bool main_bench) {
58 for (int arg = 0; arg < argc; ++arg) {
59 if (!strncmp("--batch=", argv[arg], 8))
60 SAFE(batch(argv[arg] + 8, bench), CRIT);
61 else if (!strncmp("--prop=", argv[arg], 7)) {
62 dir_t dir = str2dir(argv[arg] + 7);
64 prop = mkldnn_forward;
65 else if (dir == BWD_DW)
66 prop = mkldnn_backward;
68 assert("unknown dir");
69 } else if (!strncmp("--alg=", argv[arg], 6))
70 alg = str2alg(argv[arg] + 6);
71 else if (!strncmp("--cfg=", argv[arg], 6))
72 cfg = str2cfg(argv[arg] + 6);
73 else if (!strncmp("--attr=", argv[arg], 7))
74 SAFE(str2attr(&attr, argv[arg] + 7), CRIT);
75 else if (!strncmp("--direction=", argv[arg], 12))
76 direction = str2direction(argv[arg] + 12);
77 else if (!strncmp("--activation=", argv[arg], 13))
78 activation = str2activation(argv[arg] + 13);
79 else if (!strncmp("--allow-unimpl=", argv[arg], 15))
80 allow_unimpl = str2bool(argv[arg] + 15);
81 else if (!strncmp("--scaling=", argv[arg], 10))
82 scale_policy = str2policy(argv[arg] + 10);
83 else if (!strncmp("--reset", argv[arg], 7))
85 else if (!strncmp("--perf-template=", argv[arg], 16))
86 perf_template = argv[arg] + 16;
87 else if (!strncmp("--mb=", argv[arg], 5))
88 mb = atoi(argv[arg] + 5);
89 else if (!strncmp("-v", argv[arg], 2))
90 verbose = atoi(argv[arg] + 2);
91 else if (!strncmp("--verbose=", argv[arg], 10))
92 verbose = atoi(argv[arg] + 10);
95 if (str2desc(&d, argv[arg]) == FAIL) {
96 fprintf(stderr, "driver: unknown option: `%s`, exiting...\n",
100 if (cfg != conf_f32 && scale_policy == NONE) {
102 "driver: configuration ``%s` requires scale policy to "
103 "be COMMON or PER_OC, exiting...\n",
113 void check(rnn_desc_t *d) {
114 const rnn_prb_t p(*d, cfg, prop, alg, direction, activation, attr,
117 char pstr[max_prb_len];
119 int status = rnn::doit(&p, &res);
121 prb2str(&p, &res, pstr);
122 bool want_perf_report = false;
124 parse_result(res, want_perf_report, allow_unimpl, status, pstr);
126 if (bench_mode & PERF)
127 perf_report(&p, &res, pstr);
129 benchdnn_stat.tests++;