Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
b45d020f
P
Paddle
项目概览
wzpei9
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b45d020f
编写于
8月 30, 2017
作者:
H
hedaoyuan
提交者:
GitHub
8月 30, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3718 from hedaoyuan/convolution
Depthwise Convolution Optimization
上级
47eb8691
168707ca
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
750 addition
and
6 deletion
+750
-6
paddle/function/CMakeLists.txt
paddle/function/CMakeLists.txt
+3
-1
paddle/function/DepthwiseConvOpTest.cpp
paddle/function/DepthwiseConvOpTest.cpp
+9
-0
paddle/function/Im2Col.h
paddle/function/Im2Col.h
+92
-0
paddle/function/neon/NeonDepthwiseConv.cpp
paddle/function/neon/NeonDepthwiseConv.cpp
+577
-0
paddle/function/neon/neon_util.h
paddle/function/neon/neon_util.h
+47
-0
paddle/gserver/layers/ExpandConvLayer.cpp
paddle/gserver/layers/ExpandConvLayer.cpp
+22
-5
未找到文件。
paddle/function/CMakeLists.txt
浏览文件 @
b45d020f
...
...
@@ -21,6 +21,8 @@ if(USE_NNPACK)
endif
()
endif
()
list
(
APPEND cpp_files neon/NeonDepthwiseConv.cpp
)
add_library
(
paddle_function STATIC
${
cpp_files
}
${
cu_objs
}
)
add_dependencies
(
paddle_function
${
external_project_dependencies
}
)
add_dependencies
(
paddle_function paddle_proto
)
...
...
@@ -42,11 +44,11 @@ if(WITH_GPU)
add_simple_unittest
(
RowConvOpTest
)
add_simple_unittest
(
BlockExpandOpTest
)
add_simple_unittest
(
CropOpTest
)
add_simple_unittest
(
DepthwiseConvOpTest
)
endif
()
add_simple_unittest
(
Im2ColTest
)
add_simple_unittest
(
GemmConvOpTest
)
add_simple_unittest
(
DepthwiseConvOpTest
)
endif
()
add_style_check_target
(
paddle_function
${
h_files
}
)
...
...
paddle/function/DepthwiseConvOpTest.cpp
浏览文件 @
b45d020f
...
...
@@ -34,4 +34,13 @@ TEST(DepthwiseConv, BackwardFilter) {
}
#endif
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
TEST
(
DepthwiseConv
,
Forward
)
{
DepthwiseConvolution
<
DEVICE_TYPE_CPU
,
DEVICE_TYPE_CPU
>
(
"GemmConv-CPU"
,
"NeonDepthwiseConv-CPU"
,
forward
);
}
#endif
}
// namespace paddle
paddle/function/Im2Col.h
浏览文件 @
b45d020f
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#include "TensorShape.h"
#include "TensorType.h"
#include "neon/neon_util.h"
namespace
paddle
{
...
...
@@ -93,4 +94,95 @@ public:
int
paddingWidth
);
};
template
<
class
T
>
struct
Padding
{
static
void
run
(
const
T
*
src
,
T
*
dest
,
int
channels
,
int
inputHeight
,
int
inputWidth
,
int
paddingHeight
,
int
paddingWidth
)
{
const
int
destWidth
=
inputWidth
+
2
*
paddingWidth
;
for
(
int
c
=
0
;
c
<
channels
;
c
++
)
{
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
destWidth
*
paddingHeight
*
sizeof
(
T
));
dest
+=
destWidth
*
paddingHeight
;
}
for
(
int
i
=
0
;
i
<
inputHeight
;
i
++
)
{
// padding head
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
T
(
0
);
}
memcpy
(
dest
,
src
,
inputWidth
*
sizeof
(
T
));
dest
+=
inputWidth
;
src
+=
inputWidth
;
// padding tail
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
T
(
0
);
}
}
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
destWidth
*
paddingHeight
*
sizeof
(
T
));
dest
+=
destWidth
*
paddingHeight
;
}
}
}
};
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
template
<
>
struct
Padding
<
float
>
{
static
void
run
(
const
float
*
src
,
float
*
dest
,
int
channels
,
int
inputHeight
,
int
inputWidth
,
int
paddingHeight
,
int
paddingWidth
)
{
const
int
destWidth
=
inputWidth
+
2
*
paddingWidth
;
for
(
int
c
=
0
;
c
<
channels
;
c
++
)
{
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
destWidth
*
paddingHeight
*
sizeof
(
float
));
dest
+=
destWidth
*
paddingHeight
;
}
for
(
int
i
=
0
;
i
<
inputHeight
;
i
++
)
{
// padding head
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
float
(
0
);
}
int
step
=
inputWidth
>>
2
;
int
remain
=
inputWidth
&
3
;
for
(
int
s
=
0
;
s
<
step
;
s
++
)
{
float32x4_t
s0
=
vld1q_f32
(
src
);
vst1q_f32
(
dest
,
s0
);
src
+=
4
;
dest
+=
4
;
}
for
(
int
r
=
0
;
r
<
remain
;
r
++
)
{
*
dest
++
=
*
src
++
;
}
// padding tail
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
float
(
0
);
}
}
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
destWidth
*
paddingHeight
*
sizeof
(
float
));
dest
+=
destWidth
*
paddingHeight
;
}
}
}
};
#endif
}
// namespace paddle
paddle/function/neon/NeonDepthwiseConv.cpp
0 → 100644
浏览文件 @
b45d020f
此差异已折叠。
点击以展开。
paddle/function/neon/neon_util.h
0 → 100644
浏览文件 @
b45d020f
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
#include <arm_neon.h>
namespace
paddle
{
namespace
neon
{
inline
float32x4_t
vld1q_f32_aligned
(
const
float
*
p
)
{
return
vld1q_f32
(
(
const
float
*
)
__builtin_assume_aligned
(
p
,
sizeof
(
float32x4_t
)));
}
#ifndef __aarch64__
inline
float32_t
vaddvq_f32
(
float32x4_t
a
)
{
float32x2_t
v
=
vadd_f32
(
vget_high_f32
(
a
),
vget_low_f32
(
a
));
return
vget_lane_f32
(
vpadd_f32
(
v
,
v
),
0
);
}
inline
float32x4_t
vmlaq_laneq_f32
(
float32x4_t
a
,
float32x4_t
b
,
float32x4_t
v
,
const
int
lane
)
{
return
vmlaq_n_f32
(
a
,
b
,
vgetq_lane_f32
(
v
,
lane
));
}
#endif
}
// namespace neon
}
// namespace paddle
#endif
paddle/gserver/layers/ExpandConvLayer.cpp
浏览文件 @
b45d020f
...
...
@@ -29,6 +29,10 @@ namespace paddle {
REGISTER_LAYER
(
exconv
,
ExpandConvLayer
);
REGISTER_LAYER
(
exconvt
,
ExpandConvLayer
);
inline
bool
isDepthwiseConv
(
int
channels
,
int
groups
)
{
return
channels
==
groups
;
}
bool
ExpandConvLayer
::
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
{
/* Initialize the basic convolutional parent class */
...
...
@@ -47,14 +51,27 @@ bool ExpandConvLayer::init(const LayerMap &layerMap,
std
::
vector
<
size_t
>
paddings
=
{(
size_t
)
paddingY_
[
i
],
(
size_t
)
padding_
[
i
]};
std
::
vector
<
size_t
>
strides
=
{(
size_t
)
strideY_
[
i
],
(
size_t
)
stride_
[
i
]};
if
(
useGpu_
&&
(
size_t
)
groups_
[
i
]
==
(
size_t
)
channels_
[
i
]
&&
!
isDeconv_
)
{
// Convolution Layer uses the GemmConv function by default.
convType
=
"GemmConv"
;
convGradInputType
=
"GemmConvGradInput"
;
convGradFilterType
=
"GemmConvGradFilter"
;
// If depth wise convolution and useGpu == true
if
(
useGpu_
&&
isDepthwiseConv
(
channels_
[
i
],
groups_
[
i
])
&&
!
isDeconv_
)
{
convType
=
"DepthwiseConv"
;
convGradInputType
=
"DepthwiseConvGradInput"
;
convGradFilterType
=
"DepthwiseConvGradFilter"
;
}
else
{
convType
=
"GemmConv"
;
convGradInputType
=
"GemmConvGradInput"
;
convGradFilterType
=
"GemmConvGradFilter"
;
}
// If depth wise convolution and useGpu == false and ARM-NEON
if
(
!
useGpu_
&&
isDepthwiseConv
(
channels_
[
i
],
groups_
[
i
])
&&
!
isDeconv_
)
{
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
if
((
filterSize_
[
i
]
==
filterSizeY_
[
i
])
&&
(
filterSize_
[
i
]
==
3
||
filterSize_
[
i
]
==
4
)
&&
(
stride_
[
i
]
==
strideY_
[
i
])
&&
(
stride_
[
i
]
==
1
||
stride_
[
i
]
==
2
))
{
convType
=
"NeonDepthwiseConv"
;
}
#endif
}
if
(
FLAGS_use_nnpack
&&
!
isDeconv_
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录