Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / mkldnn_plugin / mkldnn / omp_manager.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <cstdlib>
6 #include <cstring>
7 #include "ie_parallel.hpp"
8 #include "omp_manager.h"
9
10 using namespace MKLDNNPlugin;
11 namespace MKLDNNPlugin {
12 namespace cpu {
13
14 static const char *openMpEnvVars[] = {
15         "OMP_CANCELLATION", "OMP_DISPLAY_ENV", "OMP_DEFAULT_DEVICE", "OMP_DYNAMIC",
16         "OMP_MAX_ACTIVE_LEVELS", "OMP_MAX_TASK_PRIORITY", "OMP_NESTED",
17         "OMP_NUM_THREADS", "OMP_PROC_BIND", "OMP_PLACES", "OMP_STACKSIZE",
18         "OMP_SCHEDULE", "OMP_THREAD_LIMIT", "OMP_WAIT_POLICY", "GOMP_CPU_AFFINITY",
19         "GOMP_DEBUG", "GOMP_STACKSIZE", "GOMP_SPINCOUNT", "GOMP_RTEMS_THREAD_POOLS",
20         "KMP_AFFINITY", "KMP_NUM_THREADS", "MIC_KMP_AFFINITY",
21         "MIC_OMP_NUM_THREADS", "MIC_OMP_PROC_BIND", "PHI_KMP_AFFINITY",
22         "PHI_OMP_NUM_THREADS", "PHI_KMP_PLACE_THREADS", "MKL_NUM_THREADS",
23         "MKL_DYNAMIC", "MKL_DOMAIN_NUM_THREADS"
24 };
25
26 static const unsigned numberOfOpenMpEnvVars =
27         sizeof(openMpEnvVars) / sizeof(openMpEnvVars[0]);
28
29 bool checkOpenMpEnvVars(bool includeOMPNumThreads) {
30     for (unsigned i = 0; i < numberOfOpenMpEnvVars; i++) {
31         if (getenv(openMpEnvVars[i])) {
32             if (0 != strcmp(openMpEnvVars[i], "OMP_NUM_THREADS") || includeOMPNumThreads)
33                 return true;
34         }
35     }
36     return false;
37 }
38
39 #if !(defined(__APPLE__) || defined(_WIN32))
40 // getNumberOfCPUSockets/getNumberOfCPUCores are implemented in the lin_omp_manager.cpp
41 #else
42 int getNumberOfCPUSockets() {return 1;}
43 int getNumberOfCPUCores()   {return parallel_get_max_threads();}
44 #endif
45
46 }  // namespace cpu
47 }  // namespace MKLDNNPlugin