From c52ed8de37b922b8cc5d9ab1a4ff34a426667ed6 Mon Sep 17 00:00:00 2001 From: sweetsky0901 Date: Wed, 29 Nov 2017 10:57:55 +0800 Subject: [PATCH] format code --- paddle/operators/math/unpooling.cc | 22 +++++------ paddle/operators/math/unpooling.cu | 59 ++++++++++++------------------ paddle/operators/math/unpooling.h | 23 +++++------- paddle/operators/unpool_op.cc | 15 ++++---- paddle/operators/unpool_op.cu.cc | 14 +++---- paddle/operators/unpool_op.h | 3 -- 6 files changed, 54 insertions(+), 82 deletions(-) diff --git a/paddle/operators/math/unpooling.cc b/paddle/operators/math/unpooling.cc index b13d0104de0..71928314bae 100644 --- a/paddle/operators/math/unpooling.cc +++ b/paddle/operators/math/unpooling.cc @@ -13,17 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/operators/math/unpooling.h" - namespace paddle { namespace operators { namespace math { -// All tensors are in NCHW format template class Unpool2dMaxFunctor { -public: - void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, framework::Tensor* output) { + public: + void operator()( + const platform::DeviceContext& context, const framework::Tensor& input, + const framework::Tensor& indices, framework::Tensor* output) { const int batch_size = input.dims()[0]; const int input_height = input.dims()[2]; const int input_width = input.dims()[3]; @@ -51,13 +49,11 @@ public: }; template class Unpool2dMaxGradFunctor { -public: - void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, - const framework::Tensor& output, - const framework::Tensor& output_grad, - framework::Tensor* input_grad) { + public: + void operator()( + const platform::DeviceContext& context, const framework::Tensor& input, + const framework::Tensor& indices, const framework::Tensor& output, + const framework::Tensor& output_grad, framework::Tensor* input_grad) { const int batch_size = input.dims()[0]; const int input_height = input.dims()[2]; const int input_width = input.dims()[3]; diff --git a/paddle/operators/math/unpooling.cu b/paddle/operators/math/unpooling.cu index 60179208735..4c6cb7bbca6 100644 --- a/paddle/operators/math/unpooling.cu +++ b/paddle/operators/math/unpooling.cu @@ -19,14 +19,10 @@ namespace paddle { namespace operators { namespace math { template -__global__ void KernelUnpool2dMax(const int nthreads, const T* input_data, - const int* indices_data, - const int input_height, - const int input_width, - const int channels, - T* output_data, - const int output_height, - const int output_width) { +__global__ void KernelUnpool2dMax( + const int nthreads, const T* input_data, const int* indices_data, + const int input_height, const int input_width, const int channels, + T* output_data, const int output_height, const int output_width) { int in_n_stride = input_height * input_width * channels; int in_c_stride = input_height * input_width; int out_n_stride = output_height * output_width * channels; @@ -44,16 +40,11 @@ __global__ void KernelUnpool2dMax(const int nthreads, const T* input_data, } } template -__global__ void KernelUnpool2dMaxGrad(const int nthreads, const T* input_data, - const int* indices_data, - const int input_height, - const int input_width, - const int channels, - const T* output_data, - const T* output_grad, - const int output_height, - const int output_width, - T* input_grad) { +__global__ void KernelUnpool2dMaxGrad( + const int nthreads, const T* input_data, const int* indices_data, + const int input_height, const int input_width, const int channels, + const T* output_data, const T* output_grad, const int output_height, + const int output_width, T* input_grad) { int in_n_stride = input_height * input_width * channels; int in_c_stride = input_height * input_width; int out_n_stride = output_height * output_width * channels; @@ -75,11 +66,10 @@ __global__ void KernelUnpool2dMaxGrad(const int nthreads, const T* input_data, */ template class Unpool2dMaxFunctor { -public: - void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, - framework::Tensor* output) { + public: + void operator()( + const platform::DeviceContext& context, const framework::Tensor& input, + const framework::Tensor& indices, framework::Tensor* output) { const int batch_size = input.dims()[0]; const int input_height = input.dims()[2]; const int input_width = input.dims()[3]; @@ -91,12 +81,11 @@ public: T* output_data = output->mutable_data(context.GetPlace()); int threads = 1024; int grid = (input.numel() + threads - 1) / threads; - KernelUnpool2dMax< - T><<<<(context) - .stream()>>>(input.numel(), input_data, indices_data, - input_height, input_width, output_channels, - output_data, output_height, output_width); + .stream()>>>(input.numel(), input_data, indices_data, + input_height, input_width, output_channels, + output_data, output_height, output_width); } }; /* @@ -104,7 +93,7 @@ public: */ template class Unpool2dMaxGradFunctor { -public: + public: void operator()(const platform::DeviceContext& context, const framework::Tensor& input, const framework::Tensor& indices, @@ -124,13 +113,11 @@ public: T* input_grad_data = input_grad->mutable_data(context.GetPlace()); int threads = 1024; int grid = (input.numel() + threads - 1) / threads; - KernelUnpool2dMaxGrad< - T><<(context) - .stream()>>>(input.numel(), input_data, indices_data, - input_height, input_width, output_channels, - output_data, output_grad_data, - output_height, output_width, input_grad_data); + KernelUnpool2dMaxGrad<<(context) + .stream()>>>(input.numel(), input_data, indices_data, + input_height, input_width, output_channels, output_data, + output_grad_data, output_height, output_width, input_grad_data); } }; template class Unpool2dMaxGradFunctor; diff --git a/paddle/operators/math/unpooling.h b/paddle/operators/math/unpooling.h index 0b969d8d829..43e32bf4fb5 100644 --- a/paddle/operators/math/unpooling.h +++ b/paddle/operators/math/unpooling.h @@ -18,25 +18,20 @@ limitations under the License. */ namespace paddle { namespace operators { namespace math { - template - class Unpool2dMaxFunctor { -public: - void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, framework::Tensor* output); + public: + void operator()( + const platform::DeviceContext& context, const framework::Tensor& input, + const framework::Tensor& indices, framework::Tensor* output); }; - template class Unpool2dMaxGradFunctor { -public: - void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, - const framework::Tensor& output, - const framework::Tensor& output_grad, - framework::Tensor* input_grad); + public: + void operator()( + const platform::DeviceContext& context, const framework::Tensor& input, + const framework::Tensor& indices, const framework::Tensor& output, + const framework::Tensor& output_grad, framework::Tensor* input_grad); }; } // namespace math } // namespace operators diff --git a/paddle/operators/unpool_op.cc b/paddle/operators/unpool_op.cc index cabf17401b0..a51df3aa425 100644 --- a/paddle/operators/unpool_op.cc +++ b/paddle/operators/unpool_op.cc @@ -31,13 +31,12 @@ class Unpool2dOpMaker : public framework::OpProtoAndCheckerMaker { "(Tensor) The input tensor of the indices given out by MaxPool2d. " "The format of input tensor is NCHW. Where N is batch size, C is the " "number of channels, H and W is the height and width of feature."); - AddOutput( - "Out", - "(Tensor) The output tensor of unpool operator." - "The format of output tensor is also NCHW." - "Where N is batch size, C is " - "the number of channels, H and W is the height and " - "width of feature."); + AddOutput("Out", + "(Tensor) The output tensor of unpool operator." + "The format of output tensor is also NCHW." + "Where N is batch size, C is " + "the number of channels, H and W is the height and " + "width of feature."); AddAttr>( "ksize", "(vector), the unpooling window size(height, width) " @@ -138,7 +137,7 @@ namespace ops = paddle::operators; REGISTER_OP(unpool, ops::UnpoolOp, ops::Unpool2dOpMaker, unpool_grad, ops::UnpoolOpGrad); REGISTER_OP_CPU_KERNEL( - unpool,ops::UnpoolKernel, + unpool, ops::UnpoolKernel, ops::UnpoolKernel); REGISTER_OP_CPU_KERNEL( unpool_grad, ops::UnpoolGradKernel, diff --git a/paddle/operators/unpool_op.cu.cc b/paddle/operators/unpool_op.cu.cc index d8214fc6877..8ee9e2b373b 100644 --- a/paddle/operators/unpool_op.cu.cc +++ b/paddle/operators/unpool_op.cu.cc @@ -15,11 +15,9 @@ limitations under the License. */ #include "paddle/operators/unpool_op.h" namespace ops = paddle::operators; -REGISTER_OP_GPU_KERNEL(unpool, - ops::UnpoolKernel, - ops::UnpoolKernel); -REGISTER_OP_GPU_KERNEL(unpool_grad, - ops::UnpoolGradKernel, - ops::UnpoolGradKernel); +REGISTER_OP_GPU_KERNEL( + unpool, ops::UnpoolKernel, + ops::UnpoolKernel); +REGISTER_OP_GPU_KERNEL( + unpool_grad, ops::UnpoolGradKernel, + ops::UnpoolGradKernel); diff --git a/paddle/operators/unpool_op.h b/paddle/operators/unpool_op.h index 8fad768e494..243eb7e532c 100644 --- a/paddle/operators/unpool_op.h +++ b/paddle/operators/unpool_op.h @@ -20,7 +20,6 @@ limitations under the License. */ namespace paddle { namespace operators { - template class UnpoolKernel : public framework::OpKernel { public: @@ -41,7 +40,6 @@ class UnpoolKernel : public framework::OpKernel { unpool2d_max_forward(context.device_context(), *in_x, *in_y, out); } }; - template class UnpoolGradKernel : public framework::OpKernel { public: @@ -69,6 +67,5 @@ class UnpoolGradKernel : public framework::OpKernel { *out_grad, in_x_grad); } }; - } // namespace operators } // namespace paddle -- GitLab