Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
728d6d1a
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
728d6d1a
编写于
7月 17, 2019
作者:
Y
Yanzhan Yang
提交者:
StarryRain
7月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fuse conv add batch relu when using faster depthwise conv (#1749)
上级
83fa6f82
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
79 addition
and
51 deletion
+79
-51
src/operators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
...rators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
+50
-3
src/operators/kernel/central-arm-func/conv_arm_func.cpp
src/operators/kernel/central-arm-func/conv_arm_func.cpp
+23
-48
src/operators/kernel/central-arm-func/conv_arm_func.h
src/operators/kernel/central-arm-func/conv_arm_func.h
+3
-0
src/operators/kernel/conv_add_bn_relu_kernel.h
src/operators/kernel/conv_add_bn_relu_kernel.h
+3
-0
未找到文件。
src/operators/kernel/arm/convolution/conv_add_bn_relu_kernel.cpp
浏览文件 @
728d6d1a
...
@@ -61,16 +61,61 @@ bool ConvAddBNReluKernel<CPU, float>::Init(
...
@@ -61,16 +61,61 @@ bool ConvAddBNReluKernel<CPU, float>::Init(
param
->
SetNewBias
(
new_bias
);
param
->
SetNewBias
(
new_bias
);
InitBaseConvKernel
(
param
);
InitBaseConvKernel
(
param
);
// try to use faster depthwise conv
switch
(
param
->
ExecMode
())
{
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2_FLOAT
:
const
std
::
vector
<
int
>
&
paddings
=
param
->
Paddings
();
const
std
::
vector
<
int
>
&
strides
=
param
->
Strides
();
if
(
paddings
.
size
()
==
2
&&
paddings
[
0
]
==
paddings
[
1
]
&&
strides
.
size
()
==
2
&&
strides
[
0
]
==
strides
[
1
])
{
int
pad
=
paddings
[
0
];
int
stride
=
strides
[
0
];
const
int
hin
=
param
->
Input
()
->
dims
()[
2
];
if
(
pad
==
0
&&
hin
>
2
)
{
could_use_faster_depthwise_conv_
=
true
;
}
else
if
(
pad
==
1
)
{
could_use_faster_depthwise_conv_
=
true
;
}
}
break
;
}
if
(
could_use_faster_depthwise_conv_
)
{
auto
filter_data
=
param
->
Filter
()
->
data
<
float
>
();
auto
filter_dim
=
param
->
Filter
()
->
dims
();
int
len
=
1
;
for
(
int
i
=
0
;
i
<
filter_dim
.
size
();
i
++
)
{
len
*=
filter_dim
[
i
];
}
int
batch
=
filter_dim
[
0
];
int
step
=
len
/
batch
;
for
(
int
i
=
0
;
i
<
batch
;
i
++
)
{
for
(
int
k
=
0
;
k
<
step
;
k
++
)
{
filter_data
[
i
*
step
+
k
]
=
filter_data
[
i
*
step
+
k
]
*
new_scale_ptr
[
i
];
}
}
}
return
true
;
return
true
;
}
}
template
<
>
template
<
>
void
ConvAddBNReluKernel
<
CPU
,
float
>::
Compute
(
void
ConvAddBNReluKernel
<
CPU
,
float
>::
Compute
(
const
FusionConvAddBNReluParam
<
CPU
>
&
param
)
{
const
FusionConvAddBNReluParam
<
CPU
>
&
param
)
{
bool
fusion_has_been_computed
=
false
;
switch
(
param
.
ExecMode
())
{
switch
(
param
.
ExecMode
())
{
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2_FLOAT
:
if
(
could_use_faster_depthwise_conv_
)
{
FasterDepthwiseConv3x3_bias_relu
(
param
,
param
.
NewBias
()
->
data
<
float
>
(),
true
);
fusion_has_been_computed
=
true
;
}
else
{
DepthwiseConv3x3
<
float
,
float
>
(
param
);
DepthwiseConv3x3
<
float
,
float
>
(
param
);
}
break
;
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_FLOAT
:
DepthwiseConv5x5
<
float
,
float
>
(
param
);
DepthwiseConv5x5
<
float
,
float
>
(
param
);
...
@@ -89,8 +134,10 @@ void ConvAddBNReluKernel<CPU, float>::Compute(
...
@@ -89,8 +134,10 @@ void ConvAddBNReluKernel<CPU, float>::Compute(
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid convolution execute mode %d"
,
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid convolution execute mode %d"
,
param
.
ExecMode
());
param
.
ExecMode
());
}
}
if
(
!
fusion_has_been_computed
)
{
math
::
ScaleAddChannelWise
<
RELU
>
(
param
.
Output
(),
param
.
NewScale
(),
math
::
ScaleAddChannelWise
<
RELU
>
(
param
.
Output
(),
param
.
NewScale
(),
param
.
NewBias
(),
param
.
Output
());
param
.
NewBias
(),
param
.
Output
());
}
}
}
template
class
ConvAddBNReluKernel
<
CPU
,
float
>;
template
class
ConvAddBNReluKernel
<
CPU
,
float
>;
...
...
src/operators/kernel/central-arm-func/conv_arm_func.cpp
浏览文件 @
728d6d1a
...
@@ -212,8 +212,8 @@ void DepthwiseConv3x3(const ConvParam<CPU> ¶m) {
...
@@ -212,8 +212,8 @@ void DepthwiseConv3x3(const ConvParam<CPU> ¶m) {
}
}
}
}
template
<
>
void
FasterDepthwiseConv3x3_bias_relu
(
const
ConvParam
<
CPU
>
&
param
,
void
DepthwiseConv3x3
<
float
,
float
>
(
const
ConvParam
<
CPU
>
&
param
)
{
const
float
*
bias
,
bool
flag_relu
)
{
const
Tensor
*
input
=
param
.
Input
();
const
Tensor
*
input
=
param
.
Input
();
const
Tensor
*
filter
=
param
.
Filter
();
const
Tensor
*
filter
=
param
.
Filter
();
const
std
::
vector
<
int
>
&
paddings
=
param
.
Paddings
();
const
std
::
vector
<
int
>
&
paddings
=
param
.
Paddings
();
...
@@ -222,14 +222,11 @@ void DepthwiseConv3x3<float, float>(const ConvParam<CPU> ¶m) {
...
@@ -222,14 +222,11 @@ void DepthwiseConv3x3<float, float>(const ConvParam<CPU> ¶m) {
Tensor
*
output
=
param
.
Output
();
Tensor
*
output
=
param
.
Output
();
output
->
mutable_data
<
float
>
();
output
->
mutable_data
<
float
>
();
if
(
paddings
.
size
()
==
2
&&
paddings
[
0
]
==
paddings
[
1
]
&&
strides
.
size
()
==
2
&&
strides
[
0
]
==
strides
[
1
])
{
int
pad
=
paddings
[
0
];
int
pad
=
paddings
[
0
];
int
stride
=
strides
[
0
];
int
stride
=
strides
[
0
];
const
float
*
din
=
input
->
data
<
float
>
();
const
float
*
din
=
input
->
data
<
float
>
();
float
*
dout
=
output
->
mutable_data
<
float
>
();
float
*
dout
=
output
->
mutable_data
<
float
>
();
const
float
*
weights
=
filter
->
data
<
float
>
();
const
float
*
weights
=
filter
->
data
<
float
>
();
const
float
*
bias
=
nullptr
;
const
int
num
=
input
->
dims
()[
0
];
const
int
num
=
input
->
dims
()[
0
];
const
int
chin
=
input
->
dims
()[
1
];
const
int
chin
=
input
->
dims
()[
1
];
const
int
hin
=
input
->
dims
()[
2
];
const
int
hin
=
input
->
dims
()[
2
];
...
@@ -237,37 +234,15 @@ void DepthwiseConv3x3<float, float>(const ConvParam<CPU> ¶m) {
...
@@ -237,37 +234,15 @@ void DepthwiseConv3x3<float, float>(const ConvParam<CPU> ¶m) {
const
int
chout
=
output
->
dims
()[
1
];
const
int
chout
=
output
->
dims
()[
1
];
const
int
hout
=
output
->
dims
()[
2
];
const
int
hout
=
output
->
dims
()[
2
];
const
int
wout
=
output
->
dims
()[
3
];
const
int
wout
=
output
->
dims
()[
3
];
bool
flag_relu
=
false
;
bool
flag_bias
=
bias
!=
nullptr
;
bool
flag_bias
=
bias
!=
nullptr
;
if
(
pad
==
0
&&
hin
>
2
)
{
if
(
pad
==
0
&&
hin
>
2
)
{
math
::
depthwise
::
conv_depthwise_3x3p0
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
math
::
depthwise
::
conv_depthwise_3x3p0
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
stride
,
flag_bias
,
flag_relu
);
flag_bias
,
flag_relu
);
}
else
if
(
pad
==
1
)
{
}
else
if
(
pad
==
1
)
{
math
::
depthwise
::
conv_depthwise_3x3p1
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
math
::
depthwise
::
conv_depthwise_3x3p1
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
stride
,
flag_bias
,
flag_relu
);
flag_bias
,
flag_relu
);
}
else
{
GemmConv
<
float
,
float
>
(
param
);
}
}
else
{
if
(
strides
[
0
]
==
1
)
{
for
(
int
i
=
0
;
i
<
batch_size
;
i
++
)
{
Tensor
in_batch
=
input
->
Slice
(
i
,
i
+
1
);
Tensor
out_batch
=
output
->
Slice
(
i
,
i
+
1
);
math
::
DepthwiseConv3x3S1
<
float
,
float
>
(
in_batch
,
*
filter
,
paddings
,
&
out_batch
);
}
}
else
if
(
strides
[
0
]
==
2
)
{
for
(
int
i
=
0
;
i
<
batch_size
;
i
++
)
{
Tensor
in_batch
=
input
->
Slice
(
i
,
i
+
1
);
Tensor
out_batch
=
output
->
Slice
(
i
,
i
+
1
);
math
::
DepthwiseConv3x3S2
<
float
,
float
>
(
in_batch
,
*
filter
,
paddings
,
&
out_batch
);
}
}
else
{
GemmConv
<
float
,
float
>
(
param
);
}
}
}
}
}
...
...
src/operators/kernel/central-arm-func/conv_arm_func.h
浏览文件 @
728d6d1a
...
@@ -44,6 +44,9 @@ void DepthwiseConv5x5(const ConvParam<CPU> ¶m);
...
@@ -44,6 +44,9 @@ void DepthwiseConv5x5(const ConvParam<CPU> ¶m);
template
<
typename
Itype
,
typename
Otype
>
template
<
typename
Itype
,
typename
Otype
>
void
SlidingwindowConv3x3
(
const
ConvParam
<
CPU
>
&
param
);
void
SlidingwindowConv3x3
(
const
ConvParam
<
CPU
>
&
param
);
void
FasterDepthwiseConv3x3_bias_relu
(
const
ConvParam
<
CPU
>
&
param
,
const
float
*
bias
,
bool
flag_relu
);
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
}
// namespace paddle_mobile
...
...
src/operators/kernel/conv_add_bn_relu_kernel.h
浏览文件 @
728d6d1a
...
@@ -36,6 +36,9 @@ class ConvAddBNReluKernel
...
@@ -36,6 +36,9 @@ class ConvAddBNReluKernel
public:
public:
void
Compute
(
const
FusionConvAddBNReluParam
<
DeviceType
>
&
param
);
void
Compute
(
const
FusionConvAddBNReluParam
<
DeviceType
>
&
param
);
bool
Init
(
FusionConvAddBNReluParam
<
DeviceType
>
*
param
);
bool
Init
(
FusionConvAddBNReluParam
<
DeviceType
>
*
param
);
private:
bool
could_use_faster_depthwise_conv_
=
false
;
};
};
}
// namespace operators
}
// namespace operators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录