aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/common_runtime
diff options
context:
space:
mode:
authorGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-03 07:35:47 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-03 07:35:58 -0700
commit6b0d1ec99f8765fc361390b5fd87b637500b5474 (patch)
tree8df65cae48b3541c0f8090af43369267311f9887 /tensorflow/core/common_runtime
parentdd52e1d30702df5dfc805a1f433061dfbb75c814 (diff)
parent7dc5f7caa959c70d5ca948f7b0fc5abfea9a5935 (diff)
Merge pull request #22493 from Intel-tensorflow:cuixiaom_disable_MKL
PiperOrigin-RevId: 215560522
Diffstat (limited to 'tensorflow/core/common_runtime')
-rw-r--r--tensorflow/core/common_runtime/process_util.cc31
-rw-r--r--tensorflow/core/common_runtime/threadpool_device.cc6
2 files changed, 22 insertions, 15 deletions
diff --git a/tensorflow/core/common_runtime/process_util.cc b/tensorflow/core/common_runtime/process_util.cc
index a5d31b75c7..e1dc08d645 100644
--- a/tensorflow/core/common_runtime/process_util.cc
+++ b/tensorflow/core/common_runtime/process_util.cc
@@ -28,6 +28,7 @@ limitations under the License.
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/tracing.h"
#include "tensorflow/core/platform/types.h"
+#include "tensorflow/core/util/util.h"
namespace tensorflow {
@@ -56,24 +57,26 @@ int32 NumInterOpThreadsFromSessionOptions(const SessionOptions& options) {
const int32 inter_op = options.config.inter_op_parallelism_threads();
if (inter_op != 0) return inter_op;
#ifdef INTEL_MKL
- // MKL library executes ops in parallel using OMP threads
- // Set inter_op conservatively to avoid thread oversubscription that could
- // lead to severe perf degradations and OMP resource exhaustion
- int mkl_intra_op = 1;
+ if (!DisableMKL()) {
+ // MKL library executes ops in parallel using OMP threads
+ // Set inter_op conservatively to avoid thread oversubscription that could
+ // lead to severe perf degradations and OMP resource exhaustion
+ int mkl_intra_op = 1;
#ifdef _OPENMP
- mkl_intra_op = omp_get_max_threads();
+ mkl_intra_op = omp_get_max_threads();
#endif // _OPENMP
- CHECK_GE(mkl_intra_op, 1);
- const int32 mkl_inter_op = std::max(
- (port::NumSchedulableCPUs() + mkl_intra_op - 1) / mkl_intra_op, 2);
- VLOG(0) << "Creating new thread pool with default inter op setting: "
- << mkl_inter_op
- << ". Tune using inter_op_parallelism_threads for best performance.";
- return mkl_inter_op;
-#else
+ DCHECK_GE(mkl_intra_op, 1);
+ const int32 mkl_inter_op = std::max(
+ (port::NumSchedulableCPUs() + mkl_intra_op - 1) / mkl_intra_op, 2);
+ VLOG(0)
+ << "Creating new thread pool with default inter op setting: "
+ << mkl_inter_op
+ << ". Tune using inter_op_parallelism_threads for best performance.";
+ return mkl_inter_op;
+ }
+#endif // INTEL_MKL
// Default to using the number of cores available in the process.
return port::NumSchedulableCPUs();
-#endif // INTEL_MKL
}
thread::ThreadPool* NewThreadPoolFromSessionOptions(
diff --git a/tensorflow/core/common_runtime/threadpool_device.cc b/tensorflow/core/common_runtime/threadpool_device.cc
index 8587d1783a..6404d8bc6a 100644
--- a/tensorflow/core/common_runtime/threadpool_device.cc
+++ b/tensorflow/core/common_runtime/threadpool_device.cc
@@ -29,6 +29,7 @@ limitations under the License.
#include "tensorflow/core/platform/tracing.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session_options.h"
+#include "tensorflow/core/util/util.h"
#ifdef INTEL_MKL
#ifdef _OPENMP
@@ -49,6 +50,8 @@ ThreadPoolDevice::ThreadPoolDevice(const SessionOptions& options,
allocator_(allocator),
scoped_allocator_mgr_(new ScopedAllocatorMgr(name)) {
#ifdef INTEL_MKL
+ // Early return when MKL is disabled
+ if (DisableMKL()) return;
#ifdef _OPENMP
const char* user_omp_threads = getenv("OMP_NUM_THREADS");
if (user_omp_threads == nullptr) {
@@ -114,7 +117,8 @@ class MklCPUAllocatorFactory : public AllocatorFactory {
};
#ifdef ENABLE_MKL
-REGISTER_MEM_ALLOCATOR("MklCPUAllocator", 200, MklCPUAllocatorFactory);
+REGISTER_MEM_ALLOCATOR("MklCPUAllocator", (DisableMKL() ? 50 : 200),
+ MklCPUAllocatorFactory);
#endif // ENABLE_MKL
} // namespace