diff --git a/paddle/operators/math/unpooling.cc b/paddle/operators/math/unpooling.cc index 9017ffaab13e1f33f3b31cd92f00f6eaffd420d9..b57d3dc1414cff492db8d7d503a7fce370a3f151 100644 --- a/paddle/operators/math/unpooling.cc +++ b/paddle/operators/math/unpooling.cc @@ -20,8 +20,8 @@ template class Unpool2dMaxFunctor { public: void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, - const framework::Tensor& indices, framework::Tensor* output) { + 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]; diff --git a/paddle/operators/math/unpooling.cu b/paddle/operators/math/unpooling.cu index f3a317b3b3a5f6d8ccc544f5f357e52868311913..058b82d9d2a3d604503561c95e0532eac0a3677e 100644 --- a/paddle/operators/math/unpooling.cu +++ b/paddle/operators/math/unpooling.cu @@ -20,11 +20,12 @@ 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) { + 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; @@ -42,12 +43,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; @@ -71,8 +71,8 @@ template class Unpool2dMaxFunctor { public: void operator()(const platform::DeviceContext& context, - const framework::Tensor& input, const framework::Tensor& indices, - framework::Tensor* output) { + 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]; @@ -88,8 +88,8 @@ class Unpool2dMaxFunctor { T><<(context) .stream()>>>(input.numel(), input_data, indices_data, - input_height, input_width, output_channels, - output_data, output_height, output_width); + input_height, input_width, output_channels, + output_data, output_height, output_width); } }; /* @@ -121,9 +121,9 @@ class Unpool2dMaxGradFunctor { 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); + 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 61eadcdcd58240c77f97ebe33dc72debffc3b464..7077d7c2274fd9e02b69ef343f310f4ffbbcff1a 100644 --- a/paddle/operators/math/unpooling.h +++ b/paddle/operators/math/unpooling.h @@ -23,8 +23,7 @@ class Unpool2dMaxFunctor { public: void operator()(const platform::DeviceContext& context, const framework::Tensor& input, - const framework::Tensor& indices, - framework::Tensor* output); + const framework::Tensor& indices, framework::Tensor* output); }; template class Unpool2dMaxGradFunctor { diff --git a/paddle/operators/unpool_op.cc b/paddle/operators/unpool_op.cc index a40aadcccc618ad3b9d7f9e035ceac396c8b342f..8bd596dbb07089fa47b0590d4a71dc4b6cf32461 100644 --- a/paddle/operators/unpool_op.cc +++ b/paddle/operators/unpool_op.cc @@ -75,36 +75,38 @@ int OutputSize(int input_size, int ksize, int padding, int stride) { class UnpoolOp : public framework::OperatorWithKernel { protected: framework::OpKernelType GetKernelType( - const framework::ExecutionContext& ctx) const override { - return framework::OpKernelType( - framework::ToDataType(ctx.Input("X")->type()), + const framework::ExecutionContext& ctx) const override { + return framework::OpKernelType( + framework::ToDataType(ctx.Input("X")->type()), ctx.device_context()); - } + } public: using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) of UnpoolOp" - "should not be null."); - PADDLE_ENFORCE(ctx->HasInput("Indices"), "Input(Indices) of UnpoolOp" + PADDLE_ENFORCE(ctx->HasInput("X"), + "Input(X) of UnpoolOp" + "should not be null."); + PADDLE_ENFORCE(ctx->HasInput("Indices"), + "Input(Indices) of UnpoolOp" "should not be null."); PADDLE_ENFORCE(ctx->HasOutput("Out"), "Output(Out) of UnpoolOp should not be null."); auto in_x_dims = ctx->GetInputDim("X"); auto in_y_dims = ctx->GetInputDim("Indices"); - std::string unpooling_type = - ctx->Attrs().Get("unpooling_type"); + std::string unpooling_type = ctx->Attrs() + .Get("unpooling_type"); std::vector ksize = ctx->Attrs().Get>("ksize"); std::vector strides = ctx->Attrs().Get>("strides"); std::vector paddings = ctx->Attrs().Get>("paddings"); PADDLE_ENFORCE(in_x_dims.size() == 4, - "Unpooling intput must be of 4-dimensional."); + "Unpooling intput must be of 4-dimensional."); PADDLE_ENFORCE_EQ(in_x_dims, in_y_dims); std::vector output_shape({in_x_dims[0], in_x_dims[1]}); for (size_t i = 0; i < ksize.size(); ++i) { output_shape.push_back( - OutputSize(in_x_dims[i + 2], ksize[i], paddings[i], strides[i])); + OutputSize(in_x_dims[i + 2], ksize[i], paddings[i], strides[i])); } ctx->SetOutputDim("Out", framework::make_ddim(output_shape)); } @@ -113,30 +115,30 @@ class UnpoolOp : public framework::OperatorWithKernel { class UnpoolOpGrad : public framework::OperatorWithKernel { protected: framework::OpKernelType GetKernelType( - const framework::ExecutionContext& ctx) const override { - return framework::OpKernelType( + const framework::ExecutionContext& ctx) const override { + return framework::OpKernelType( framework::ToDataType(ctx.Input("X")->type()), ctx.device_context()); - } + } public: using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) must not be null."); PADDLE_ENFORCE(ctx->HasOutput(framework::GradVarName("X")), - "Input(X@GRAD) should not be null."); + "Input(X@GRAD) should not be null."); ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("X")); } }; -} // namespace operators -} // namespace paddle +} // namespace operators +} // namespace paddle namespace ops = paddle::operators; REGISTER_OP(unpool, ops::UnpoolOp, ops::Unpool2dOpMaker, unpool_grad, ops::UnpoolOpGrad); -REGISTER_OP_CPU_KERNEL( - unpool, ops::UnpoolKernel, - ops::UnpoolKernel); +REGISTER_OP_CPU_KERNEL(unpool, + ops::UnpoolKernel, + ops::UnpoolKernel); REGISTER_OP_CPU_KERNEL( unpool_grad, ops::UnpoolGradKernel, ops::UnpoolGradKernel); diff --git a/paddle/operators/unpool_op.cu.cc b/paddle/operators/unpool_op.cu.cc index 29b393f474528da25ad9ca521f8ff6a58245058b..18aafb7dc74ed474ed3ec5e8a388ecdb71b9a8f5 100644 --- a/paddle/operators/unpool_op.cu.cc +++ b/paddle/operators/unpool_op.cu.cc @@ -15,9 +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, + ops::UnpoolKernel, + ops::UnpoolKernel); REGISTER_OP_GPU_KERNEL( unpool_grad, ops::UnpoolGradKernel, ops::UnpoolGradKernel);