Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4f6b43a0
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
4f6b43a0
编写于
10月 22, 2019
作者:
A
Adam
提交者:
Tao Luo
10月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor MKL-DNN conv int8 performance fixes (#20768)
test=develop
上级
392fa55c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
51 deletion
+58
-51
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
+57
-50
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+1
-1
未找到文件。
paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc
浏览文件 @
4f6b43a0
...
...
@@ -338,8 +338,6 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
const
auto
&
mkldnn_engine
=
dev_ctx
.
GetEngine
();
auto
*
input
=
ctx
.
Input
<
Tensor
>
(
"Input"
);
auto
*
filter
=
ctx
.
Input
<
Tensor
>
(
"Filter"
);
auto
*
bias
=
ctx
.
HasInput
(
"Bias"
)
?
ctx
.
Input
<
Tensor
>
(
"Bias"
)
:
nullptr
;
auto
*
output
=
ctx
.
Output
<
Tensor
>
(
"Output"
);
PADDLE_ENFORCE_EQ
(
input
->
layout
(),
DataLayout
::
kMKLDNN
,
...
...
@@ -347,11 +345,6 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
PADDLE_ENFORCE_NE
(
input
->
format
(),
MKLDNNMemoryFormat
::
format_undef
,
"Wrong format set for Input tensor"
);
PADDLE_ENFORCE_EQ
(
filter
->
layout
(),
DataLayout
::
kMKLDNN
,
"Wrong layout set for Filter tensor"
);
PADDLE_ENFORCE_NE
(
filter
->
format
(),
MKLDNNMemoryFormat
::
format_undef
,
"Wrong format set for Filter tensor"
);
PADDLE_ENFORCE_GE
(
input
->
dims
().
size
(),
4
,
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW"
);
...
...
@@ -359,57 +352,14 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
input
->
dims
().
size
(),
5
,
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW"
);
PADDLE_ENFORCE_GE
(
filter
->
dims
().
size
(),
4
,
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW"
);
PADDLE_ENFORCE_LE
(
filter
->
dims
().
size
(),
5
,
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW"
);
if
(
bias
)
{
PADDLE_ENFORCE_EQ
(
bias
->
layout
(),
DataLayout
::
kMKLDNN
,
"Wrong layout set for Bias tensor"
);
PADDLE_ENFORCE_NE
(
bias
->
format
(),
MKLDNNMemoryFormat
::
format_undef
,
"Wrong format set for Bias tensor"
);
PADDLE_ENFORCE_EQ
(
bias
->
dims
().
size
(),
1
,
"Bias must only have 1 dimension, i.e. X"
);
}
std
::
vector
<
int
>
strides
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
dilations
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"dilations"
);
int
groups
=
ctx
.
Attr
<
int
>
(
"groups"
);
std
::
string
fuse_activation
=
ctx
.
Attr
<
std
::
string
>
(
"fuse_activation"
);
float
fuse_alpha
=
ctx
.
Attr
<
float
>
(
"fuse_alpha"
);
float
fuse_beta
=
ctx
.
Attr
<
float
>
(
"fuse_beta"
);
bool
fuse_residual_conn
=
ctx
.
Attr
<
bool
>
(
"fuse_residual_connection"
);
bool
force_fp32_output
=
ctx
.
Attr
<
bool
>
(
"force_fp32_output"
);
bool
unsigned_output
=
(
fuse_activation
==
"relu"
||
fuse_activation
==
"relu6"
);
PADDLE_ENFORCE
(
!
fuse_residual_conn
||
!
force_fp32_output
,
"residual fusion does not support force output with fp32"
);
bool
is_conv3d
=
strides
.
size
()
==
3U
;
PADDLE_ENFORCE
(
is_conv3d
?
dilations
.
size
()
==
3
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
&&
dilations
[
2
]
==
1
:
dilations
.
size
()
==
2
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
,
"dilation in convolution is not implemented yet"
);
PADDLE_ENFORCE_NE
(
is_conv3d
,
true
,
"int8 does not support conv3d currently"
);
const
T
*
input_data
=
input
->
data
<
T
>
();
auto
src_tz
=
paddle
::
framework
::
vectorize
<
int
>
(
input
->
dims
());
auto
weights_tz
=
paddle
::
framework
::
vectorize
<
int
>
(
filter
->
dims
());
int
g
=
std
::
max
(
groups
,
1
);
GetWeightsTz
(
weights_tz
,
g
,
is_conv3d
);
auto
dst_tz
=
paddle
::
framework
::
vectorize
<
int
>
(
output
->
dims
());
mkldnn
::
memory
::
data_type
src_dt
=
paddle
::
framework
::
ToMKLDNNDataType
(
input
->
type
());
...
...
@@ -448,6 +398,63 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
dev_ctx
.
GetBlob
(
prim_key
));
if
(
conv_p
==
nullptr
||
!
is_test
)
{
float
fuse_alpha
=
ctx
.
Attr
<
float
>
(
"fuse_alpha"
);
float
fuse_beta
=
ctx
.
Attr
<
float
>
(
"fuse_beta"
);
bool
force_fp32_output
=
ctx
.
Attr
<
bool
>
(
"force_fp32_output"
);
auto
*
filter
=
ctx
.
Input
<
Tensor
>
(
"Filter"
);
PADDLE_ENFORCE_EQ
(
filter
->
layout
(),
DataLayout
::
kMKLDNN
,
"Wrong layout set for Filter tensor"
);
PADDLE_ENFORCE_NE
(
filter
->
format
(),
MKLDNNMemoryFormat
::
format_undef
,
"Wrong format set for Filter tensor"
);
PADDLE_ENFORCE_GE
(
filter
->
dims
().
size
(),
4
,
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW"
);
PADDLE_ENFORCE_LE
(
filter
->
dims
().
size
(),
5
,
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW"
);
PADDLE_ENFORCE_EQ
(
!
fuse_residual_conn
||
!
force_fp32_output
,
true
,
"residual fusion does not support force output with fp32"
);
auto
*
bias
=
ctx
.
HasInput
(
"Bias"
)
?
ctx
.
Input
<
Tensor
>
(
"Bias"
)
:
nullptr
;
if
(
bias
)
{
PADDLE_ENFORCE_EQ
(
bias
->
layout
(),
DataLayout
::
kMKLDNN
,
"Wrong layout set for Bias tensor"
);
PADDLE_ENFORCE_NE
(
bias
->
format
(),
MKLDNNMemoryFormat
::
format_undef
,
"Wrong format set for Bias tensor"
);
PADDLE_ENFORCE_EQ
(
bias
->
dims
().
size
(),
1
,
"Bias must only have 1 dimension, i.e. X"
);
}
std
::
vector
<
int
>
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
dilations
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"dilations"
);
std
::
vector
<
int
>
strides
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
bool
is_conv3d
=
strides
.
size
()
==
3U
;
PADDLE_ENFORCE_NE
(
is_conv3d
,
true
,
"int8 does not support conv3d currently"
);
int
groups
=
ctx
.
Attr
<
int
>
(
"groups"
);
auto
weights_tz
=
paddle
::
framework
::
vectorize
<
int
>
(
filter
->
dims
());
int
g
=
std
::
max
(
groups
,
1
);
GetWeightsTz
(
weights_tz
,
g
,
is_conv3d
);
auto
dst_tz
=
paddle
::
framework
::
vectorize
<
int
>
(
output
->
dims
());
PADDLE_ENFORCE_EQ
(
is_conv3d
?
dilations
.
size
()
==
3
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
&&
dilations
[
2
]
==
1
:
dilations
.
size
()
==
2
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
,
true
,
"dilation in convolution is not implemented yet"
);
const
K
*
filter_data
=
filter
->
data
<
K
>
();
auto
scale_in_data
=
ctx
.
Attr
<
float
>
(
"Scale_in"
);
auto
scale_in_eltwise_data
=
ctx
.
Attr
<
float
>
(
"Scale_in_eltwise"
);
...
...
paddle/fluid/platform/mkldnn_helper.h
浏览文件 @
4f6b43a0
...
...
@@ -205,7 +205,7 @@ inline void AppendKey(std::string* key, const std::vector<int>& dims) {
template
<
typename
...
ArgTypes
>
inline
std
::
string
CreateKey
(
ArgTypes
&&
...
args
)
{
std
::
string
key
;
key
.
reserve
(
256
);
key
.
reserve
(
64
);
using
expand_type
=
int
[];
expand_type
{
0
,
(
AppendKey
(
&
key
,
std
::
forward
<
ArgTypes
>
(
args
)),
0
)...};
return
key
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录