Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7c9aabd1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2300
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看板
提交
7c9aabd1
编写于
11月 14, 2018
作者:
X
xiaolil1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert md reuse
上级
2b2eac47
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
77 addition
and
77 deletion
+77
-77
paddle/fluid/operators/conv_mkldnn_op.cc
paddle/fluid/operators/conv_mkldnn_op.cc
+77
-77
未找到文件。
paddle/fluid/operators/conv_mkldnn_op.cc
浏览文件 @
7c9aabd1
...
@@ -560,18 +560,18 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -560,18 +560,18 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
}
}
static
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>>
md_map
;
//
static std::unordered_map<std::string, std::shared_ptr<mkldnn::memory::desc>> md_map;
bool
md_reuse
=
true
;
//
bool md_reuse = true;
auto
user_src_md_key
=
key
+
"@user_src_md"
;
//
auto user_src_md_key = key + "@user_src_md";
if
(
GetMdMap
(
md_map
,
user_src_md_key
)
==
nullptr
){
//
if (GetMdMap(md_map, user_src_md_key) == nullptr){
md_reuse
=
false
;
//we suppose all mds are reused if the first md is in the map.
//
md_reuse = false; //we suppose all mds are reused if the first md is in the map.
}
//
}
auto
user_weights_md_key
=
key
+
"@user_weights_md"
;
//
auto user_weights_md_key = key + "@user_weights_md";
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_src_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_src_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_weights_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_weights_md
;
std
::
vector
<
primitive
>
pipeline
;
std
::
vector
<
primitive
>
pipeline
;
//std::cout<<"md_reuse = "<<md_reuse<<std::endl;
//std::cout<<"md_reuse = "<<md_reuse<<std::endl;
if
(
!
md_reuse
){
//
if(!md_reuse){
//std::cout<<"create md.......... "<<std::endl;
//std::cout<<"create md.......... "<<std::endl;
user_src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
user_src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
{
src_tz
},
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
()),
input
->
format
())));
{
src_tz
},
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
()),
input
->
format
())));
...
@@ -579,12 +579,12 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -579,12 +579,12 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
{
weights_tz
},
platform
::
MKLDNNGetDataType
<
float
>
(),
{
weights_tz
},
platform
::
MKLDNNGetDataType
<
float
>
(),
(
g
==
1
)
?
mkldnn
::
memory
::
format
::
oihw
:
mkldnn
::
memory
::
format
::
goihw
)));
(
g
==
1
)
?
mkldnn
::
memory
::
format
::
oihw
:
mkldnn
::
memory
::
format
::
goihw
)));
SetMdMap
(
md_map
,
user_src_md_key
,
user_src_md
);
//
SetMdMap(md_map, user_src_md_key, user_src_md);
SetMdMap
(
md_map
,
user_weights_md_key
,
user_weights_md
);
//
SetMdMap(md_map, user_weights_md_key, user_weights_md);
}
else
{
//
} else{
user_src_md
=
GetMdMap
(
md_map
,
user_src_md_key
);
//
user_src_md = GetMdMap(md_map, user_src_md_key);
user_weights_md
=
GetMdMap
(
md_map
,
user_weights_md_key
);
//
user_weights_md = GetMdMap(md_map, user_weights_md_key);
}
//
}
/* create memory descriptor for convolution without specified format
/* create memory descriptor for convolution without specified format
* ('any') which lets a primitive (convolution in this case) choose
* ('any') which lets a primitive (convolution in this case) choose
...
@@ -597,16 +597,16 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -597,16 +597,16 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
std
::
shared_ptr
<
mkldnn
::
convolution_forward
::
primitive_desc
>
conv_pd
;
std
::
shared_ptr
<
mkldnn
::
convolution_forward
::
primitive_desc
>
conv_pd
;
auto
bias_tz
=
paddle
::
framework
::
vectorize2int
(
bias
->
dims
());
auto
bias_tz
=
paddle
::
framework
::
vectorize2int
(
bias
->
dims
());
auto
src_md_key
=
key
+
"@src_md"
;
//
auto src_md_key = key + "@src_md";
auto
weights_md_key
=
key
+
"@weights_md_key"
;
//
auto weights_md_key = key + "@weights_md_key";
auto
dst_md_key
=
key
+
"@dst_md_key"
;
//
auto dst_md_key = key + "@dst_md_key";
auto
bias_md_key
=
key
+
"@bias_md_key"
;
//
auto bias_md_key = key + "@bias_md_key";
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
src_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
src_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
weights_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
weights_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
dst_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
dst_md
;
if
(
is_INT8
){
if
(
is_INT8
){
if
(
!
md_reuse
){
//
if(!md_reuse){
src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
src_tz
,
memory
::
data_type
::
u8
,
chosen_memory_format
)));
src_tz
,
memory
::
data_type
::
u8
,
chosen_memory_format
)));
weights_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
weights_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
...
@@ -621,25 +621,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -621,25 +621,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
if
(
force_fp32_output
)
if
(
force_fp32_output
)
dst_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
std
::
type_index
(
typeid
(
float
)));
dst_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
std
::
type_index
(
typeid
(
float
)));
dst_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
dst_tz
,
dst_dt
,
chosen_memory_format
)));
dst_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
dst_tz
,
dst_dt
,
chosen_memory_format
)));
SetMdMap
(
md_map
,
src_md_key
,
src_md
);
//
SetMdMap(md_map, src_md_key, src_md);
SetMdMap
(
md_map
,
weights_md_key
,
weights_md
);
//
SetMdMap(md_map, weights_md_key, weights_md);
SetMdMap
(
md_map
,
dst_md_key
,
dst_md
);
//
SetMdMap(md_map, dst_md_key, dst_md);
}
else
{
//
} else{
src_md
=
GetMdMap
(
md_map
,
src_md_key
);
//
src_md = GetMdMap(md_map, src_md_key);
weights_md
=
GetMdMap
(
md_map
,
weights_md_key
);
//
weights_md = GetMdMap(md_map, weights_md_key);
dst_md
=
GetMdMap
(
md_map
,
dst_md_key
);
//
dst_md = GetMdMap(md_map, dst_md_key);
}
//
}
// create a conv primitive descriptor and save it for usage in backward
// create a conv primitive descriptor and save it for usage in backward
if
(
bias
)
{
if
(
bias
)
{
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
bias_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
bias_md
;
if
(
!
md_reuse
){
//
if(!md_reuse){
bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
bias_tz
,
memory
::
data_type
::
s32
,
memory
::
format
::
x
)));
bias_tz
,
memory
::
data_type
::
s32
,
memory
::
format
::
x
)));
SetMdMap
(
md_map
,
bias_md_key
,
bias_md
);
//
SetMdMap(md_map, bias_md_key, bias_md);
}
else
{
//
} else{
bias_md
=
GetMdMap
(
md_map
,
bias_md_key
);
//
bias_md = GetMdMap(md_map, bias_md_key);
}
//
}
conv_pd
=
ConvFwdPrimitiveDesc
(
*
src_md
,
*
weights_md
,
*
bias_md
,
*
dst_md
,
conv_pd
=
ConvFwdPrimitiveDesc
(
*
src_md
,
*
weights_md
,
*
bias_md
,
*
dst_md
,
strides
,
paddings
,
mkldnn_engine
,
strides
,
paddings
,
mkldnn_engine
,
...
@@ -652,31 +652,31 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -652,31 +652,31 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
output_shift_scale
,
sum_scale
[
0
],
is_test
);
output_shift_scale
,
sum_scale
[
0
],
is_test
);
}
}
}
else
{
}
else
{
if
(
!
md_reuse
){
//
if(!md_reuse){
src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
src_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
src_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
src_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
weights_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
weights_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
weights_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
weights_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
dst_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
dst_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
dst_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
dst_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
chosen_memory_format
)));
SetMdMap
(
md_map
,
src_md_key
,
src_md
);
//
SetMdMap(md_map, src_md_key, src_md);
SetMdMap
(
md_map
,
weights_md_key
,
weights_md
);
//
SetMdMap(md_map, weights_md_key, weights_md);
SetMdMap
(
md_map
,
dst_md_key
,
dst_md
);
//
SetMdMap(md_map, dst_md_key, dst_md);
}
else
{
//
} else{
src_md
=
GetMdMap
(
md_map
,
src_md_key
);
//
src_md = GetMdMap(md_map, src_md_key);
weights_md
=
GetMdMap
(
md_map
,
weights_md_key
);
//
weights_md = GetMdMap(md_map, weights_md_key);
dst_md
=
GetMdMap
(
md_map
,
dst_md_key
);
//
dst_md = GetMdMap(md_map, dst_md_key);
}
//
}
// create a conv primitive descriptor and save it for usage in backward
// create a conv primitive descriptor and save it for usage in backward
if
(
bias
)
{
if
(
bias
)
{
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
bias_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
bias_md
;
if
(
!
md_reuse
){
//
if(!md_reuse){
bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
bias_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
memory
::
format
::
x
)));
bias_tz
,
platform
::
MKLDNNGetDataType
<
float
>
(),
memory
::
format
::
x
)));
SetMdMap
(
md_map
,
bias_md_key
,
bias_md
);
//
SetMdMap(md_map, bias_md_key, bias_md);
}
else
{
//
} else{
bias_md
=
GetMdMap
(
md_map
,
bias_md_key
);
//
bias_md = GetMdMap(md_map, bias_md_key);
}
//
}
conv_pd
=
ConvFwdPrimitiveDesc
(
*
src_md
,
*
weights_md
,
*
bias_md
,
*
dst_md
,
conv_pd
=
ConvFwdPrimitiveDesc
(
*
src_md
,
*
weights_md
,
*
bias_md
,
*
dst_md
,
strides
,
paddings
,
mkldnn_engine
,
strides
,
paddings
,
mkldnn_engine
,
fuse_relu
,
fuse_residual_conn
,
is_test
);
fuse_relu
,
fuse_residual_conn
,
is_test
);
...
@@ -714,7 +714,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -714,7 +714,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
std
::
shared_ptr
<
mkldnn
::
memory
>
dst_memory_p
;
std
::
shared_ptr
<
mkldnn
::
memory
>
dst_memory_p
;
bool
need_s8_to_u8
=
false
;
bool
need_s8_to_u8
=
false
;
auto
user_residual_md_key
=
key
+
"@user_residual_md"
;
//
auto user_residual_md_key = key + "@user_residual_md";
if
(
fuse_residual_conn
)
{
if
(
fuse_residual_conn
)
{
auto
residual_param
=
ctx
.
Input
<
Tensor
>
(
"ResidualData"
);
auto
residual_param
=
ctx
.
Input
<
Tensor
>
(
"ResidualData"
);
PADDLE_ENFORCE_EQ
(
output
->
dims
(),
residual_param
->
dims
(),
PADDLE_ENFORCE_EQ
(
output
->
dims
(),
residual_param
->
dims
(),
...
@@ -723,17 +723,17 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -723,17 +723,17 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
residual_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
residual_param
->
type
());
auto
residual_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
residual_param
->
type
());
if
(
residual_param
->
format
()
!=
handler
.
GetDstFormat
())
{
if
(
residual_param
->
format
()
!=
handler
.
GetDstFormat
())
{
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_residual_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_residual_md
;
if
(
!
md_reuse
){
//
if(!md_reuse){
auto
residual_data_tz
=
auto
residual_data_tz
=
paddle
::
framework
::
vectorize2int
(
residual_param
->
dims
());
paddle
::
framework
::
vectorize2int
(
residual_param
->
dims
());
auto
residual_data_type
=
auto
residual_data_type
=
paddle
::
framework
::
ToMKLDNNDataType
(
residual_param
->
type
());
paddle
::
framework
::
ToMKLDNNDataType
(
residual_param
->
type
());
user_residual_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
user_residual_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
residual_data_tz
,
residual_data_type
,
residual_param
->
format
())));
residual_data_tz
,
residual_data_type
,
residual_param
->
format
())));
SetMdMap
(
md_map
,
user_residual_md_key
,
user_residual_md
);
//
SetMdMap(md_map, user_residual_md_key, user_residual_md);
}
else
{
//
} else{
user_residual_md
=
GetMdMap
(
md_map
,
user_residual_md_key
);
//
user_residual_md = GetMdMap(md_map, user_residual_md_key);
}
//
}
if
(
is_INT8
){
if
(
is_INT8
){
PADDLE_ENFORCE
(
PADDLE_ENFORCE
(
force_fp32_output
==
false
,
force_fp32_output
==
false
,
...
@@ -818,17 +818,17 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -818,17 +818,17 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
// create convolution op primitive
// create convolution op primitive
std
::
shared_ptr
<
mkldnn
::
convolution_forward
>
conv_p
;
std
::
shared_ptr
<
mkldnn
::
convolution_forward
>
conv_p
;
//auto scale_bias_key = key + "@scale_bias";
//auto scale_bias_key = key + "@scale_bias";
auto
user_bias_md_key
=
key
+
"@user_bias_md"
;
//
auto user_bias_md_key = key + "@user_bias_md";
if
(
bias
)
{
if
(
bias
)
{
const
float
*
bias_data
=
bias
->
data
<
float
>
();
const
float
*
bias_data
=
bias
->
data
<
float
>
();
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_bias_md
;
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
user_bias_md
;
if
(
!
md_reuse
){
//
if(!md_reuse){
user_bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
user_bias_md
.
reset
(
new
mkldnn
::
memory
::
desc
(
platform
::
MKLDNNMemDesc
(
{
bias_tz
},
platform
::
MKLDNNGetDataType
<
float
>
(),
memory
::
format
::
x
)));
{
bias_tz
},
platform
::
MKLDNNGetDataType
<
float
>
(),
memory
::
format
::
x
)));
SetMdMap
(
md_map
,
user_bias_md_key
,
user_bias_md
);
//
SetMdMap(md_map, user_bias_md_key, user_bias_md);
}
else
{
//
} else{
user_bias_md
=
GetMdMap
(
md_map
,
user_bias_md_key
);
//
user_bias_md = GetMdMap(md_map, user_bias_md_key);
}
//
}
auto
user_bias_memory_p
=
auto
user_bias_memory_p
=
handler
.
AcquireBiasMemory
(
*
user_bias_md
,
to_void_cast
<
float
>
(
bias_data
));
handler
.
AcquireBiasMemory
(
*
user_bias_md
,
to_void_cast
<
float
>
(
bias_data
));
std
::
shared_ptr
<
mkldnn
::
memory
>
bias_memory_p
;
std
::
shared_ptr
<
mkldnn
::
memory
>
bias_memory_p
;
...
@@ -898,25 +898,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
...
@@ -898,25 +898,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
return
{{
0.0
f
}};
return
{{
0.0
f
}};
}
}
void
SetMdMap
(
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>>
&
md_map
,
//
void SetMdMap(std::unordered_map<std::string, std::shared_ptr<mkldnn::memory::desc>> &md_map,
const
std
::
string
&
name
,
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
mds
)
const
{
//
const std::string& name, std::shared_ptr<mkldnn::memory::desc> mds) const {
auto
it
=
md_map
.
find
(
name
);
//
auto it = md_map.find(name);
if
(
it
==
md_map
.
end
())
{
//
if (it == md_map.end()) {
md_map
[
name
]
=
mds
;
// create new blob
//
md_map[name] = mds; // create new blob
}
else
{
//
} else {
(
*
it
).
second
=
mds
;
// set data to existing blob
//
(*it).second = mds; // set data to existing blob
}
//
}
return
;
//
return;
}
//
}
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>
GetMdMap
(
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
mkldnn
::
memory
::
desc
>>
md_map
,
//
std::shared_ptr<mkldnn::memory::desc> GetMdMap(std::unordered_map<std::string, std::shared_ptr<mkldnn::memory::desc>> md_map,
const
std
::
string
&
name
)
const
{
//
const std::string& name) const {
auto
it
=
md_map
.
find
(
name
);
//
auto it = md_map.find(name);
if
(
it
!=
md_map
.
end
())
{
//
if (it != md_map.end()) {
return
(
*
it
).
second
;
//
return (*it).second;
}
//
}
return
nullptr
;
//
return nullptr;
}
//
}
mkldnn
::
primitive_attr
CreatePostOps
(
bool
fuse_relu
,
bool
fuse_residual_conn
,
mkldnn
::
primitive_attr
CreatePostOps
(
bool
fuse_relu
,
bool
fuse_residual_conn
,
const
std
::
vector
<
float
>
output_shift_scale
,
float
sum_scale
)
const
{
const
std
::
vector
<
float
>
output_shift_scale
,
float
sum_scale
)
const
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录