Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e7724a2c
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e7724a2c
编写于
7月 17, 2020
作者:
A
Adam
提交者:
GitHub
7月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor of conv fp32 oneDNN operator (#25137) (#25572)
上级
9bf70039
变更
2
展开全部
显示空白变更内容
内联
并排
Showing
2 changed file
with
467 addition
and
266 deletion
+467
-266
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
+345
-261
paddle/fluid/platform/mkldnn_reuse.h
paddle/fluid/platform/mkldnn_reuse.h
+122
-5
未找到文件。
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
浏览文件 @
e7724a2c
此差异已折叠。
点击以展开。
paddle/fluid/platform/mkldnn_reuse.h
浏览文件 @
e7724a2c
...
...
@@ -108,8 +108,20 @@ class MKLDNNHandlerT {
}
protected:
template
<
typename
...
Args
>
void
AcquireForwardPrimitiveDescriptor
(
Args
&&
...
args
)
{
bool
isCached
()
{
const
std
::
string
key_pd
=
key_common_
+
"@forward_pd"
;
fwd_pd_
=
std
::
static_pointer_cast
<
typename
TForward
::
primitive_desc
>
(
dev_ctx_
.
GetBlob
(
key_pd
));
const
std
::
string
key_p
=
key_
+
"@forward_p"
;
return
(
dev_ctx_
.
GetBlob
(
key_p
)
!=
nullptr
);
}
// If your primitive descriptor requires attributes, pass them as a
// first argument and paramters to descriptor constructor in the following
// arguments. Otherwise, all arguments will be forwarded to descriptor
// constructor, including the first one.
template
<
typename
Arg
,
typename
...
Args
>
void
AcquireForwardPrimitiveDescriptor
(
Arg
&&
first_arg
,
Args
&&
...
args
)
{
// Forward PD has to be passed to Grad op that
// may be executed by diffrent thread, hence
// for that one we use key that does not contain TID
...
...
@@ -123,14 +135,34 @@ class MKLDNNHandlerT {
fwd_pd_
=
std
::
static_pointer_cast
<
typename
TForward
::
primitive_desc
>
(
dev_ctx_
.
GetBlob
(
key_pd
));
if
(
fwd_pd_
==
nullptr
)
{
auto
fwd_desc
=
typename
TForward
::
desc
(
std
::
forward
<
Args
>
(
args
)...);
fwd_pd_
=
std
::
make_shared
<
typename
TForward
::
primitive_desc
>
(
fwd_desc
,
engine_
);
CreateForwardPrimitiveDescriptor
(
first_arg
,
std
::
forward
<
Args
>
(
args
)...);
dev_ctx_
.
SetBlob
(
key_pd
,
fwd_pd_
);
}
}
}
// Using sfinae to specialise variadic function. Workaround for not having
// if constexpr in C++ 11.
template
<
class
First
,
class
...
Args
>
typename
std
::
enable_if
<
std
::
is_same
<
typename
std
::
decay
<
First
>::
type
,
dnnl
::
primitive_attr
>::
value
>::
type
CreateForwardPrimitiveDescriptor
(
First
&&
first
,
Args
&&
...
args
)
{
auto
fwd_desc
=
typename
TForward
::
desc
(
std
::
forward
<
Args
>
(
args
)...);
fwd_pd_
=
std
::
make_shared
<
typename
TForward
::
primitive_desc
>
(
fwd_desc
,
first
,
engine_
);
}
template
<
class
First
,
class
...
Args
>
typename
std
::
enable_if
<!
std
::
is_same
<
typename
std
::
decay
<
First
>::
type
,
dnnl
::
primitive_attr
>::
value
>::
type
CreateForwardPrimitiveDescriptor
(
First
&&
first
,
Args
&&
...
args
)
{
auto
fwd_desc
=
typename
TForward
::
desc
(
std
::
forward
<
First
>
(
first
),
std
::
forward
<
Args
>
(
args
)...);
fwd_pd_
=
std
::
make_shared
<
typename
TForward
::
primitive_desc
>
(
fwd_desc
,
engine_
);
}
template
<
typename
...
Args
>
void
AcquireBackwardPrimitiveDescriptor
(
Args
&&
...
args
)
{
const
std
::
string
key_fwd_pd
=
key_common_
+
"@forward_pd"
;
...
...
@@ -162,6 +194,91 @@ class MKLDNNHandlerT {
return
mem_p
;
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireMemoryFromPrimitive
(
mkldnn
::
memory
::
desc
md
,
const
std
::
string
&
suffix
)
{
const
auto
local_key
=
key_
+
suffix
;
auto
mem_p
=
std
::
static_pointer_cast
<
mkldnn
::
memory
>
(
dev_ctx_
.
GetBlob
(
local_key
));
if
(
mem_p
==
nullptr
)
{
mem_p
=
std
::
make_shared
<
mkldnn
::
memory
>
(
md
,
engine_
);
dev_ctx_
.
SetBlob
(
local_key
,
mem_p
);
}
return
mem_p
;
}
void
AcquireReorder
(
const
std
::
shared_ptr
<
mkldnn
::
memory
>&
user_memory_p
,
const
std
::
shared_ptr
<
mkldnn
::
memory
>&
target_memory_p
,
const
std
::
string
&
suffix
)
{
const
auto
key_reorder_p
=
key_
+
suffix
+
"reorder_p"
;
auto
reorder_p
=
std
::
static_pointer_cast
<
mkldnn
::
reorder
>
(
dev_ctx_
.
GetBlob
(
key_reorder_p
));
if
(
reorder_p
==
nullptr
)
{
reorder_p
=
std
::
make_shared
<
mkldnn
::
reorder
>
(
*
user_memory_p
,
*
target_memory_p
);
dev_ctx_
.
SetBlob
(
key_reorder_p
,
reorder_p
);
}
mkldnn
::
stream
astream
(
engine_
);
reorder_p
->
execute
(
astream
,
{{
MKLDNN_ARG_FROM
,
*
user_memory_p
},
{
MKLDNN_ARG_TO
,
*
target_memory_p
}});
astream
.
wait
();
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireMemoryWithReorder
(
const
mkldnn
::
memory
::
desc
&
user_md
,
const
mkldnn
::
memory
::
desc
&
target_md
,
void
*
ptr
,
const
std
::
string
&
suffix
,
bool
is_persistent
=
false
)
{
const
auto
target_key
=
key_
+
suffix
+
"_target"
;
const
auto
key_reorder_p
=
key_
+
suffix
+
"reorder_p"
;
const
auto
user_key
=
key_
+
suffix
+
"_user"
;
auto
target_memory_p
=
std
::
static_pointer_cast
<
dnnl
::
memory
>
(
dev_ctx_
.
GetBlob
(
target_key
));
if
(
target_memory_p
==
nullptr
)
{
auto
user_memory_p
=
std
::
make_shared
<
dnnl
::
memory
>
(
user_md
,
engine_
,
ptr
);
if
(
user_md
!=
target_md
)
{
target_memory_p
=
std
::
make_shared
<
mkldnn
::
memory
>
(
target_md
,
engine_
);
auto
reorder_p
=
std
::
make_shared
<
dnnl
::
reorder
>
(
*
user_memory_p
,
*
target_memory_p
);
dev_ctx_
.
SetBlob
(
key_reorder_p
,
reorder_p
);
mkldnn
::
stream
astream
(
engine_
);
reorder_p
->
execute
(
astream
,
{{
MKLDNN_ARG_FROM
,
*
user_memory_p
},
{
MKLDNN_ARG_TO
,
*
target_memory_p
}});
astream
.
wait
();
}
else
{
target_memory_p
=
user_memory_p
;
}
dev_ctx_
.
SetBlob
(
user_key
,
user_memory_p
);
dev_ctx_
.
SetBlob
(
target_key
,
target_memory_p
);
}
else
if
(
!
is_persistent
)
{
mkldnn
::
stream
astream
(
engine_
);
auto
user_memory_p
=
std
::
static_pointer_cast
<
dnnl
::
memory
>
(
dev_ctx_
.
GetBlob
(
user_key
));
user_memory_p
->
set_data_handle
(
ptr
);
auto
reorder_p
=
std
::
static_pointer_cast
<
mkldnn
::
reorder
>
(
dev_ctx_
.
GetBlob
(
key_reorder_p
));
if
(
reorder_p
!=
nullptr
)
{
reorder_p
->
execute
(
astream
,
{{
MKLDNN_ARG_FROM
,
*
user_memory_p
},
{
MKLDNN_ARG_TO
,
*
target_memory_p
}});
astream
.
wait
();
}
}
return
target_memory_p
;
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireMemory
(
const
std
::
string
&
suffix
)
{
const
auto
local_key
=
key_
+
suffix
;
return
std
::
static_pointer_cast
<
mkldnn
::
memory
>
(
dev_ctx_
.
GetBlob
(
local_key
));
}
const
MKLDNNDeviceContext
&
dev_ctx_
;
mkldnn
::
engine
engine_
;
platform
::
Place
place_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录