Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
840104c9
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
840104c9
编写于
8月 31, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add NeonDepthwiseConvTransposeFunction.
上级
40d47fae
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
164 addition
and
41 deletion
+164
-41
paddle/function/neon/NeonDepthwiseConv.cpp
paddle/function/neon/NeonDepthwiseConv.cpp
+8
-11
paddle/function/neon/NeonDepthwiseConv.h
paddle/function/neon/NeonDepthwiseConv.h
+32
-30
paddle/function/neon/NeonDepthwiseConvTranspose.cpp
paddle/function/neon/NeonDepthwiseConvTranspose.cpp
+124
-0
未找到文件。
paddle/function/neon/NeonDepthwiseConv.cpp
浏览文件 @
840104c9
...
...
@@ -64,9 +64,10 @@ public:
// padding the input
float
*
inputPadding
=
inputData
;
int
padInputHeight
=
inputHeight
+
2
*
paddingH
();
int
padInputWidth
=
inputWidth
+
2
*
paddingW
();
if
(
paddingH
()
>
0
||
paddingW
()
>
0
)
{
int
newSize
=
batchSize
*
inputChannels
*
(
inputHeight
+
2
*
paddingH
())
*
(
inputWidth
+
2
*
paddingW
());
int
newSize
=
batchSize
*
inputChannels
*
padInputHeight
*
padInputWidth
;
resizeBuffer
<
Device
>
(
newSize
);
inputPadding
=
reinterpret_cast
<
float
*>
(
memory_
->
getBuf
());
neon
::
Padding
<
float
>::
run
(
inputData
,
...
...
@@ -74,12 +75,8 @@ public:
batchSize
*
inputChannels
,
inputHeight
,
inputWidth
,
paddingH
(),
paddingW
());
// height and width of padding data
inputHeight
+=
2
*
paddingH
();
inputWidth
+=
2
*
paddingW
();
padInputHeight
,
padInputWidth
);
}
std
::
function
<
void
(
...
...
@@ -101,14 +98,14 @@ public:
for
(
int
i
=
0
;
i
<
batchSize
;
i
++
)
{
DepthWiseConv
(
inputPadding
,
filterData
,
i
nputHeight
,
i
nputWidth
,
padI
nputHeight
,
padI
nputWidth
,
outputChannels
,
outputHeight
,
outputWidth
,
filterMultiplier
,
outputData
);
inputPadding
+=
inputChannels
*
inputHeight
*
i
nputWidth
;
inputPadding
+=
inputChannels
*
padInputHeight
*
padI
nputWidth
;
outputData
+=
outputChannels
*
outputHeight
*
outputWidth
;
}
}
...
...
paddle/function/neon/NeonDepthwiseConv.h
浏览文件 @
840104c9
...
...
@@ -477,39 +477,40 @@ struct DepthwiseConvKernel<4, 2> {
template
<
class
T
>
struct
Padding
{
static
void
run
(
const
T
*
src
,
T
*
dest
,
static
void
run
(
const
T
*
input
,
T
*
inputPadding
,
int
channels
,
int
inputHeight
,
int
inputWidth
,
int
paddingHeight
,
int
paddingWidth
)
{
const
int
destWidth
=
inputWidth
+
2
*
paddingWidth
;
int
padInputHeight
,
int
padInputWidth
)
{
const
int
paddingHeight
=
(
padInputHeight
-
inputHeight
)
/
2
;
const
int
paddingWidth
=
(
padInputWidth
-
inputWidth
)
/
2
;
for
(
int
c
=
0
;
c
<
channels
;
c
++
)
{
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
des
tWidth
*
paddingHeight
*
sizeof
(
T
));
dest
+=
des
tWidth
*
paddingHeight
;
memset
(
inputPadding
,
0
,
padInpu
tWidth
*
paddingHeight
*
sizeof
(
T
));
inputPadding
+=
padInpu
tWidth
*
paddingHeight
;
}
for
(
int
i
=
0
;
i
<
inputHeight
;
i
++
)
{
// padding head
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
T
(
0
);
*
inputPadding
++
=
T
(
0
);
}
memcpy
(
dest
,
src
,
inputWidth
*
sizeof
(
T
));
dest
+=
inputWidth
;
src
+=
inputWidth
;
memcpy
(
inputPadding
,
input
,
inputWidth
*
sizeof
(
T
));
inputPadding
+=
inputWidth
;
input
+=
inputWidth
;
// padding tail
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
T
(
0
);
*
inputPadding
++
=
T
(
0
);
}
}
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
des
tWidth
*
paddingHeight
*
sizeof
(
T
));
dest
+=
des
tWidth
*
paddingHeight
;
memset
(
inputPadding
,
0
,
padInpu
tWidth
*
paddingHeight
*
sizeof
(
T
));
inputPadding
+=
padInpu
tWidth
*
paddingHeight
;
}
}
}
...
...
@@ -518,47 +519,48 @@ struct Padding {
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
template
<
>
struct
Padding
<
float
>
{
static
void
run
(
const
float
*
src
,
float
*
dest
,
static
void
run
(
const
float
*
input
,
float
*
inputPadding
,
int
channels
,
int
inputHeight
,
int
inputWidth
,
int
paddingHeight
,
int
paddingWidth
)
{
const
int
destWidth
=
inputWidth
+
2
*
paddingWidth
;
int
padInputHeight
,
int
padInputWidth
)
{
const
int
paddingHeight
=
(
padInputHeight
-
inputHeight
)
/
2
;
const
int
paddingWidth
=
(
padInputWidth
-
inputWidth
)
/
2
;
for
(
int
c
=
0
;
c
<
channels
;
c
++
)
{
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
des
tWidth
*
paddingHeight
*
sizeof
(
float
));
dest
+=
des
tWidth
*
paddingHeight
;
memset
(
inputPadding
,
0
,
padInpu
tWidth
*
paddingHeight
*
sizeof
(
float
));
inputPadding
+=
padInpu
tWidth
*
paddingHeight
;
}
for
(
int
i
=
0
;
i
<
inputHeight
;
i
++
)
{
// padding head
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
float
(
0
);
*
inputPadding
++
=
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
;
float32x4_t
s0
=
vld1q_f32
(
input
);
vst1q_f32
(
inputPadding
,
s0
);
input
+=
4
;
inputPadding
+=
4
;
}
for
(
int
r
=
0
;
r
<
remain
;
r
++
)
{
*
dest
++
=
*
src
++
;
*
inputPadding
++
=
*
input
++
;
}
// padding tail
for
(
int
j
=
0
;
j
<
paddingWidth
;
j
++
)
{
*
dest
++
=
float
(
0
);
*
inputPadding
++
=
float
(
0
);
}
}
if
(
paddingHeight
>
0
)
{
memset
(
dest
,
0
,
des
tWidth
*
paddingHeight
*
sizeof
(
float
));
dest
+=
des
tWidth
*
paddingHeight
;
memset
(
inputPadding
,
0
,
padInpu
tWidth
*
paddingHeight
*
sizeof
(
float
));
inputPadding
+=
padInpu
tWidth
*
paddingHeight
;
}
}
}
...
...
paddle/function/neon/NeonDepthwiseConvTranspose.cpp
0 → 100644
浏览文件 @
840104c9
/* 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. */
#include "NeonDepthwiseConv.h"
#include "paddle/function/ConvOp.h"
namespace
paddle
{
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
template
<
DeviceType
Device
>
class
NeonDepthwiseConvTransposeFunction
:
public
ConvFunctionBase
{
public:
void
init
(
const
FuncConfig
&
config
)
override
{
ConvFunctionBase
::
init
(
config
);
}
void
check
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
const
TensorShape
&
input
=
inputs
[
0
].
shape
();
const
TensorShape
&
filter
=
inputs
[
1
].
shape
();
const
TensorShape
&
output
=
outputs
[
0
].
shape
();
checkShape
(
input
,
filter
,
output
);
}
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
CHECK_EQ
(
numInputs_
,
inputs
.
size
());
CHECK_EQ
(
numOutputs_
,
outputs
.
size
());
check
(
inputs
,
outputs
);
const
TensorShape
&
input
=
inputs
[
0
].
shape
();
const
TensorShape
&
filter
=
inputs
[
1
].
shape
();
const
TensorShape
&
output
=
outputs
[
0
].
shape
();
int
batchSize
=
input
[
0
];
int
inputChannels
=
input
[
1
];
int
inputHeight
=
input
[
2
];
int
inputWidth
=
input
[
3
];
int
filterHeight
=
getFilterHeight
(
filter
);
int
filterWidth
=
getFilterWidth
(
filter
);
int
outputChannels
=
output
[
1
];
int
outputHeight
=
output
[
2
];
int
outputWidth
=
output
[
3
];
int
filterMultiplier
=
outputChannels
/
groups_
;
CHECK_EQ
(
inputChannels
,
groups_
);
// only support strideH() == strideW() and filterHeight == filterWidth.
CHECK_EQ
(
strideH
(),
strideW
());
CHECK_EQ
(
paddingH
(),
paddingW
());
CHECK_EQ
(
filterHeight
,
filterWidth
);
float
*
inputData
=
inputs
[
0
].
data
<
float
>
();
float
*
filterData
=
inputs
[
1
].
data
<
float
>
();
float
*
outputData
=
outputs
[
0
].
data
<
float
>
();
// padding the input, input -> inputPadding
float
*
inputPadding
=
inputData
;
int
padInputHeight
=
(
inputHeight
-
1
)
*
strideH
()
+
2
*
filterHeight
-
1
-
2
*
paddingH
();
int
padInputWidth
=
(
inputWidth
-
1
)
*
strideW
()
+
2
*
filterWidth
-
1
-
2
*
paddingW
();
if
(
padInputHeight
>
inputHeight
||
padInputWidth
>
inputWidth
)
{
int
newSize
=
batchSize
*
inputChannels
*
padInputHeight
*
padInputWidth
;
resizeBuffer
<
Device
>
(
newSize
);
inputPadding
=
reinterpret_cast
<
float
*>
(
memory_
->
getBuf
());
neon
::
Padding
<
float
>::
run
(
inputData
,
inputPadding
,
batchSize
*
inputChannels
,
inputHeight
,
inputWidth
,
padInputHeight
,
padInputWidth
);
}
std
::
function
<
void
(
const
float
*
,
const
float
*
,
int
,
int
,
int
,
int
,
int
,
int
,
float
*
)
>
DepthWiseConv
;
if
(
filterWidth
==
3
)
{
DepthWiseConv
=
neon
::
DepthwiseConvKernel
<
3
,
1
>::
run
;
}
else
if
(
filterWidth
==
4
)
{
DepthWiseConv
=
neon
::
DepthwiseConvKernel
<
4
,
1
>::
run
;
}
else
{
LOG
(
FATAL
)
<<
"Not supported"
;
}
for
(
int
i
=
0
;
i
<
batchSize
;
i
++
)
{
DepthWiseConv
(
inputPadding
,
filterData
,
padInputHeight
,
padInputWidth
,
outputChannels
,
outputHeight
,
outputWidth
,
filterMultiplier
,
outputData
);
inputPadding
+=
inputChannels
*
padInputHeight
*
padInputWidth
;
outputData
+=
outputChannels
*
outputHeight
*
outputWidth
;
}
}
};
#ifndef PADDLE_TYPE_DOUBLE
REGISTER_TYPED_FUNC
(
NeonDepthwiseConvTranspose
,
CPU
,
NeonDepthwiseConvTransposeFunction
);
#endif
#endif
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录