Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / rnn / bench_rnn.cpp
index 3d43c77..875db4c 100644 (file)
@@ -35,12 +35,23 @@ mkldnn_prop_kind_t prop = mkldnn_forward;
 alg_t alg = VANILLA_RNN;
 mkldnn_rnn_direction_t direction = mkldnn_unidirectional_left2right;
 activation_t activation = RELU;
+const char *perf_template = "perf,%n,%d,,,%-t,,%0t,";
+const dt_conf_t *cfg = conf_f32;
+policy_t scale_policy = NONE;
+attr_t attr;
+bool allow_unimpl = false;
+int mb = 0;
 
 void reset_parameters() {
+    cfg = conf_f32;
+    attr = attr_t();
     prop = mkldnn_forward;
     alg = VANILLA_RNN;
     direction = mkldnn_unidirectional_left2right;
     activation = RELU;
+    scale_policy = NONE;
+    allow_unimpl = false;
+    mb = 0;
 }
 
 int bench(int argc, char **argv, bool main_bench) {
@@ -57,12 +68,28 @@ int bench(int argc, char **argv, bool main_bench) {
                 assert("unknown dir");
         } else if (!strncmp("--alg=", argv[arg], 6))
             alg = str2alg(argv[arg] + 6);
+        else if (!strncmp("--cfg=", argv[arg], 6))
+            cfg = str2cfg(argv[arg] + 6);
+        else if (!strncmp("--attr=", argv[arg], 7))
+            SAFE(str2attr(&attr, argv[arg] + 7), CRIT);
         else if (!strncmp("--direction=", argv[arg], 12))
             direction = str2direction(argv[arg] + 12);
         else if (!strncmp("--activation=", argv[arg], 13))
             activation = str2activation(argv[arg] + 13);
+        else if (!strncmp("--allow-unimpl=", argv[arg], 15))
+            allow_unimpl = str2bool(argv[arg] + 15);
+        else if (!strncmp("--scaling=", argv[arg], 10))
+            scale_policy = str2policy(argv[arg] + 10);
         else if (!strncmp("--reset", argv[arg], 7))
             reset_parameters();
+        else if (!strncmp("--perf-template=", argv[arg], 16))
+            perf_template = argv[arg] + 16;
+        else if (!strncmp("--mb=", argv[arg], 5))
+            mb = atoi(argv[arg] + 5);
+        else if (!strncmp("-v", argv[arg], 2))
+            verbose = atoi(argv[arg] + 2);
+        else if (!strncmp("--verbose=", argv[arg], 10))
+            verbose = atoi(argv[arg] + 10);
         else {
             rnn_desc_t d;
             if (str2desc(&d, argv[arg]) == FAIL) {
@@ -70,6 +97,20 @@ int bench(int argc, char **argv, bool main_bench) {
                         argv[arg]);
                 exit(2);
             }
+            if (cfg != conf_f32 && alg != VANILLA_LSTM) {
+                fprintf(stderr,
+                        "driver: configuration ``%s` is supported for LSTM "
+                        "cell only, exiting...\n",
+                        cfg2str(cfg));
+                exit(2);
+            }
+            if (cfg != conf_f32 && scale_policy == NONE) {
+                fprintf(stderr,
+                        "driver: configuration ``%s` requires scale policy to "
+                        "be COMMON or PER_OC, exiting...\n",
+                        cfg2str(cfg));
+                exit(2);
+            }
             check(&d);
         }
     }
@@ -77,17 +118,17 @@ int bench(int argc, char **argv, bool main_bench) {
 }
 
 void check(rnn_desc_t *d) {
-    const rnn_prb_t p(*d, conf_f32, prop, alg, direction, activation);
+    const rnn_prb_t p(*d, cfg, prop, alg, direction, activation, attr,
+        scale_policy, mb);
     res_t res{};
     char pstr[max_prb_len];
-    prb2str(&p, &res, pstr);
 
     int status = rnn::doit(&p, &res);
 
     prb2str(&p, &res, pstr);
     bool want_perf_report = false;
 
-    parse_result(res, want_perf_report, false, status, pstr);
+    parse_result(res, want_perf_report, allow_unimpl, status, pstr);
 
     if (bench_mode & PERF)
         perf_report(&p, &res, pstr);