From 0417e4e4bf205566ca882f3878c0a64417f5da96 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Fri, 22 Sep 2017 12:02:41 +0800 Subject: [PATCH] fix framework::LoDTensor => Tensor --- paddle/operators/math/pooling.h | 26 +++++++++++--------------- paddle/operators/pool_op.cc | 4 ++-- paddle/operators/pool_op.h | 3 +-- paddle/platform/hostdevice.h | 2 ++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/paddle/operators/math/pooling.h b/paddle/operators/math/pooling.h index 3f01c9dacb..627ece2ca4 100644 --- a/paddle/operators/math/pooling.h +++ b/paddle/operators/math/pooling.h @@ -16,17 +16,13 @@ limitations under the License. */ #include "paddle/framework/eigen.h" #include "paddle/framework/tensor.h" #include "paddle/platform/device_context.h" +#include "paddle/platform/hostdevice.h" namespace paddle { namespace operators { namespace math { ////////////////////// -#ifdef __NVCC__ -#define HL_DEVICE __device__ -#else -#define HL_DEVICE -#endif #define FLT_MAX __FLT_MAX__ ///////////////////// @@ -34,11 +30,11 @@ namespace pool { template class maxPool { public: - HL_DEVICE inline T initial() { return -(T)(FLT_MAX); } - HL_DEVICE inline void process(T& y, const T& x) { y = y > x ? y : x; } - HL_DEVICE inline void finalize(T& y, const T& poo_size) {} - HL_DEVICE inline void gradProcess(const T& x, const T& y, const T& dy, T& dx, - T scale) { + DEVICE inline T initial() { return static_cast(-FLT_MAX); } + DEVICE inline void process(T& y, const T& x) { y = y > x ? y : x; } + DEVICE inline void finalize(T& y, const T& poo_size) {} + DEVICE inline void gradProcess(const T& x, const T& y, const T& dy, T& dx, + T scale) { dx += dy * (x == y); } }; @@ -46,11 +42,11 @@ class maxPool { template class avePool { public: - HL_DEVICE inline T initial() { return 0; } - HL_DEVICE inline void process(T& y, const T& x) { y += x; } - HL_DEVICE inline void finalize(T& y, const T& poo_size) { y /= poo_size; } - HL_DEVICE inline void gradProcess(const T& x, const T& y, const T& dy, T& dx, - T scale) { + DEVICE inline T initial() { return static_cast(0); } + DEVICE inline void process(T& y, const T& x) { y += x; } + DEVICE inline void finalize(T& y, const T& poo_size) { y /= poo_size; } + DEVICE inline void gradProcess(const T& x, const T& y, const T& dy, T& dx, + T scale) { dx += (scale * dy); } }; diff --git a/paddle/operators/pool_op.cc b/paddle/operators/pool_op.cc index bcda072a2d..434aae811c 100644 --- a/paddle/operators/pool_op.cc +++ b/paddle/operators/pool_op.cc @@ -37,7 +37,7 @@ class PoolOp : public framework::OperatorWithKernel { // PADDLE_ENFORCE_NOT_NULL(Attr>("ksize"), "ksize should // not be null."); auto in_X = ctx.Input("X"); - auto out = ctx.Output("Out"); + auto out = ctx.Output("Out"); int global_pooling = Attr("globalPooling"); std::string pooling_type = Attr("poolingType"); std::vector ksize = Attr>("ksize"); @@ -78,7 +78,7 @@ class PoolOpGrad : public framework::OperatorWithKernel { protected: void InferShape(const framework::InferShapeContext &ctx) const override { auto in = ctx.Input("X"); - auto d_in = ctx.Output(framework::GradVarName("X")); + auto d_in = ctx.Output(framework::GradVarName("X")); if (d_in) d_in->Resize(in->dims()); } }; diff --git a/paddle/operators/pool_op.h b/paddle/operators/pool_op.h index 2e737f0a4b..5a40f76172 100644 --- a/paddle/operators/pool_op.h +++ b/paddle/operators/pool_op.h @@ -90,8 +90,7 @@ class PoolGradKernel : public framework::OpKernel { const Tensor* out = context.Input("Out"); const Tensor* out_grad = context.Input(framework::GradVarName("Out")); - Tensor* in_X_grad = - context.Output(framework::GradVarName("X")); + Tensor* in_X_grad = context.Output(framework::GradVarName("X")); int global_pooling = context.Attr("globalPooling"); std::string pooling_type = context.Attr("poolingType"); diff --git a/paddle/platform/hostdevice.h b/paddle/platform/hostdevice.h index e7de86b7b2..eb2df291cc 100644 --- a/paddle/platform/hostdevice.h +++ b/paddle/platform/hostdevice.h @@ -2,8 +2,10 @@ #ifdef __CUDACC__ #define HOSTDEVICE __host__ __device__ +#define DEVICE __device__ #define HOST __host__ #else #define HOSTDEVICE +#define DEVICE #define HOST #endif -- GitLab