Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bd1d6d3b
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,发现更多精彩内容 >>
未验证
提交
bd1d6d3b
编写于
11月 23, 2020
作者:
J
Jacek Czaja
提交者:
GitHub
11月 23, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extends oneDNN caching keys so caching objects are unique to executor/predictor (#28758)
上级
3d0ff8ee
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
36 addition
and
6 deletion
+36
-6
paddle/fluid/framework/executor.cc
paddle/fluid/framework/executor.cc
+1
-0
paddle/fluid/framework/naive_executor.cc
paddle/fluid/framework/naive_executor.cc
+3
-0
paddle/fluid/operators/mkldnn/concat_mkldnn_op.cc
paddle/fluid/operators/mkldnn/concat_mkldnn_op.cc
+1
-1
paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc
paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc
+5
-3
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
+2
-2
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+5
-0
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+17
-0
paddle/fluid/platform/mkldnn_reuse.h
paddle/fluid/platform/mkldnn_reuse.h
+2
-0
未找到文件。
paddle/fluid/framework/executor.cc
浏览文件 @
bd1d6d3b
...
...
@@ -557,6 +557,7 @@ void Executor::EnableMKLDNN(const ProgramDesc& program) {
}
}
}
platform
::
AttachPointerHashToMKLDNNKey
(
this
,
place_
);
#else
LOG
(
WARNING
)
<<
"'MKLDNN' is not supported, Please re-compile with WITH_MKLDNN option"
;
...
...
paddle/fluid/framework/naive_executor.cc
浏览文件 @
bd1d6d3b
...
...
@@ -44,6 +44,9 @@ void NaiveExecutor::Prepare(Scope *scope, const ProgramDesc &program_desc,
}
void
NaiveExecutor
::
Run
()
{
#ifdef PADDLE_WITH_MKLDNN
platform
::
AttachPointerHashToMKLDNNKey
(
this
,
place_
);
#endif
for
(
auto
&
op
:
ops_
)
{
VLOG
(
4
)
<<
std
::
this_thread
::
get_id
()
<<
" run "
<<
op
->
DebugStringEx
(
scope_
)
<<
" on scope "
<<
scope_
;
...
...
paddle/fluid/operators/mkldnn/concat_mkldnn_op.cc
浏览文件 @
bd1d6d3b
...
...
@@ -160,7 +160,7 @@ class ConcatMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
std
::
string
key
=
platform
::
CreateKey
(
paddle
::
framework
::
vectorize
<
int
>
(
multi_input
[
0
]
->
dims
()),
multi_input
.
size
(),
ctx
.
OutputName
(
"Out"
),
dt
,
platform
::
ThreadIDasStr
());
platform
::
ThreadIDasStr
()
,
dev_ctx
.
GetKeySuffix
()
);
const
std
::
string
key_prim
=
key
+
"@concat_p"
;
const
std
::
string
key_concat_pd
=
key
+
"@concat_pd"
;
...
...
paddle/fluid/operators/mkldnn/fc_mkldnn_op.cc
浏览文件 @
bd1d6d3b
...
...
@@ -361,7 +361,8 @@ class FCPrimitiveFactory {
void
CacheWeightsAndBias
(
const
MKLDNNDeviceContext
&
dev_ctx
,
const
ExecutionContext
&
ctx
)
{
const
std
::
string
key
=
platform
::
CreateKey
(
platform
::
ThreadIDasStr
());
const
std
::
string
key
=
platform
::
CreateKey
(
platform
::
ThreadIDasStr
(),
dev_ctx
.
GetKeySuffix
());
const
std
::
string
weights_key
=
key
+
ctx
.
InputName
(
"W"
);
const
std
::
string
bias_key
=
key
+
ctx
.
InputName
(
"Bias"
);
dev_ctx
.
SetBlob
(
weights_key
,
weights_
);
...
...
@@ -532,8 +533,9 @@ static void ExecuteFc(const ExecutionContext& ctx, const LoDTensor* input,
bool
fuse_relu
,
bool
force_fp32_output
)
{
auto
&
dev_ctx
=
ctx
.
template
device_context
<
MKLDNNDeviceContext
>();
const
std
::
string
prim_key
=
platform
::
CreateKey
(
platform
::
ThreadIDasStr
(),
input
->
format
(),
input
->
dims
()[
0
],
framework
::
vectorize
<
int
>
(
w
->
dims
()),
ctx
.
OutputName
(
"Out"
));
platform
::
ThreadIDasStr
(),
dev_ctx
.
GetKeySuffix
(),
input
->
format
(),
input
->
dims
()[
0
],
framework
::
vectorize
<
int
>
(
w
->
dims
()),
ctx
.
OutputName
(
"Out"
));
constexpr
bool
is_int8
=
std
::
is_same
<
T_in
,
int8_t
>::
value
||
std
::
is_same
<
T_in
,
uint8_t
>::
value
;
bool
is_bfloat16
=
std
::
is_same
<
T_in
,
paddle
::
platform
::
bfloat16
>::
value
;
...
...
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
浏览文件 @
bd1d6d3b
...
...
@@ -337,8 +337,8 @@ static std::shared_ptr<MatMulFactory<XT, YT, OT>> GetPrimitiveFactory(
const
auto
&
dev_ctx
=
ctx
.
template
device_context
<
MKLDNNDeviceContext
>();
const
auto
batch_size
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
()[
0
];
const
std
::
string
key
=
platform
::
CreateKey
(
platform
::
ThreadIDasStr
(),
batch_size
,
out_name
);
const
std
::
string
key
=
platform
::
CreateKey
(
platform
::
ThreadIDasStr
(),
dev_ctx
.
GetKeySuffix
(),
batch_size
,
out_name
);
auto
factory
=
std
::
static_pointer_cast
<
MatMulFactory
<
XT
,
YT
,
OT
>>
(
dev_ctx
.
GetBlob
(
key
));
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
bd1d6d3b
...
...
@@ -535,6 +535,10 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
// Remove all entries from the blob map
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_
;
}
// Prevent next ResetBlobMap()
void
BlockNextCacheClearing
();
...
...
@@ -556,6 +560,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
std
::
shared_ptr
<
BlobMap
>
p_blobmap_
;
std
::
shared_ptr
<
std
::
mutex
>
p_mutex_
;
bool
block_next_cache_clearing_
=
false
;
std
::
string
key_suffix_
;
// Key identifying current Executor
};
#endif
...
...
paddle/fluid/platform/mkldnn_helper.h
浏览文件 @
bd1d6d3b
...
...
@@ -433,6 +433,23 @@ inline void AppendKey(std::string* key, const std::vector<T>& dims) {
}
}
inline
unsigned
int
HashPointer
(
uintptr_t
ptr
)
{
// Get four less meaningful digits in decimal numerals
return
ptr
%
1000
;
}
// If MKLDNN build and CPU place then register suffix in DeviceContext
inline
void
AttachPointerHashToMKLDNNKey
(
void
*
ptr
,
const
platform
::
Place
&
place
)
{
if
(
platform
::
is_cpu_place
(
place
))
{
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
MKLDNNDeviceContext
*
dev_ctx
=
(
platform
::
MKLDNNDeviceContext
*
)
pool
.
Get
(
place
);
dev_ctx
->
SetKeySuffix
(
"E"
+
std
::
to_string
(
platform
::
HashPointer
(
reinterpret_cast
<
uintptr_t
>
(
ptr
))));
}
}
template
<
typename
...
ArgTypes
>
inline
std
::
string
CreateKey
(
ArgTypes
&&
...
args
)
{
std
::
string
key
;
...
...
paddle/fluid/platform/mkldnn_reuse.h
浏览文件 @
bd1d6d3b
...
...
@@ -51,6 +51,7 @@ class MKLDNNHandlerT {
}
else
{
key_
=
key_common_
+
"-t:"
+
ThreadIDasStr
();
}
key_
+=
dev_ctx
.
GetKeySuffix
();
}
std
::
shared_ptr
<
TForward
>
AcquireForwardPrimitive
()
{
...
...
@@ -316,6 +317,7 @@ class MKLDNNHandler {
}
else
{
key_
=
key_common_
+
"-t:"
+
ThreadIDasStr
();
}
key_
+=
dev_ctx
.
GetKeySuffix
();
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireSrcMemory
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录