Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
dabaca00
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dabaca00
编写于
4月 09, 2021
作者:
J
Jacek Czaja
提交者:
GitHub
4月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Candidate fix to #31992 (#32136)
上级
3822247f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
20 deletion
+26
-20
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+6
-10
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+20
-10
未找到文件。
paddle/fluid/platform/device_context.h
浏览文件 @
dabaca00
...
@@ -600,6 +600,8 @@ class MKLDNNDeviceContextThreadLocals {
...
@@ -600,6 +600,8 @@ class MKLDNNDeviceContextThreadLocals {
// MKL-DNN stream used for execution of primitives (per-thread)
// MKL-DNN stream used for execution of primitives (per-thread)
mkldnn
::
engine
cur_engine
;
mkldnn
::
engine
cur_engine
;
mkldnn
::
stream
cur_stream
;
mkldnn
::
stream
cur_stream
;
std
::
string
key_suffix
;
// Key identifying current Executor
bool
key_attach_thread_id
=
true
;
Body
();
Body
();
~
Body
();
~
Body
();
...
@@ -612,6 +614,10 @@ class MKLDNNDeviceContextThreadLocals {
...
@@ -612,6 +614,10 @@ class MKLDNNDeviceContextThreadLocals {
void
log_lib_version
(
void
);
void
log_lib_version
(
void
);
const
mkldnn
::
engine
&
get_engine
(
void
);
const
mkldnn
::
engine
&
get_engine
(
void
);
mkldnn
::
stream
&
get_stream
(
void
);
mkldnn
::
stream
&
get_stream
(
void
);
void
set_key_suffix
(
const
std
::
string
&
suffix
)
{
key_suffix
=
suffix
;
}
const
std
::
string
&
get_key_suffix
(
void
)
const
{
return
key_suffix
;
}
void
disable_tid_in_key
(
void
)
{
key_attach_thread_id
=
false
;
}
bool
is_tid_used_in_key
(
void
)
const
{
return
key_attach_thread_id
;
}
};
};
MKLDNNDeviceContextThreadLocals
()
=
default
;
MKLDNNDeviceContextThreadLocals
()
=
default
;
MKLDNNDeviceContextThreadLocals
(
const
MKLDNNDeviceContextThreadLocals
&
c
)
=
MKLDNNDeviceContextThreadLocals
(
const
MKLDNNDeviceContextThreadLocals
&
c
)
=
...
@@ -655,14 +661,6 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -655,14 +661,6 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
// Remove all entries from the blob map
// Remove all entries from the blob map
void
ResetBlobMap
();
void
ResetBlobMap
();
// Set a suffix to be added to key
void
SetKeySuffix
(
const
std
::
string
&
suffix
)
{
key_suffix_
=
suffix
;
}
const
std
::
string
&
GetKeySuffix
(
void
)
const
{
return
key_suffix_
;
}
// Disable adding thread ID to the key
void
DisableThreadInfoInKey
(
void
)
{
key_attach_thread_id_
=
false
;
}
bool
IsThreadIdUsedInKey
(
void
)
const
{
return
key_attach_thread_id_
;
}
// Prevent next ResetBlobMap()
// Prevent next ResetBlobMap()
void
BlockNextCacheClearing
();
void
BlockNextCacheClearing
();
...
@@ -686,8 +684,6 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -686,8 +684,6 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
std
::
shared_ptr
<
BlobMap
>
p_blobmap_
;
std
::
shared_ptr
<
BlobMap
>
p_blobmap_
;
std
::
shared_ptr
<
std
::
mutex
>
p_mutex_
;
std
::
shared_ptr
<
std
::
mutex
>
p_mutex_
;
bool
block_next_cache_clearing_
=
false
;
bool
block_next_cache_clearing_
=
false
;
std
::
string
key_suffix_
;
// Key identifying current Executor
bool
key_attach_thread_id_
=
true
;
};
};
#endif
#endif
...
...
paddle/fluid/platform/mkldnn_helper.h
浏览文件 @
dabaca00
...
@@ -439,14 +439,23 @@ inline void AppendKey(std::string* key, const std::vector<T>& dims) {
...
@@ -439,14 +439,23 @@ inline void AppendKey(std::string* key, const std::vector<T>& dims) {
inline
void
AttachPointerHashToMKLDNNKey
(
void
*
ptr
,
inline
void
AttachPointerHashToMKLDNNKey
(
void
*
ptr
,
const
platform
::
Place
&
place
)
{
const
platform
::
Place
&
place
)
{
if
(
platform
::
is_cpu_place
(
place
))
{
if
(
platform
::
is_cpu_place
(
place
))
{
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
// Static vars will remember first executor and its thread
platform
::
MKLDNNDeviceContext
*
dev_ctx
=
// so both of them need to be processed by the same thread within
(
platform
::
MKLDNNDeviceContext
*
)
pool
.
Get
(
place
);
// critical section
dev_ctx
->
SetKeySuffix
(
"E"
+
static
std
::
mutex
static_vars_barrier
;
std
::
to_string
(
reinterpret_cast
<
uintptr_t
>
(
ptr
)));
static_vars_barrier
.
lock
();
// When NaiveExecutor/Executor is used no info on thread id is needed in a
static
auto
first_exec
=
ptr
;
// key
static
auto
first_thread
=
ThreadIDasStr
();
dev_ctx
->
DisableThreadInfoInKey
();
static_vars_barrier
.
unlock
();
if
(
first_exec
!=
ptr
)
{
paddle
::
platform
::
MKLDNNDeviceContext
::
tls
().
set_key_suffix
(
"E"
+
std
::
to_string
(
reinterpret_cast
<
uintptr_t
>
(
ptr
)));
}
// For first thread
if
(
first_thread
==
ThreadIDasStr
())
{
paddle
::
platform
::
MKLDNNDeviceContext
::
tls
().
disable_tid_in_key
();
}
}
}
}
}
...
@@ -457,13 +466,14 @@ inline std::string CreateKey(const platform::MKLDNNDeviceContext& dev_ctx,
...
@@ -457,13 +466,14 @@ inline std::string CreateKey(const platform::MKLDNNDeviceContext& dev_ctx,
key
.
reserve
(
64
);
key
.
reserve
(
64
);
using
expand_type
=
int
[];
using
expand_type
=
int
[];
expand_type
{
0
,
(
AppendKey
(
&
key
,
std
::
forward
<
ArgTypes
>
(
args
)),
0
)...};
expand_type
{
0
,
(
AppendKey
(
&
key
,
std
::
forward
<
ArgTypes
>
(
args
)),
0
)...};
key
+=
dev_ctx
.
GetKeyS
uffix
();
key
+=
paddle
::
platform
::
MKLDNNDeviceContext
::
tls
().
get_key_s
uffix
();
return
key
;
return
key
;
}
}
inline
std
::
string
ExtendKeyWithThreadInfoIfNeeded
(
inline
std
::
string
ExtendKeyWithThreadInfoIfNeeded
(
const
platform
::
MKLDNNDeviceContext
&
dev_ctx
,
const
std
::
string
&
key
)
{
const
platform
::
MKLDNNDeviceContext
&
dev_ctx
,
const
std
::
string
&
key
)
{
return
((
dev_ctx
.
IsThreadIdUsedInKey
()
==
true
)
&&
return
((
paddle
::
platform
::
MKLDNNDeviceContext
::
tls
().
is_tid_used_in_key
()
==
true
)
&&
(
platform
::
MKLDNNDeviceContext
::
tls
().
get_cur_mkldnn_session_id
()
==
(
platform
::
MKLDNNDeviceContext
::
tls
().
get_cur_mkldnn_session_id
()
==
platform
::
MKLDNNDeviceContextThreadLocals
::
kMKLDNNSessionID_Default
))
platform
::
MKLDNNDeviceContextThreadLocals
::
kMKLDNNSessionID_Default
))
?
key
+
"-t:"
+
ThreadIDasStr
()
?
key
+
"-t:"
+
ThreadIDasStr
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录