Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
497bf326
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看板
提交
497bf326
编写于
7月 17, 2019
作者:
Y
Yanzhan Yang
提交者:
StarryRain
7月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fuse conv add batch relu when using faster depthwise conv (#1749)
上级
b42f3d49
变更
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
浏览文件 @
497bf326
...
...
@@ -61,16 +61,61 @@ bool ConvAddBNReluKernel<CPU, float>::Init(
param
->
SetNewBias
(
new_bias
);
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
;
}
template
<
>
void
ConvAddBNReluKernel
<
CPU
,
float
>::
Compute
(
const
FusionConvAddBNReluParam
<
CPU
>
&
param
)
{
bool
fusion_has_been_computed
=
false
;
switch
(
param
.
ExecMode
())
{
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S1_FLOAT
:
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE3x3S2_FLOAT
:
DepthwiseConv3x3
<
float
,
float
>
(
param
);
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
);
}
break
;
case
ConvParam
<
CPU
>::
EXEC_DEPTHWISE5x5_FLOAT
:
DepthwiseConv5x5
<
float
,
float
>
(
param
);
...
...
@@ -89,8 +134,10 @@ void ConvAddBNReluKernel<CPU, float>::Compute(
PADDLE_MOBILE_THROW_EXCEPTION
(
"Invalid convolution execute mode %d"
,
param
.
ExecMode
());
}
math
::
ScaleAddChannelWise
<
RELU
>
(
param
.
Output
(),
param
.
NewScale
(),
param
.
NewBias
(),
param
.
Output
());
if
(
!
fusion_has_been_computed
)
{
math
::
ScaleAddChannelWise
<
RELU
>
(
param
.
Output
(),
param
.
NewScale
(),
param
.
NewBias
(),
param
.
Output
());
}
}
template
class
ConvAddBNReluKernel
<
CPU
,
float
>;
...
...
src/operators/kernel/central-arm-func/conv_arm_func.cpp
浏览文件 @
497bf326
...
...
@@ -212,8 +212,8 @@ void DepthwiseConv3x3(const ConvParam<CPU> ¶m) {
}
}
template
<
>
void
DepthwiseConv3x3
<
float
,
float
>
(
const
ConvParam
<
CPU
>
&
param
)
{
void
FasterDepthwiseConv3x3_bias_relu
(
const
ConvParam
<
CPU
>
&
param
,
const
float
*
bias
,
bool
flag_relu
)
{
const
Tensor
*
input
=
param
.
Input
();
const
Tensor
*
filter
=
param
.
Filter
();
const
std
::
vector
<
int
>
&
paddings
=
param
.
Paddings
();
...
...
@@ -222,52 +222,27 @@ void DepthwiseConv3x3<float, float>(const ConvParam<CPU> ¶m) {
Tensor
*
output
=
param
.
Output
();
output
->
mutable_data
<
float
>
();
if
(
paddings
.
size
()
==
2
&&
paddings
[
0
]
==
paddings
[
1
]
&&
strides
.
size
()
==
2
&&
strides
[
0
]
==
strides
[
1
])
{
int
pad
=
paddings
[
0
];
int
stride
=
strides
[
0
];
const
float
*
din
=
input
->
data
<
float
>
();
float
*
dout
=
output
->
mutable_data
<
float
>
();
const
float
*
weights
=
filter
->
data
<
float
>
();
const
float
*
bias
=
nullptr
;
const
int
num
=
input
->
dims
()[
0
];
const
int
chin
=
input
->
dims
()[
1
];
const
int
hin
=
input
->
dims
()[
2
];
const
int
win
=
input
->
dims
()[
3
];
const
int
chout
=
output
->
dims
()[
1
];
const
int
hout
=
output
->
dims
()[
2
];
const
int
wout
=
output
->
dims
()[
3
];
bool
flag_relu
=
false
;
bool
flag_bias
=
bias
!=
nullptr
;
if
(
pad
==
0
&&
hin
>
2
)
{
math
::
depthwise
::
conv_depthwise_3x3p0
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
flag_bias
,
flag_relu
);
}
else
if
(
pad
==
1
)
{
math
::
depthwise
::
conv_depthwise_3x3p1
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
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
);
}
int
pad
=
paddings
[
0
];
int
stride
=
strides
[
0
];
const
float
*
din
=
input
->
data
<
float
>
();
float
*
dout
=
output
->
mutable_data
<
float
>
();
const
float
*
weights
=
filter
->
data
<
float
>
();
const
int
num
=
input
->
dims
()[
0
];
const
int
chin
=
input
->
dims
()[
1
];
const
int
hin
=
input
->
dims
()[
2
];
const
int
win
=
input
->
dims
()[
3
];
const
int
chout
=
output
->
dims
()[
1
];
const
int
hout
=
output
->
dims
()[
2
];
const
int
wout
=
output
->
dims
()[
3
];
bool
flag_bias
=
bias
!=
nullptr
;
if
(
pad
==
0
&&
hin
>
2
)
{
math
::
depthwise
::
conv_depthwise_3x3p0
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
flag_bias
,
flag_relu
);
}
else
if
(
pad
==
1
)
{
math
::
depthwise
::
conv_depthwise_3x3p1
(
din
,
dout
,
num
,
chout
,
hout
,
wout
,
chin
,
hin
,
win
,
weights
,
bias
,
stride
,
flag_bias
,
flag_relu
);
}
}
...
...
src/operators/kernel/central-arm-func/conv_arm_func.h
浏览文件 @
497bf326
...
...
@@ -44,6 +44,9 @@ void DepthwiseConv5x5(const ConvParam<CPU> ¶m);
template
<
typename
Itype
,
typename
Otype
>
void
SlidingwindowConv3x3
(
const
ConvParam
<
CPU
>
&
param
);
void
FasterDepthwiseConv3x3_bias_relu
(
const
ConvParam
<
CPU
>
&
param
,
const
float
*
bias
,
bool
flag_relu
);
}
// namespace operators
}
// namespace paddle_mobile
...
...
src/operators/kernel/conv_add_bn_relu_kernel.h
浏览文件 @
497bf326
...
...
@@ -36,6 +36,9 @@ class ConvAddBNReluKernel
public:
void
Compute
(
const
FusionConvAddBNReluParam
<
DeviceType
>
&
param
);
bool
Init
(
FusionConvAddBNReluParam
<
DeviceType
>
*
param
);
private:
bool
could_use_faster_depthwise_conv_
=
false
;
};
}
// namespace operators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录