reorder_aux.cpp 2.22 KB
Newer Older
openvino-pushbot's avatar
openvino-pushbot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*******************************************************************************
* Copyright 2017-2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

#include "mkldnn_debug.hpp"
#include "reorder/reorder.hpp"

#define DPRINT(...) do { \
    int l = snprintf(buffer, rem_len, __VA_ARGS__); \
    buffer += l; rem_len -= l; \
} while(0)

namespace reorder {

Alexey Suhov's avatar
Alexey Suhov committed
27 28 29 30 31 32 33 34 35 36 37 38
dims_t str2dims(const char *str) {
    dims_t dims;
    do {
        int dim, len;
        int scan = sscanf(str, "%d%n", &dim, &len);
        SAFE_V(scan == 1 ? OK : FAIL);
        dims.push_back(dim);
        str += len;
        SAFE_V(*str == 'x' || *str == '\0' ? OK : FAIL);
    } while (*str++ != '\0');
    return dims;
}
openvino-pushbot's avatar
openvino-pushbot committed
39

Alexey Suhov's avatar
Alexey Suhov committed
40 41 42 43 44
void dims2str(const dims_t &dims, char *buffer) {
    int rem_len = max_dims_len;
    for (size_t d = 0; d < dims.size() - 1; ++d)
        DPRINT("%dx", dims[d]);
    DPRINT("%d", dims[dims.size() - 1]);
openvino-pushbot's avatar
openvino-pushbot committed
45 46 47
}

void prb2str(const prb_t *p, const res_t *res, char *buffer) {
Alexey Suhov's avatar
Alexey Suhov committed
48 49
    char dims_buf[max_dims_len] = {0};
    dims2str(p->reorder.dims, dims_buf);
openvino-pushbot's avatar
openvino-pushbot committed
50

Alexey Suhov's avatar
Alexey Suhov committed
51 52 53 54 55 56 57 58 59
    char attr_buf[max_attr_len] = {0};
    bool is_attr_def = p->attr.is_def();
    if (!is_attr_def) {
        int len = snprintf(attr_buf, max_attr_len, "--attr=\"");
        SAFE_V(len >= 0 ? OK : FAIL);
        attr2str(&p->attr, attr_buf + len);
        len = (int)strnlen(attr_buf, max_attr_len);
        snprintf(attr_buf + len, max_attr_len - len, "\" ");
    }
openvino-pushbot's avatar
openvino-pushbot committed
60

Alexey Suhov's avatar
Alexey Suhov committed
61 62 63 64 65
    int rem_len = max_prb_len;
    DPRINT("--idt=%s --odt=%s --ifmt=%s --ofmt=%s %s%s",
            dt2str(cfg2dt(p->conf_in)), dt2str(cfg2dt(p->conf_out)),
            fmt2str(p->reorder.fmt_in), fmt2str(p->reorder.fmt_out),
            attr_buf, dims_buf);
openvino-pushbot's avatar
openvino-pushbot committed
66 67 68
}

}