Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / tests / benchdnn / reorder / reorder_aux.cpp
1 /*******************************************************************************
2 * Copyright 2017-2018 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 #include "mkldnn_debug.hpp"
18 #include "reorder/reorder.hpp"
19
20 #define DPRINT(...) do { \
21     int l = snprintf(buffer, rem_len, __VA_ARGS__); \
22     buffer += l; rem_len -= l; \
23 } while(0)
24
25 namespace reorder {
26
27 dims_t str2dims(const char *str) {
28     dims_t dims;
29     do {
30         int dim, len;
31         int scan = sscanf(str, "%d%n", &dim, &len);
32         SAFE_V(scan == 1 ? OK : FAIL);
33         dims.push_back(dim);
34         str += len;
35         SAFE_V(*str == 'x' || *str == '\0' ? OK : FAIL);
36     } while (*str++ != '\0');
37     return dims;
38 }
39
40 void dims2str(const dims_t &dims, char *buffer) {
41     int rem_len = max_dims_len;
42     for (size_t d = 0; d < dims.size() - 1; ++d)
43         DPRINT("%tdx", dims[d]);
44     DPRINT("%td", dims[dims.size() - 1]);
45 }
46
47 void prb2str(const prb_t *p, const res_t *res, char *buffer) {
48     char dims_buf[max_dims_len] = {0};
49     dims2str(p->reorder.dims, dims_buf);
50
51     char attr_buf[max_attr_len] = {0};
52     bool is_attr_def = p->attr.is_def();
53     if (!is_attr_def) {
54         int len = snprintf(attr_buf, max_attr_len, "--attr=\"");
55         SAFE_V(len >= 0 ? OK : FAIL);
56         attr2str(&p->attr, attr_buf + len);
57         len = (int)strnlen(attr_buf, max_attr_len);
58         snprintf(attr_buf + len, max_attr_len - len, "\" ");
59     }
60
61     int rem_len = max_prb_len;
62     DPRINT("--idt=%s --odt=%s --ifmt=%s --ofmt=%s %s%s",
63             dt2str(cfg2dt(p->conf_in)), dt2str(cfg2dt(p->conf_out)),
64             fmt2str(p->reorder.fmt_in), fmt2str(p->reorder.fmt_out),
65             attr_buf, dims_buf);
66 }
67
68 }