Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
09adb769
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
09adb769
编写于
1月 17, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix code style
上级
bfe7e242
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
22 deletion
+25
-22
paddle/operators/block_expand_op.cc
paddle/operators/block_expand_op.cc
+10
-11
paddle/operators/block_expand_op.cu
paddle/operators/block_expand_op.cu
+5
-4
paddle/operators/block_expand_op.h
paddle/operators/block_expand_op.h
+10
-7
未找到文件。
paddle/operators/block_expand_op.cc
浏览文件 @
09adb769
...
...
@@ -57,16 +57,14 @@ class BlockExpandOp : public framework::OperatorWithKernel {
class
BlockExpandOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
BlockExpandOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
BlockExpandOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
R"DOC(
(Tensor)The input tensor has NCHW format.
N: batch size
C: channels
H: height
W: width
)DOC"
);
AddInput
(
"X"
,
"(Tensor)The input tensor has NCHW format."
"N: batch size"
"C: channels"
"H: height"
"W: width"
);
AddOutput
(
"Out"
,
"(LodTensor)The output data of block_expand op,"
);
AddAttr
<
int
>
(
"block_height"
,
"(int)height of block."
);
AddAttr
<
int
>
(
"block_width"
,
"(int)width of block."
);
...
...
@@ -155,7 +153,8 @@ namespace ops = paddle::operators;
REGISTER_OP
(
block_expand
,
ops
::
BlockExpandOp
,
ops
::
BlockExpandOpMaker
,
block_expand_grad
,
ops
::
BlockExpandGradOp
);
REGISTER_OP_CPU_KERNEL
(
block_expand
,
ops
::
BlockExpandKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
block_expand
,
ops
::
BlockExpandKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
REGISTER_OP_CPU_KERNEL
(
block_expand_grad
,
ops
::
BlockExpandGradKernel
<
paddle
::
platform
::
CPU
Place
,
float
>
);
ops
::
BlockExpandGradKernel
<
paddle
::
platform
::
CPU
DeviceContext
,
float
>
);
paddle/operators/block_expand_op.cu
浏览文件 @
09adb769
...
...
@@ -17,8 +17,9 @@
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_GPU_KERNEL
(
block_expand
,
ops
::
BlockExpandKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
REGISTER_OP_GPU_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
block_expand
,
ops
::
BlockExpandKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
REGISTER_OP_CUDA_KERNEL
(
block_expand_grad
,
ops
::
BlockExpandGradKernel
<
paddle
::
platform
::
GPUPlace
,
float
>
);
ops
::
BlockExpandGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
paddle/operators/block_expand_op.h
浏览文件 @
09adb769
...
...
@@ -31,7 +31,7 @@ inline int get_output_size(int img_size, int block_size, int stride,
return
(
1
+
(
img_size
+
2
*
padding
-
block_size
+
stride
-
1
)
/
stride
);
}
template
<
typename
Place
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
class
BlockExpandKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -71,8 +71,9 @@ class BlockExpandKernel : public framework::OpKernel<T> {
img_channels
,
block_height
,
block_width
});
math
::
Im2ColFunctor
<
math
::
ColFormat
::
kOCF
,
Place
,
T
>
f
;
f
(
ctx
.
device_context
(),
src
,
dilations
,
strides
,
paddings
,
&
dst
);
math
::
Im2ColFunctor
<
math
::
ColFormat
::
kOCF
,
DeviceContext
,
T
>
f
;
auto
&
dev_ctx
=
ctx
.
template
device_context
<
DeviceContext
>();
f
(
dev_ctx
,
src
,
dilations
,
strides
,
paddings
,
&
dst
);
}
out
->
Resize
(
out_dims
);
...
...
@@ -87,7 +88,7 @@ class BlockExpandKernel : public framework::OpKernel<T> {
}
};
template
<
typename
Place
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
class
BlockExpandGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
...
...
@@ -98,7 +99,8 @@ class BlockExpandGradKernel : public framework::OpKernel<T> {
d_x
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
x_v
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
d_x
);
x_v
.
device
(
ctx
.
GetEigenDevice
<
Place
>
())
=
x_v
.
constant
(
0.0
);
auto
&
place
=
*
ctx
.
template
device_context
<
DeviceContext
>().
eigen_device
();
x_v
.
device
(
place
)
=
x_v
.
constant
(
0.0
);
auto
in_dim
=
in
->
dims
();
int
batch_size
=
in_dim
[
0
];
...
...
@@ -131,8 +133,9 @@ class BlockExpandGradKernel : public framework::OpKernel<T> {
const
Tensor
src
=
d_out
->
Slice
(
i
,
i
+
1
).
Resize
(
{
output_height
,
output_width
,
img_channels
,
block_height
,
block_width
});
math
::
Col2ImFunctor
<
math
::
ColFormat
::
kOCF
,
Place
,
T
>
f
;
f
(
ctx
.
device_context
(),
src
,
dilations
,
strides
,
paddings
,
&
dst
);
math
::
Col2ImFunctor
<
math
::
ColFormat
::
kOCF
,
DeviceContext
,
T
>
f
;
auto
&
dev_ctx
=
ctx
.
template
device_context
<
DeviceContext
>();
f
(
dev_ctx
,
src
,
dilations
,
strides
,
paddings
,
&
dst
);
}
d_out
->
Resize
(
d_out_dims
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录