1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "ie_parallel.hpp"
8 #include "omp_manager.h"
10 using namespace MKLDNNPlugin;
11 namespace MKLDNNPlugin {
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"
26 static const unsigned numberOfOpenMpEnvVars =
27 sizeof(openMpEnvVars) / sizeof(openMpEnvVars[0]);
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)
39 #if !(defined(__APPLE__) || defined(_WIN32))
40 // getNumberOfCPUSockets/getNumberOfCPUCores are implemented in the lin_omp_manager.cpp
42 int getNumberOfCPUSockets() {return 1;}
43 int getNumberOfCPUCores() {return parallel_get_max_threads();}
47 } // namespace MKLDNNPlugin