Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wux_labs
Tensorflow
提交
6b0d1ec9
T
Tensorflow
项目概览
wux_labs
/
Tensorflow
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6b0d1ec9
编写于
10月 03, 2018
作者:
T
TensorFlower Gardener
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22493 from Intel-tensorflow:cuixiaom_disable_MKL
PiperOrigin-RevId: 215560522
上级
dd52e1d3
7dc5f7ca
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
53 addition
and
15 deletion
+53
-15
tensorflow/core/common_runtime/process_util.cc
tensorflow/core/common_runtime/process_util.cc
+17
-14
tensorflow/core/common_runtime/threadpool_device.cc
tensorflow/core/common_runtime/threadpool_device.cc
+5
-1
tensorflow/core/graph/mkl_layout_pass.cc
tensorflow/core/graph/mkl_layout_pass.cc
+5
-0
tensorflow/core/graph/mkl_tfconversion_pass.cc
tensorflow/core/graph/mkl_tfconversion_pass.cc
+5
-0
tensorflow/core/util/util.cc
tensorflow/core/util/util.cc
+16
-0
tensorflow/core/util/util.h
tensorflow/core/util/util.h
+5
-0
未找到文件。
tensorflow/core/common_runtime/process_util.cc
浏览文件 @
6b0d1ec9
...
...
@@ -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
(
...
...
tensorflow/core/common_runtime/threadpool_device.cc
浏览文件 @
6b0d1ec9
...
...
@@ -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
...
...
tensorflow/core/graph/mkl_layout_pass.cc
浏览文件 @
6b0d1ec9
...
...
@@ -38,6 +38,7 @@ limitations under the License.
#include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/util/tensor_format.h"
#include "tensorflow/core/util/util.h"
#include "tensorflow/core/graph/mkl_graph_util.h"
#include "tensorflow/core/graph/mkl_layout_pass.h"
...
...
@@ -4511,6 +4512,10 @@ Status MklLayoutRewritePass::Run(const GraphOptimizationPassOptions& options) {
if
(
options
.
graph
==
nullptr
&&
options
.
partition_graphs
==
nullptr
)
{
return
Status
::
OK
();
}
if
(
DisableMKL
())
{
VLOG
(
2
)
<<
"TF-MKL: Disabling MKL"
;
return
Status
::
OK
();
}
auto
process_graph
=
[
&
](
std
::
unique_ptr
<
Graph
>*
g
)
{
// Get the ownership of a graph
...
...
tensorflow/core/graph/mkl_tfconversion_pass.cc
浏览文件 @
6b0d1ec9
...
...
@@ -31,6 +31,7 @@ limitations under the License.
#include "tensorflow/core/lib/gtl/map_util.h"
#include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/util/util.h"
#include "tensorflow/core/graph/mkl_graph_util.h"
#include "tensorflow/core/graph/mkl_tfconversion_pass.h"
...
...
@@ -424,6 +425,10 @@ Status MklToTfConversionPass::Run(const GraphOptimizationPassOptions& options) {
if
(
options
.
graph
==
nullptr
&&
options
.
partition_graphs
==
nullptr
)
{
return
Status
::
OK
();
}
if
(
DisableMKL
())
{
VLOG
(
2
)
<<
"TF-MKL: Disabling MKL"
;
return
Status
::
OK
();
}
auto
process_graph
=
[
&
](
std
::
unique_ptr
<
Graph
>*
g
)
{
// Get the ownership of graph
...
...
tensorflow/core/util/util.cc
浏览文件 @
6b0d1ec9
...
...
@@ -120,4 +120,20 @@ string SliceDebugString(const TensorShape& shape, const int64 flat) {
return
result
;
}
#ifdef INTEL_MKL
bool
DisableMKL
()
{
enum
MklStatus
{
MKL_DEFAULT
=
0
,
MKL_ON
=
1
,
MKL_OFF
=
2
};
static
MklStatus
status
=
MKL_DEFAULT
;
if
(
status
==
MKL_DEFAULT
)
{
char
*
tf_disable_mkl
=
getenv
(
"TF_DISABLE_MKL"
);
if
((
tf_disable_mkl
!=
NULL
)
&&
(
std
::
stoi
(
tf_disable_mkl
)
==
1
))
{
VLOG
(
2
)
<<
"TF-MKL: Disabling MKL"
;
status
=
MKL_OFF
;
}
else
{
status
=
MKL_ON
;
}
}
return
status
==
MKL_OFF
?
true
:
false
;
}
#endif // INTEL_MKL
}
// namespace tensorflow
tensorflow/core/util/util.h
浏览文件 @
6b0d1ec9
...
...
@@ -56,6 +56,11 @@ string PrintMemory(const char* ptr, size_t n);
// "tensor", "tensor[i]", "tensor[i, j]", etc.
string
SliceDebugString
(
const
TensorShape
&
shape
,
const
int64
flat
);
// disable MKL in runtime
#ifdef INTEL_MKL
bool
DisableMKL
();
#endif // INTEL_MKL
}
// namespace tensorflow
#endif // TENSORFLOW_CORE_UTIL_UTIL_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录