Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b83ff451
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
b83ff451
编写于
1月 18, 2018
作者:
G
guosheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Register reduce_op_kernel with multiple data types
上级
c73f00fe
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
33 addition
and
9 deletion
+33
-9
paddle/operators/reduce_op.cc
paddle/operators/reduce_op.cc
+13
-1
paddle/operators/reduce_op.cu
paddle/operators/reduce_op.cu
+13
-1
python/paddle/v2/fluid/tests/test_reduce_op.py
python/paddle/v2/fluid/tests/test_reduce_op.py
+7
-7
未找到文件。
paddle/operators/reduce_op.cc
浏览文件 @
b83ff451
...
@@ -190,10 +190,22 @@ REGISTER_OP(reduce_min, ops::ReduceOp, ops::ReduceMinOpMaker, reduce_min_grad,
...
@@ -190,10 +190,22 @@ REGISTER_OP(reduce_min, ops::ReduceOp, ops::ReduceMinOpMaker, reduce_min_grad,
#define REGISTER_REDUCE_CPU_KERNEL(reduce_type, functor, grad_functor) \
#define REGISTER_REDUCE_CPU_KERNEL(reduce_type, functor, grad_functor) \
REGISTER_OP_CPU_KERNEL(reduce_type, \
REGISTER_OP_CPU_KERNEL(reduce_type, \
ops::ReduceKernel<paddle::platform::CPUDeviceContext, \
ops::ReduceKernel<paddle::platform::CPUDeviceContext, \
float, ops::functor>); \
float, ops::functor>, \
ops::ReduceKernel<paddle::platform::CPUDeviceContext, \
double, ops::functor>, \
ops::ReduceKernel<paddle::platform::CPUDeviceContext, \
int, ops::functor>, \
ops::ReduceKernel<paddle::platform::CPUDeviceContext, \
int64_t, ops::functor>); \
REGISTER_OP_CPU_KERNEL( \
REGISTER_OP_CPU_KERNEL( \
reduce_type##_grad, \
reduce_type##_grad, \
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, float, \
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, float, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, double, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CPUDeviceContext, int64_t, \
ops::grad_functor>);
ops::grad_functor>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_REDUCE_CPU_KERNEL
);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_REDUCE_CPU_KERNEL
);
paddle/operators/reduce_op.cu
浏览文件 @
b83ff451
...
@@ -20,10 +20,22 @@ namespace ops = paddle::operators;
...
@@ -20,10 +20,22 @@ namespace ops = paddle::operators;
#define REGISTER_REDUCE_GPU_KERNEL(reduce_type, functor, grad_functor) \
#define REGISTER_REDUCE_GPU_KERNEL(reduce_type, functor, grad_functor) \
REGISTER_OP_CUDA_KERNEL( \
REGISTER_OP_CUDA_KERNEL( \
reduce_type, ops::ReduceKernel<paddle::platform::CUDADeviceContext, \
reduce_type, ops::ReduceKernel<paddle::platform::CUDADeviceContext, \
float, ops::functor>); \
float, ops::functor>, \
ops::ReduceKernel<paddle::platform::CUDADeviceContext, double, \
ops::functor>, \
ops::ReduceKernel<paddle::platform::CUDADeviceContext, int, \
ops::functor>, \
ops::ReduceKernel<paddle::platform::CUDADeviceContext, int64_t, \
ops::functor>); \
REGISTER_OP_CUDA_KERNEL( \
REGISTER_OP_CUDA_KERNEL( \
reduce_type##_grad, \
reduce_type##_grad, \
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, float, \
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, float, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, double, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int, \
ops::grad_functor>, \
ops::ReduceGradKernel<paddle::platform::CUDADeviceContext, int64_t, \
ops::grad_functor>);
ops::grad_functor>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_REDUCE_GPU_KERNEL
);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_REDUCE_GPU_KERNEL
);
python/paddle/v2/fluid/tests/test_reduce_op.py
浏览文件 @
b83ff451
...
@@ -19,7 +19,7 @@ from op_test import OpTest
...
@@ -19,7 +19,7 @@ from op_test import OpTest
class
TestSumOp
(
OpTest
):
class
TestSumOp
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_sum"
self
.
op_type
=
"reduce_sum"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
64
"
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
0
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
0
)}
def
test_check_output
(
self
):
def
test_check_output
(
self
):
...
@@ -32,7 +32,7 @@ class TestSumOp(OpTest):
...
@@ -32,7 +32,7 @@ class TestSumOp(OpTest):
class
TestMeanOp
(
OpTest
):
class
TestMeanOp
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_mean"
self
.
op_type
=
"reduce_mean"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
2
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
2
,
10
)).
astype
(
"float
64
"
)}
self
.
attrs
=
{
'dim'
:
1
}
self
.
attrs
=
{
'dim'
:
1
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
mean
(
axis
=
self
.
attrs
[
'dim'
])}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
mean
(
axis
=
self
.
attrs
[
'dim'
])}
...
@@ -48,7 +48,7 @@ class TestMaxOp(OpTest):
...
@@ -48,7 +48,7 @@ class TestMaxOp(OpTest):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_max"
self
.
op_type
=
"reduce_max"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
64
"
)}
self
.
attrs
=
{
'dim'
:
-
1
}
self
.
attrs
=
{
'dim'
:
-
1
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
max
(
axis
=
self
.
attrs
[
'dim'
])}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
max
(
axis
=
self
.
attrs
[
'dim'
])}
...
@@ -61,7 +61,7 @@ class TestMinOp(OpTest):
...
@@ -61,7 +61,7 @@ class TestMinOp(OpTest):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_min"
self
.
op_type
=
"reduce_min"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
64
"
)}
self
.
attrs
=
{
'dim'
:
2
}
self
.
attrs
=
{
'dim'
:
2
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
min
(
axis
=
self
.
attrs
[
'dim'
])}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
min
(
axis
=
self
.
attrs
[
'dim'
])}
...
@@ -72,7 +72,7 @@ class TestMinOp(OpTest):
...
@@ -72,7 +72,7 @@ class TestMinOp(OpTest):
class
TestKeepDimReduce
(
OpTest
):
class
TestKeepDimReduce
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_sum"
self
.
op_type
=
"reduce_sum"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
10
)).
astype
(
"float
64
"
)}
self
.
attrs
=
{
'dim'
:
-
2
,
'keep_dim'
:
True
}
self
.
attrs
=
{
'dim'
:
-
2
,
'keep_dim'
:
True
}
self
.
outputs
=
{
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
self
.
attrs
[
'dim'
],
keepdims
=
True
)
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
self
.
attrs
[
'dim'
],
keepdims
=
True
)
...
@@ -88,7 +88,7 @@ class TestKeepDimReduce(OpTest):
...
@@ -88,7 +88,7 @@ class TestKeepDimReduce(OpTest):
class
Test1DReduce
(
OpTest
):
class
Test1DReduce
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_sum"
self
.
op_type
=
"reduce_sum"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
(
20
).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
(
20
).
astype
(
"float
64
"
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
0
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
(
axis
=
0
)}
def
test_check_output
(
self
):
def
test_check_output
(
self
):
...
@@ -101,7 +101,7 @@ class Test1DReduce(OpTest):
...
@@ -101,7 +101,7 @@ class Test1DReduce(OpTest):
class
TestReduceAll
(
OpTest
):
class
TestReduceAll
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_sum"
self
.
op_type
=
"reduce_sum"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
2
,
10
)).
astype
(
"float
32
"
)}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
5
,
6
,
2
,
10
)).
astype
(
"float
64
"
)}
self
.
attrs
=
{
'reduce_all'
:
True
}
self
.
attrs
=
{
'reduce_all'
:
True
}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
()}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
sum
()}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录