From 06a7f741f0e1c4d28437010020dcfc6d9f96530e Mon Sep 17 00:00:00 2001 From: mozga-intel Date: Wed, 27 Feb 2019 01:36:40 +0100 Subject: [PATCH] The flag of mkldnn is enabled iff it is necessary test=develop --- paddle/fluid/pybind/pybind.cc | 9 +++++++++ python/paddle/fluid/__init__.py | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index d744394022..bdb9bc7e26 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -86,6 +86,14 @@ bool IsCompiledWithCUDA() { #endif } +bool IsCompiledWithMKLDNN() { +#ifndef PADDLE_WITH_MKLDNN + return false; +#else + return true; +#endif +} + bool IsCompiledWithBrpc() { #ifndef PADDLE_WITH_DISTRIBUTE return false; @@ -873,6 +881,7 @@ All parameter, weight, gradient are variables in Paddle. [](bool init_p2p) { framework::InitDevices(init_p2p); }); m.def("is_compiled_with_cuda", IsCompiledWithCUDA); + m.def("is_compiled_with_mkldnn", IsCompiledWithMKLDNN); m.def("is_compiled_with_brpc", IsCompiledWithBrpc); m.def("is_compiled_with_dist", IsCompiledWithDIST); #ifdef PADDLE_WITH_CUDA diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index a9c92efb72..d12f04a6ab 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -125,14 +125,13 @@ def __bootstrap__(): os.environ['OMP_NUM_THREADS'] = str(num_threads) sysstr = platform.system() read_env_flags = [ - 'check_nan_inf', 'benchmark', 'eager_delete_scope', 'use_mkldnn', - 'use_ngraph', 'initial_cpu_memory_in_mb', 'init_allocated_mem', - 'free_idle_memory', 'paddle_num_threads', "dist_threadpool_size", - 'eager_delete_tensor_gb', 'fast_eager_deletion_mode', - 'allocator_strategy', 'reader_queue_speed_test_mode', - 'print_sub_graph_dir', 'pe_profile_fname', 'warpctc_dir', - 'inner_op_parallelism', 'enable_parallel_graph', - 'multiple_of_cupti_buffer_size' + 'check_nan_inf', 'benchmark', 'eager_delete_scope', 'use_ngraph', + 'initial_cpu_memory_in_mb', 'init_allocated_mem', 'free_idle_memory', + 'paddle_num_threads', "dist_threadpool_size", 'eager_delete_tensor_gb', + 'fast_eager_deletion_mode', 'allocator_strategy', + 'reader_queue_speed_test_mode', 'print_sub_graph_dir', + 'pe_profile_fname', 'warpctc_dir', 'inner_op_parallelism', + 'enable_parallel_graph', 'multiple_of_cupti_buffer_size' ] if 'Darwin' not in sysstr: read_env_flags.append('use_pinned_memory') @@ -140,6 +139,9 @@ def __bootstrap__(): if os.name != 'nt': read_env_flags.append('cpu_deterministic') + if core.is_compiled_with_mkldnn(): + read_env_flags.append('use_mkldnn') + if core.is_compiled_with_dist(): read_env_flags.append('rpc_deadline') read_env_flags.append('rpc_server_profile_path') -- GitLab