From b83ff4514b2bbdce5ec2ba76f8205307c874c574 Mon Sep 17 00:00:00 2001 From: guosheng Date: Thu, 18 Jan 2018 17:52:26 +0800 Subject: [PATCH] Register reduce_op_kernel with multiple data types --- paddle/operators/reduce_op.cc | 14 +++++++++++++- paddle/operators/reduce_op.cu | 14 +++++++++++++- python/paddle/v2/fluid/tests/test_reduce_op.py | 14 +++++++------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/paddle/operators/reduce_op.cc b/paddle/operators/reduce_op.cc index 09b7091358..4a06babeda 100644 --- a/paddle/operators/reduce_op.cc +++ b/paddle/operators/reduce_op.cc @@ -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) \ REGISTER_OP_CPU_KERNEL(reduce_type, \ ops::ReduceKernel); \ + float, ops::functor>, \ + ops::ReduceKernel, \ + ops::ReduceKernel, \ + ops::ReduceKernel); \ REGISTER_OP_CPU_KERNEL( \ reduce_type##_grad, \ ops::ReduceGradKernel, \ + ops::ReduceGradKernel, \ + ops::ReduceGradKernel, \ + ops::ReduceGradKernel); FOR_EACH_KERNEL_FUNCTOR(REGISTER_REDUCE_CPU_KERNEL); diff --git a/paddle/operators/reduce_op.cu b/paddle/operators/reduce_op.cu index 1dd948ed8a..4ed1e051db 100644 --- a/paddle/operators/reduce_op.cu +++ b/paddle/operators/reduce_op.cu @@ -20,10 +20,22 @@ namespace ops = paddle::operators; #define REGISTER_REDUCE_GPU_KERNEL(reduce_type, functor, grad_functor) \ REGISTER_OP_CUDA_KERNEL( \ reduce_type, ops::ReduceKernel); \ + float, ops::functor>, \ + ops::ReduceKernel, \ + ops::ReduceKernel, \ + ops::ReduceKernel); \ REGISTER_OP_CUDA_KERNEL( \ reduce_type##_grad, \ ops::ReduceGradKernel, \ + ops::ReduceGradKernel, \ + ops::ReduceGradKernel, \ + ops::ReduceGradKernel); FOR_EACH_KERNEL_FUNCTOR(REGISTER_REDUCE_GPU_KERNEL); diff --git a/python/paddle/v2/fluid/tests/test_reduce_op.py b/python/paddle/v2/fluid/tests/test_reduce_op.py index 57ee307ba6..e2df0395ea 100644 --- a/python/paddle/v2/fluid/tests/test_reduce_op.py +++ b/python/paddle/v2/fluid/tests/test_reduce_op.py @@ -19,7 +19,7 @@ from op_test import OpTest class TestSumOp(OpTest): def setUp(self): self.op_type = "reduce_sum" - self.inputs = {'X': np.random.random((5, 6, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 10)).astype("float64")} self.outputs = {'Out': self.inputs['X'].sum(axis=0)} def test_check_output(self): @@ -32,7 +32,7 @@ class TestSumOp(OpTest): class TestMeanOp(OpTest): def setUp(self): self.op_type = "reduce_mean" - self.inputs = {'X': np.random.random((5, 6, 2, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 2, 10)).astype("float64")} self.attrs = {'dim': 1} self.outputs = {'Out': self.inputs['X'].mean(axis=self.attrs['dim'])} @@ -48,7 +48,7 @@ class TestMaxOp(OpTest): def setUp(self): self.op_type = "reduce_max" - self.inputs = {'X': np.random.random((5, 6, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 10)).astype("float64")} self.attrs = {'dim': -1} self.outputs = {'Out': self.inputs['X'].max(axis=self.attrs['dim'])} @@ -61,7 +61,7 @@ class TestMinOp(OpTest): def setUp(self): self.op_type = "reduce_min" - self.inputs = {'X': np.random.random((5, 6, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 10)).astype("float64")} self.attrs = {'dim': 2} self.outputs = {'Out': self.inputs['X'].min(axis=self.attrs['dim'])} @@ -72,7 +72,7 @@ class TestMinOp(OpTest): class TestKeepDimReduce(OpTest): def setUp(self): self.op_type = "reduce_sum" - self.inputs = {'X': np.random.random((5, 6, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 10)).astype("float64")} self.attrs = {'dim': -2, 'keep_dim': True} self.outputs = { 'Out': self.inputs['X'].sum(axis=self.attrs['dim'], keepdims=True) @@ -88,7 +88,7 @@ class TestKeepDimReduce(OpTest): class Test1DReduce(OpTest): def setUp(self): self.op_type = "reduce_sum" - self.inputs = {'X': np.random.random(20).astype("float32")} + self.inputs = {'X': np.random.random(20).astype("float64")} self.outputs = {'Out': self.inputs['X'].sum(axis=0)} def test_check_output(self): @@ -101,7 +101,7 @@ class Test1DReduce(OpTest): class TestReduceAll(OpTest): def setUp(self): self.op_type = "reduce_sum" - self.inputs = {'X': np.random.random((5, 6, 2, 10)).astype("float32")} + self.inputs = {'X': np.random.random((5, 6, 2, 10)).astype("float64")} self.attrs = {'reduce_all': True} self.outputs = {'Out': self.inputs['X'].sum()} -- GitLab