From c7cd8d987aa3025c57c86c6b316273193c8054f6 Mon Sep 17 00:00:00 2001 From: jzhang533 Date: Tue, 8 Nov 2022 11:09:23 +0800 Subject: [PATCH] removing dependent to fluid/framework/eigen.h in phi (#47675) * removing dependent to fluid/framework/eigen.h in phi * more fix according to PR-CI-Py3 fail --- .../ps/service/communicator/communicator.h | 2 +- .../fluid/imperative/gradient_accumulator.cc | 14 ++++++------- .../operators/detection/anchor_generator_op.h | 6 +++--- .../detection/density_prior_box_op.h | 6 +++--- .../fluid/operators/detection/prior_box_op.h | 4 ++-- paddle/fluid/operators/index_select_op.h | 4 ++-- paddle/fluid/operators/interpolate_op.h | 2 +- .../fluid/operators/math/sequence_pooling.cc | 4 ++-- .../sequence_ops/sequence_expand_op.h | 2 +- paddle/phi/kernels/cpu/norm_grad_kernel.cc | 10 +++++----- paddle/phi/kernels/cpu/norm_kernel.cc | 6 +++--- .../phi/kernels/funcs/detail/gru_cpu_kernel.h | 4 ++-- .../kernels/funcs/detail/lstm_cpu_kernel.h | 4 ++-- paddle/phi/kernels/funcs/math_function.cc | 6 +++--- paddle/phi/kernels/funcs/math_function.h | 2 +- paddle/phi/kernels/funcs/math_function_impl.h | 20 +++++++++---------- paddle/phi/kernels/funcs/sequence2batch.h | 4 ++-- paddle/phi/kernels/gpudnn/conv_grad_kernel.cu | 1 - paddle/phi/kernels/impl/conv_cudnn_impl.h | 1 - .../impl/segment_pool_grad_kernel_impl.h | 1 - .../kernels/impl/segment_pool_kernel_impl.h | 1 - 21 files changed, 50 insertions(+), 54 deletions(-) diff --git a/paddle/fluid/distributed/ps/service/communicator/communicator.h b/paddle/fluid/distributed/ps/service/communicator/communicator.h index b8832964415..04ed31f67d2 100644 --- a/paddle/fluid/distributed/ps/service/communicator/communicator.h +++ b/paddle/fluid/distributed/ps/service/communicator/communicator.h @@ -154,7 +154,7 @@ class BlockingQueue { template -using EigenVector = framework::EigenVector; +using EigenVector = phi::EigenVector; template inline void MergeVars(const std::string &var_name, diff --git a/paddle/fluid/imperative/gradient_accumulator.cc b/paddle/fluid/imperative/gradient_accumulator.cc index f60d8ef5134..188617dd310 100644 --- a/paddle/fluid/imperative/gradient_accumulator.cc +++ b/paddle/fluid/imperative/gradient_accumulator.cc @@ -206,13 +206,13 @@ void TensorAdd(const VarType& src, VarType* dst) { #endif } -#define TENSOR_ADD_EIGEN(T) \ - auto cpu_ctx = static_cast( \ - platform::DeviceContextPool::Instance().Get(place)); \ - auto in = paddle::framework::EigenVector::Flatten(src_tensor); \ - auto out = paddle::framework::EigenVector::Flatten(*dst_tensor); \ - auto& p = *(cpu_ctx->eigen_device()); \ - out.device(p) = out + in; \ +#define TENSOR_ADD_EIGEN(T) \ + auto cpu_ctx = static_cast( \ + platform::DeviceContextPool::Instance().Get(place)); \ + auto in = phi::EigenVector::Flatten(src_tensor); \ + auto out = phi::EigenVector::Flatten(*dst_tensor); \ + auto& p = *(cpu_ctx->eigen_device()); \ + out.device(p) = out + in; \ return; if (platform::is_cpu_place(place)) { diff --git a/paddle/fluid/operators/detection/anchor_generator_op.h b/paddle/fluid/operators/detection/anchor_generator_op.h index aaebcef3c90..6582ddac141 100644 --- a/paddle/fluid/operators/detection/anchor_generator_op.h +++ b/paddle/fluid/operators/detection/anchor_generator_op.h @@ -70,7 +70,7 @@ class AnchorGeneratorOpKernel : public framework::OpKernel { anchors->mutable_data(ctx.GetPlace()); vars->mutable_data(ctx.GetPlace()); - auto e_anchors = framework::EigenTensor::From(*anchors); + auto e_anchors = phi::EigenTensor::From(*anchors); for (int h_idx = 0; h_idx < feature_height; ++h_idx) { for (int w_idx = 0; w_idx < feature_width; ++w_idx) { T x_ctr = (w_idx * stride_width) + offset * (stride_width - 1); @@ -110,7 +110,7 @@ class AnchorGeneratorOpKernel : public framework::OpKernel { var_t.mutable_data( phi::make_ddim({1, static_cast(variances.size())}), ctx.GetPlace()); - auto var_et = framework::EigenTensor::From(var_t); + auto var_et = phi::EigenTensor::From(var_t); for (size_t i = 0; i < variances.size(); ++i) { var_et(0, i) = variances[i]; } @@ -119,7 +119,7 @@ class AnchorGeneratorOpKernel : public framework::OpKernel { auto var_dim = vars->dims(); vars->Resize({anchor_num, static_cast(variances.size())}); - auto e_vars = framework::EigenMatrix::From(*vars); + auto e_vars = phi::EigenMatrix::From(*vars); e_vars = var_et.broadcast(Eigen::DSizes(anchor_num, 1)); vars->Resize(var_dim); diff --git a/paddle/fluid/operators/detection/density_prior_box_op.h b/paddle/fluid/operators/detection/density_prior_box_op.h index f3e3cb0ffb6..237626fee4c 100644 --- a/paddle/fluid/operators/detection/density_prior_box_op.h +++ b/paddle/fluid/operators/detection/density_prior_box_op.h @@ -66,7 +66,7 @@ class DensityPriorBoxOpKernel : public framework::OpKernel { auto box_dim = vars->dims(); boxes->Resize({feature_height, feature_width, num_priors, 4}); - auto e_boxes = framework::EigenTensor::From(*boxes).setConstant(0.0); + auto e_boxes = phi::EigenTensor::From(*boxes).setConstant(0.0); int step_average = static_cast((step_width + step_height) * 0.5); std::vector sqrt_fixed_ratios; @@ -126,7 +126,7 @@ class DensityPriorBoxOpKernel : public framework::OpKernel { phi::make_ddim({1, static_cast(variances.size())}), ctx.GetPlace()); - auto var_et = framework::EigenTensor::From(var_t); + auto var_et = phi::EigenTensor::From(var_t); for (size_t i = 0; i < variances.size(); ++i) { var_et(0, i) = variances[i]; @@ -136,7 +136,7 @@ class DensityPriorBoxOpKernel : public framework::OpKernel { auto var_dim = vars->dims(); vars->Resize({box_num, static_cast(variances.size())}); - auto e_vars = framework::EigenMatrix::From(*vars); + auto e_vars = phi::EigenMatrix::From(*vars); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(2) #endif diff --git a/paddle/fluid/operators/detection/prior_box_op.h b/paddle/fluid/operators/detection/prior_box_op.h index 51e8bbbcae5..9968a07fcf7 100644 --- a/paddle/fluid/operators/detection/prior_box_op.h +++ b/paddle/fluid/operators/detection/prior_box_op.h @@ -182,7 +182,7 @@ class PriorBoxOpKernel : public framework::OpKernel { var_t.mutable_data( phi::make_ddim({1, static_cast(variances.size())}), ctx.GetPlace()); - auto var_et = framework::EigenTensor::From(var_t); + auto var_et = phi::EigenTensor::From(var_t); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for @@ -195,7 +195,7 @@ class PriorBoxOpKernel : public framework::OpKernel { auto var_dim = vars->dims(); vars->Resize({box_num, static_cast(variances.size())}); - auto e_vars = framework::EigenMatrix::From(*vars); + auto e_vars = phi::EigenMatrix::From(*vars); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(2) diff --git a/paddle/fluid/operators/index_select_op.h b/paddle/fluid/operators/index_select_op.h index e21da66a160..71dd10d0aa4 100644 --- a/paddle/fluid/operators/index_select_op.h +++ b/paddle/fluid/operators/index_select_op.h @@ -83,8 +83,8 @@ void IndexSelectInner(const framework::ExecutionContext& context, input->Resize(phi::make_ddim({outer_nums, input_dim[dim], slice_size})); output->Resize(phi::make_ddim({outer_nums, index_size, slice_size})); - auto input_tensor = framework::EigenTensor::From(*input); - auto output_tensor = framework::EigenTensor::From(*output); + auto input_tensor = phi::EigenTensor::From(*input); + auto output_tensor = phi::EigenTensor::From(*output); auto& place = *context.template device_context().eigen_device(); diff --git a/paddle/fluid/operators/interpolate_op.h b/paddle/fluid/operators/interpolate_op.h index ff2d5236d78..11c14291076 100644 --- a/paddle/fluid/operators/interpolate_op.h +++ b/paddle/fluid/operators/interpolate_op.h @@ -25,7 +25,7 @@ template -using EigenTensor = framework::EigenTensor; +using EigenTensor = phi::EigenTensor; using Tensor = phi::DenseTensor; using DataLayout = phi::DataLayout; diff --git a/paddle/fluid/operators/math/sequence_pooling.cc b/paddle/fluid/operators/math/sequence_pooling.cc index 43b39795753..9008111e42b 100644 --- a/paddle/fluid/operators/math/sequence_pooling.cc +++ b/paddle/fluid/operators/math/sequence_pooling.cc @@ -29,11 +29,11 @@ using LoDTensor = phi::DenseTensor; template -using EigenVector = framework::EigenVector; +using EigenVector = phi::EigenVector; template -using EigenMatrix = framework::EigenMatrix; +using EigenMatrix = phi::EigenMatrix; template class MaxSeqPoolFunctor { diff --git a/paddle/fluid/operators/sequence_ops/sequence_expand_op.h b/paddle/fluid/operators/sequence_ops/sequence_expand_op.h index 025a160b0e9..af43aec7931 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_expand_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_expand_op.h @@ -26,7 +26,7 @@ using LoDTensor = phi::DenseTensor; template -using EigenMatrix = framework::EigenMatrix; +using EigenMatrix = phi::EigenMatrix; template struct SequenceExpandFunctor { diff --git a/paddle/phi/kernels/cpu/norm_grad_kernel.cc b/paddle/phi/kernels/cpu/norm_grad_kernel.cc index 92ca51b499c..b27546d7814 100644 --- a/paddle/phi/kernels/cpu/norm_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/norm_grad_kernel.cc @@ -45,10 +45,10 @@ void NormGradKernel(const Context& ctx, auto* place = ctx.eigen_device(); - auto x_e = paddle::framework::EigenVector::Flatten(*in_x); - auto dy_e = paddle::framework::EigenVector::Flatten(*in_dy); - auto norm_e = paddle::framework::EigenVector::Flatten(*in_norm); - auto dx_e = paddle::framework::EigenVector::Flatten(*out_dx); + auto x_e = phi::EigenVector::Flatten(*in_x); + auto dy_e = phi::EigenVector::Flatten(*in_dy); + auto norm_e = phi::EigenVector::Flatten(*in_norm); + auto dx_e = phi::EigenVector::Flatten(*out_dx); Eigen::DSizes shape(pre, n, post); Eigen::DSizes rshape(pre, 1, post); @@ -60,7 +60,7 @@ void NormGradKernel(const Context& ctx, DenseTensor rsum; rsum.Resize({pre, post}); ctx.template Alloc(&rsum); - auto sum = paddle::framework::EigenTensor::From(rsum); + auto sum = phi::EigenTensor::From(rsum); Eigen::DSizes rdim(1); Eigen::DSizes bcast(1, n, 1); diff --git a/paddle/phi/kernels/cpu/norm_kernel.cc b/paddle/phi/kernels/cpu/norm_kernel.cc index f69d03b66b1..21af086515d 100644 --- a/paddle/phi/kernels/cpu/norm_kernel.cc +++ b/paddle/phi/kernels/cpu/norm_kernel.cc @@ -55,9 +55,9 @@ void NormKernel(const Context& ctx, Eigen::DSizes shape(pre, n, post); Eigen::DSizes norm_shape(pre, post); - auto x_e = paddle::framework::EigenVector::Flatten(x); - auto y_e = paddle::framework::EigenVector::Flatten(*out); - auto norm_e = paddle::framework::EigenVector::Flatten(*out_norm); + auto x_e = phi::EigenVector::Flatten(x); + auto y_e = phi::EigenVector::Flatten(*out); + auto norm_e = phi::EigenVector::Flatten(*out_norm); auto x_r = x_e.reshape(shape); auto y = y_e.reshape(shape); auto norm_reshape = norm_e.reshape(norm_shape); diff --git a/paddle/phi/kernels/funcs/detail/gru_cpu_kernel.h b/paddle/phi/kernels/funcs/detail/gru_cpu_kernel.h index 0fdf490c553..eb02200f01d 100644 --- a/paddle/phi/kernels/funcs/detail/gru_cpu_kernel.h +++ b/paddle/phi/kernels/funcs/detail/gru_cpu_kernel.h @@ -15,9 +15,9 @@ limitations under the License. */ #pragma once #include -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/kernels/funcs/activation_functor.h" #include "paddle/phi/kernels/funcs/detail/activation_functions.h" +#include "paddle/phi/kernels/funcs/eigen/common.h" #include "paddle/phi/kernels/funcs/gru_compute.h" namespace phi { @@ -27,7 +27,7 @@ using Array1 = Eigen::DSizes; template -using EigenVector = paddle::framework::EigenVector; +using EigenVector = phi::EigenVector; #if !defined(__NVCC__) && !defined(__HIPCC___) // @{ Group for GRU CPU template diff --git a/paddle/phi/kernels/funcs/detail/lstm_cpu_kernel.h b/paddle/phi/kernels/funcs/detail/lstm_cpu_kernel.h index 02fddc57b31..e8b8e957c80 100644 --- a/paddle/phi/kernels/funcs/detail/lstm_cpu_kernel.h +++ b/paddle/phi/kernels/funcs/detail/lstm_cpu_kernel.h @@ -15,9 +15,9 @@ limitations under the License. */ #pragma once #include -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/kernels/funcs/activation_functor.h" #include "paddle/phi/kernels/funcs/detail/activation_functions.h" +#include "paddle/phi/kernels/funcs/eigen/common.h" #include "paddle/phi/kernels/funcs/lstm_compute.h" #if defined(_WIN32) @@ -34,7 +34,7 @@ using Array1 = Eigen::DSizes; template -using EigenVector = paddle::framework::EigenVector; +using EigenVector = phi::EigenVector; #if !defined(__NVCC__) && !defined(__HIPCC___) // @{ Group LSTM CPU diff --git a/paddle/phi/kernels/funcs/math_function.cc b/paddle/phi/kernels/funcs/math_function.cc index 7102b9cb11a..7cad8866548 100644 --- a/paddle/phi/kernels/funcs/math_function.cc +++ b/paddle/phi/kernels/funcs/math_function.cc @@ -299,9 +299,9 @@ struct RowwiseAdd { in_dims_cstr, out_dims_cstr)); - auto in = paddle::framework::EigenMatrix::From(input); - auto vec = paddle::framework::EigenVector::Flatten(vector); - auto out = paddle::framework::EigenMatrix::From(*output); + auto in = phi::EigenMatrix::From(input); + auto vec = phi::EigenVector::Flatten(vector); + auto out = phi::EigenMatrix::From(*output); for (int64_t i = 0; i < in_dims[0]; ++i) { out.chip(i, 0) = in.chip(i, 0) + vec; diff --git a/paddle/phi/kernels/funcs/math_function.h b/paddle/phi/kernels/funcs/math_function.h index 3a95c998b1f..e922864060c 100644 --- a/paddle/phi/kernels/funcs/math_function.h +++ b/paddle/phi/kernels/funcs/math_function.h @@ -18,7 +18,6 @@ limitations under the License. */ #include #include "paddle/fluid/framework/convert_utils.h" -#include "paddle/fluid/framework/eigen.h" #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/framework/tensor.h" #include "paddle/fluid/framework/tensor_util.h" @@ -26,6 +25,7 @@ limitations under the License. */ #include "paddle/fluid/platform/enforce.h" #include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/utils/data_type.h" +#include "paddle/phi/kernels/funcs/eigen/common.h" namespace phi { namespace funcs { diff --git a/paddle/phi/kernels/funcs/math_function_impl.h b/paddle/phi/kernels/funcs/math_function_impl.h index 512f21e8209..1ab9455215e 100644 --- a/paddle/phi/kernels/funcs/math_function_impl.h +++ b/paddle/phi/kernels/funcs/math_function_impl.h @@ -22,13 +22,13 @@ limitations under the License. */ namespace phi { namespace funcs { -using paddle::framework::To32BitIndex; +using phi::To32BitIndex; template void SetConstant::operator()(const DeviceContext& context, phi::DenseTensor* tensor, T num) { - auto t = paddle::framework::EigenVector::Flatten(*tensor); + auto t = phi::EigenVector::Flatten(*tensor); t.device(*context.eigen_device()) = t.constant(static_cast(num)); } @@ -60,8 +60,8 @@ void Transpose::operator()( for (int i = 0; i < Rank; i++) { permute[i] = axis[i]; } - auto eigen_in = paddle::framework::EigenTensor::From(in); - auto eigen_out = paddle::framework::EigenTensor::From(*out); + auto eigen_in = phi::EigenTensor::From(in); + auto eigen_out = phi::EigenTensor::From(*out); auto* dev = context.eigen_device(); // use 32bit index to speed up computation bool use_32bit_index = eigen_out.size() < Eigen::NumTraits::highest(); @@ -89,8 +89,8 @@ void ColwiseSum::operator()(const DeviceContext& context, size, out->numel())); - auto in = paddle::framework::EigenMatrix::From(input); - auto vec = paddle::framework::EigenVector::Flatten(*out); + auto in = phi::EigenMatrix::From(input); + auto vec = phi::EigenVector::Flatten(*out); vec.device(*context.eigen_device()) = in.sum(Eigen::array({{0}})); } @@ -151,8 +151,8 @@ void RowwiseMean::operator()(const DeviceContext& context, in_dims[0], out->numel())); - auto in = paddle::framework::EigenMatrix::From(input); - auto vec = paddle::framework::EigenVector::Flatten(*out); + auto in = phi::EigenMatrix::From(input); + auto vec = phi::EigenVector::Flatten(*out); vec.device(*context.eigen_device()) = in.mean(Eigen::array({{1}})); } @@ -217,8 +217,8 @@ void RowwiseSum::operator()(const DeviceContext& context, in_dims[0], out->numel())); - auto in = paddle::framework::EigenMatrix::From(input); - auto vec = paddle::framework::EigenVector::Flatten(*out); + auto in = phi::EigenMatrix::From(input); + auto vec = phi::EigenVector::Flatten(*out); vec.device(*context.eigen_device()) = in.sum(Eigen::array({{1}})); } diff --git a/paddle/phi/kernels/funcs/sequence2batch.h b/paddle/phi/kernels/funcs/sequence2batch.h index 5ae2c2f617d..83c89a30916 100644 --- a/paddle/phi/kernels/funcs/sequence2batch.h +++ b/paddle/phi/kernels/funcs/sequence2batch.h @@ -16,10 +16,10 @@ limitations under the License. */ #include #include -#include "paddle/fluid/framework/eigen.h" #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/tensor.h" #include "paddle/fluid/platform/device_context.h" +#include "paddle/phi/kernels/funcs/eigen/common.h" namespace phi { namespace funcs { @@ -27,7 +27,7 @@ namespace funcs { template -using EigenMatrix = paddle::framework::EigenMatrix; +using EigenMatrix = phi::EigenMatrix; template class CopyMatrixRowsFunctor { diff --git a/paddle/phi/kernels/gpudnn/conv_grad_kernel.cu b/paddle/phi/kernels/gpudnn/conv_grad_kernel.cu index 6d7c486a75f..43b0d0a81d4 100644 --- a/paddle/phi/kernels/gpudnn/conv_grad_kernel.cu +++ b/paddle/phi/kernels/gpudnn/conv_grad_kernel.cu @@ -14,7 +14,6 @@ #include "paddle/phi/kernels/conv_grad_kernel.h" -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/kernel_registry.h" diff --git a/paddle/phi/kernels/impl/conv_cudnn_impl.h b/paddle/phi/kernels/impl/conv_cudnn_impl.h index ba7f69f9c3a..02b0ab64471 100644 --- a/paddle/phi/kernels/impl/conv_cudnn_impl.h +++ b/paddle/phi/kernels/impl/conv_cudnn_impl.h @@ -14,7 +14,6 @@ #pragma once -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/kernel_registry.h" diff --git a/paddle/phi/kernels/impl/segment_pool_grad_kernel_impl.h b/paddle/phi/kernels/impl/segment_pool_grad_kernel_impl.h index e75c3e980ef..8d37c7c5124 100644 --- a/paddle/phi/kernels/impl/segment_pool_grad_kernel_impl.h +++ b/paddle/phi/kernels/impl/segment_pool_grad_kernel_impl.h @@ -16,7 +16,6 @@ #include -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/common/place.h" #include "paddle/phi/kernels/funcs/math_function.h" #include "paddle/phi/kernels/funcs/segment_pooling.h" diff --git a/paddle/phi/kernels/impl/segment_pool_kernel_impl.h b/paddle/phi/kernels/impl/segment_pool_kernel_impl.h index 48111913c78..216d5e6100d 100644 --- a/paddle/phi/kernels/impl/segment_pool_kernel_impl.h +++ b/paddle/phi/kernels/impl/segment_pool_kernel_impl.h @@ -16,7 +16,6 @@ #include -#include "paddle/fluid/framework/eigen.h" #include "paddle/phi/common/place.h" #include "paddle/phi/kernels/funcs/math_function.h" #include "paddle/phi/kernels/funcs/segment_pooling.h" -- GitLab