From 783f9eade49aef3ae2c4e89404b1da4ce49fb6f5 Mon Sep 17 00:00:00 2001 From: sweetsky0901 Date: Tue, 2 Jan 2018 15:32:32 +0800 Subject: [PATCH] del using in .h --- paddle/operators/norm_op.h | 81 ++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/paddle/operators/norm_op.h b/paddle/operators/norm_op.h index b22df373af1..7bee48919e9 100644 --- a/paddle/operators/norm_op.h +++ b/paddle/operators/norm_op.h @@ -19,13 +19,6 @@ limitations under the License. */ namespace paddle { namespace operators { -template -using EigenVector = framework::EigenVector; -template -using EigenMatrix = framework::EigenMatrix; - template class NormKernel : public framework::OpKernel { public: @@ -42,29 +35,37 @@ class NormKernel : public framework::OpKernel { int fea_len = height * width; auto* place = context.template device_context().eigen_device(); - auto x = EigenMatrix::From( - *in_x, framework::make_ddim({batch_size, fea_len * channels})); + auto x = + framework::EigenMatrix::From( + *in_x, framework::make_ddim({batch_size, fea_len * channels})); // get square framework::Tensor x_square; x_square.mutable_data(in_x->dims(), context.GetPlace()); - auto x_square_eigen = EigenMatrix::From( - x_square, framework::make_ddim({batch_size, fea_len * channels})); + auto x_square_eigen = + framework::EigenMatrix::From( + x_square, framework::make_ddim({batch_size, fea_len * channels})); x_square_eigen.device(*place) = x.square(); - auto scale_eigen = EigenVector::Flatten(*scale); + auto scale_eigen = + framework::EigenVector::Flatten( + *scale); for (int n = 0; n < batch_size; ++n) { framework::Tensor in_x_batch = in_x->Slice(n, n + 1); - auto in_x_batch_eigen = EigenMatrix::From( - in_x_batch, framework::make_ddim({channels, fea_len})); + auto in_x_batch_eigen = + framework::EigenMatrix::From( + in_x_batch, framework::make_ddim({channels, fea_len})); framework::Tensor x_square_batch = x_square.Slice(n, n + 1); - auto x_square_batch_eigen = EigenMatrix::From( - x_square_batch, framework::make_ddim({channels, fea_len})); + auto x_square_batch_eigen = + framework::EigenMatrix::From( + x_square_batch, framework::make_ddim({channels, fea_len})); framework::Tensor out_batch = out->Slice(n, n + 1); - auto out_batch_eigen = EigenMatrix::From( - out_batch, framework::make_ddim({channels, fea_len})); + auto out_batch_eigen = + framework::EigenMatrix::From( + out_batch, framework::make_ddim({channels, fea_len})); framework::Tensor tmp_tensor; tmp_tensor.mutable_data(framework::make_ddim({1, fea_len}), context.GetPlace()); - auto tmp = EigenVector::Flatten(tmp_tensor); + auto tmp = framework::EigenVector::Flatten(tmp_tensor); // get colsum and sqrt , inverse auto dim = Eigen::array({{0}}); tmp.device(*place) = x_square_batch_eigen.sum(dim); @@ -102,40 +103,52 @@ class NormGradKernel : public framework::OpKernel { auto* place = context.template device_context().eigen_device(); - auto scale_eigen = EigenVector::Flatten(*scale); - auto x = EigenMatrix::From( - *in_x, framework::make_ddim({batch_size, fea_len * channels})); + auto scale_eigen = + framework::EigenVector::Flatten( + *scale); + auto x = + framework::EigenMatrix::From( + *in_x, framework::make_ddim({batch_size, fea_len * channels})); // get square framework::Tensor x_square; x_square.mutable_data(in_x->dims(), context.GetPlace()); - auto x_square_eigen = EigenMatrix::From( - x_square, framework::make_ddim({batch_size, fea_len * channels})); + auto x_square_eigen = + framework::EigenMatrix::From( + x_square, framework::make_ddim({batch_size, fea_len * channels})); x_square_eigen.device(*place) = x.square(); for (int n = 0; n < batch_size; ++n) { framework::Tensor in_x_batch = in_x->Slice(n, n + 1); - auto in_x_batch_eigen = EigenMatrix::From( - in_x_batch, framework::make_ddim({channels, fea_len})); + auto in_x_batch_eigen = + framework::EigenMatrix::From( + in_x_batch, framework::make_ddim({channels, fea_len})); framework::Tensor in_g_batch = in_x_grad->Slice(n, n + 1); - auto in_g_batch_eigen = EigenMatrix::From( - in_g_batch, framework::make_ddim({channels, fea_len})); + auto in_g_batch_eigen = + framework::EigenMatrix::From( + in_g_batch, framework::make_ddim({channels, fea_len})); framework::Tensor x_square_batch = x_square.Slice(n, n + 1); - auto x_square_batch_eigen = EigenMatrix::From( - x_square_batch, framework::make_ddim({channels, fea_len})); + auto x_square_batch_eigen = + framework::EigenMatrix::From( + x_square_batch, framework::make_ddim({channels, fea_len})); framework::Tensor outg_batch = out_grad->Slice(n, n + 1); - auto outg_batch_eigen = EigenMatrix::From( - outg_batch, framework::make_ddim({channels, fea_len})); + auto outg_batch_eigen = + framework::EigenMatrix::From( + outg_batch, framework::make_ddim({channels, fea_len})); framework::Tensor tmp_tensor; tmp_tensor.mutable_data(framework::make_ddim({1, fea_len}), context.GetPlace()); - auto tmp_eigen = EigenVector::Flatten(tmp_tensor); + auto tmp_eigen = + framework::EigenVector::Flatten(tmp_tensor); auto dim = Eigen::array({{0}}); tmp_eigen.device(*place) = (in_x_batch_eigen * outg_batch_eigen).sum(dim); framework::Tensor norm_tmp_tensor; norm_tmp_tensor.mutable_data(framework::make_ddim({1, fea_len}), context.GetPlace()); - auto norm_tmp_eigen = EigenVector::Flatten(norm_tmp_tensor); + auto norm_tmp_eigen = + framework::EigenVector::Flatten(norm_tmp_tensor); norm_tmp_eigen.device(*place) = (x_square_batch_eigen.sum(dim) + epsilon).sqrt(); Eigen::array broadcast_dim_col; -- GitLab