Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / common / verbose.cpp
1 /*******************************************************************************
2 * Copyright 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 <stdlib.h>
18 #ifndef _WIN32
19 #include <sys/time.h>
20 #endif
21
22 #include "mkldnn.h"
23 #include "mkldnn_version.h"
24 #include "c_types_map.hpp"
25 #include "verbose.hpp"
26 #include "cpu_isa_traits.hpp"
27
28 /* MKL-DNN CPU ISA info */
29 #define ISA_ANY "No instruction set specific optimizations"
30 #define SSE42 "Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2)"
31 #define AVX "Intel(R) Advanced Vector Extensions (Intel(R) AVX)"
32 #define AVX2 "Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2)"
33 #define AVX512_COMMON "Intel(R) Advanced Vector Extensions 512 (Intel(R) " \
34                       "AVX-512)"
35 #define AVX512_CORE "Intel(R) Advanced Vector Extensions 512 (Intel(R) " \
36                     "AVX-512) with AVX512BW, AVX512VL, and AVX512DQ extensions"
37 #define AVX512_CORE_VNNI "Intel(R) AVX512-Deep Learning Boost (Intel(R) " \
38                          "AVX512-DL Boost)"
39 #define AVX512_MIC "Intel(R) Advanced Vector Extensions 512 (Intel(R) " \
40                    "AVX-512) with AVX512CD, AVX512ER, and AVX512PF extensions"
41 #define AVX512_MIC_4OPS "Intel(R) Advanced Vector Extensions 512 (Intel(R) " \
42                    "AVX-512) with AVX512_4FMAPS and AVX512_4VNNIW extensions"
43
44 namespace mkldnn {
45 namespace impl {
46
47 static verbose_t verbose;
48 static bool initialized;
49 static bool version_printed = false;
50
51 const verbose_t *mkldnn_verbose() {
52 #if !defined(DISABLE_VERBOSE)
53     if (!initialized) {
54         const int len = 2;
55         char val[len] = {0};
56         if (mkldnn_getenv(val, "MKLDNN_VERBOSE", len) == 1)
57             verbose.level = atoi(val);
58         initialized = true;
59     }
60     if (!version_printed && verbose.level > 0) {
61          printf("mkldnn_verbose,info,"
62                  "Intel(R) MKL-DNN v%d.%d.%d (Git Hash %s),%s\n",
63                 mkldnn_version()->major, mkldnn_version()->minor,
64                 mkldnn_version()->patch, mkldnn_version()->hash,
65                 get_isa_info());
66          version_printed = true;
67     }
68 #else
69     verbose.level = 0;
70 #endif
71     return &verbose;
72 }
73
74 double get_msec() {
75 #ifdef _WIN32
76     static LARGE_INTEGER frequency;
77     if (frequency.QuadPart == 0)
78         QueryPerformanceFrequency(&frequency);
79     LARGE_INTEGER now;
80     QueryPerformanceCounter(&now);
81     return 1e+3 * now.QuadPart / frequency.QuadPart;
82 #else
83     struct timeval time;
84     gettimeofday(&time, NULL);
85     return 1e+3 * time.tv_sec + 1e-3 * time.tv_usec;
86 #endif
87 }
88
89 const char *get_isa_info() {
90     using namespace mkldnn::impl::cpu;
91     if (mayiuse(avx512_mic_4ops))  return AVX512_MIC_4OPS;
92     if (mayiuse(avx512_mic))       return AVX512_MIC;
93     if (mayiuse(avx512_core_vnni)) return AVX512_CORE_VNNI;
94     if (mayiuse(avx512_core))      return AVX512_CORE;
95     if (mayiuse(avx512_common))    return AVX512_COMMON;
96     if (mayiuse(avx2))             return AVX2;
97     if (mayiuse(avx))              return AVX;
98     if (mayiuse(sse42))            return SSE42;
99     return ISA_ANY;
100 }
101
102 }
103 }
104
105 mkldnn_status_t mkldnn_set_verbose(int level) {
106     using namespace mkldnn::impl::status;
107     if (level < 0 || level > 2) return invalid_arguments;
108     mkldnn::impl::verbose.level = level;
109     mkldnn::impl::initialized = true;
110     return success;
111 }
112
113 const mkldnn_version_t *mkldnn_version() {
114     static mkldnn_version_t ver = {
115         MKLDNN_VERSION_MAJOR,
116         MKLDNN_VERSION_MINOR,
117         MKLDNN_VERSION_PATCH,
118         MKLDNN_VERSION_HASH};
119     return &ver;
120 }
121