diff --git a/paddle/fluid/distributed/collective/reducer.cc b/paddle/fluid/distributed/collective/reducer.cc index 4262161b1bc45f4c3a31586fe2c7e7d28ed5e17b..dda5f2eee6e8f768eec6b3363f3d19bc277c2c34 100644 --- a/paddle/fluid/distributed/collective/reducer.cc +++ b/paddle/fluid/distributed/collective/reducer.cc @@ -251,7 +251,7 @@ void EagerGroup::ConcatTensors(const platform::Place &place) { "Please recompile or reinstall Paddle with NCCL support.")); #endif } else if (platform::is_cpu_place(place)) { - auto *default_ctx = static_cast( + auto *default_ctx = static_cast( platform::DeviceContextPool::Instance().Get(place)); ConcatTensorsWithType( *default_ctx, dense_tensors_, &dense_contents_, dtype_); @@ -274,7 +274,7 @@ void EagerGroup::SplitTensors(const platform::Place &place) { "Please recompile or reinstall Paddle with NCCL support.")); #endif } else if (platform::is_cpu_place(place)) { - auto *default_ctx = static_cast( + auto *default_ctx = static_cast( platform::DeviceContextPool::Instance().Get(place)); SplitTensorsWithType( *default_ctx, &dense_contents_, &dense_tensors_, dtype_); @@ -891,7 +891,7 @@ void EagerReducer::AllReduceSparse(EagerGroup *group, "Please recompile or reinstall Paddle with NCCL support.")); #endif } else if (platform::is_cpu_place(inner_place_)) { - dev_ctx = static_cast( + dev_ctx = static_cast( platform::DeviceContextPool::Instance().Get(inner_place_)); } else { PADDLE_THROW(platform::errors::Unimplemented( diff --git a/paddle/fluid/distributed/common/utils.h b/paddle/fluid/distributed/common/utils.h index 847e85a13415dcc5514c8d8cd85a0ae62601a7ca..1abfb57b99dabc8fd463694ca54d6722d85e2c22 100644 --- a/paddle/fluid/distributed/common/utils.h +++ b/paddle/fluid/distributed/common/utils.h @@ -31,9 +31,9 @@ namespace paddle { namespace distributed { template -inline phi::funcs::BlasT GetBlas() { - paddle::platform::CPUDeviceContext cpu_ctx; - return phi::funcs::GetBlas(cpu_ctx); +inline phi::funcs::BlasT GetBlas() { + phi::CPUContext cpu_ctx; + return phi::funcs::GetBlas(cpu_ctx); } template diff --git a/paddle/fluid/distributed/ps/service/communicator/communicator.cc b/paddle/fluid/distributed/ps/service/communicator/communicator.cc index 990dbc845f0adad98a73c0d98ca2984acd28d94f..0856c81121f895b8c6d5b58cc70fd79ec5a43e36 100644 --- a/paddle/fluid/distributed/ps/service/communicator/communicator.cc +++ b/paddle/fluid/distributed/ps/service/communicator/communicator.cc @@ -353,11 +353,12 @@ void Communicator::RpcRecvSparse(const std::string &varname, bool training = true; - auto status = _worker_ptr->PullSparseParam((float **)push_g_vec.data(), - table_id, // NOLINT - sparse_push_keys.data(), - sparse_push_keys.size(), - training); + auto status = + _worker_ptr->PullSparseParam(static_cast(push_g_vec.data()), + table_id, + sparse_push_keys.data(), + sparse_push_keys.size(), + training); status.wait(); return; } @@ -1184,12 +1185,12 @@ void GeoCommunicator::SendDense(const CommContext &send_ctx) { auto &t_latest = var_latest->Get(); auto t_timestamp = var_timestamp->GetMutable(); - paddle::platform::CPUDeviceContext cpu_ctx; + phi::CPUContext cpu_ctx; auto *var_delta = delta_scope_->Var(varname); auto *t_delta = var_delta->GetMutable(); t_delta->mutable_data(t_latest.dims(), cpu_ctx.GetPlace()); - auto blas = phi::funcs::GetBlas(cpu_ctx); + auto blas = phi::funcs::GetBlas(cpu_ctx); blas.VSUB(t_latest.numel(), t_latest.data(), t_timestamp->data(), @@ -1218,7 +1219,7 @@ void GeoCommunicator::RecvDense(const CommContext &send_ctx) { RpcRecvDense(varnames, table_id, pserver_scope_.get()); // 2.1 pserver - old => delta; 2.2 latest + old => latest 2.3 old => pserver - paddle::platform::CPUDeviceContext cpu_ctx; + phi::CPUContext cpu_ctx; for (auto &varname : varnames) { auto *var_latest = recv_scope_->FindVar(varname); auto t_latest = var_latest->GetMutable(); @@ -1233,7 +1234,7 @@ void GeoCommunicator::RecvDense(const CommContext &send_ctx) { auto *t_delta = var_delta->GetMutable(); t_delta->mutable_data(t_latest->dims(), cpu_ctx.GetPlace()); - auto blas = phi::funcs::GetBlas(cpu_ctx); + auto blas = phi::funcs::GetBlas(cpu_ctx); blas.VSUB(t_latest->numel(), t_pserver.data(), t_old->data(), @@ -1334,7 +1335,7 @@ void GeoCommunicator::SendSparse(const std::string &varname, auto *t_old = var_old->GetMutable(); auto dims1 = t_latest.dims()[1]; - paddle::platform::CPUDeviceContext cpu_ctx; + phi::CPUContext cpu_ctx; auto *var_delta = delta_scope_->Var(varname); auto *t_delta = var_delta->GetMutable(); @@ -1345,7 +1346,7 @@ void GeoCommunicator::SendSparse(const std::string &varname, t_delta->set_rows(sparse_ids); t_delta->set_height(t_latest.dims()[0]); - auto blas = phi::funcs::GetBlas(cpu_ctx); + auto blas = phi::funcs::GetBlas(cpu_ctx); float coefficient = 1.0 / static_cast(trainers_); std::vector push_g_vec; @@ -1419,8 +1420,8 @@ void GeoCommunicator::RecvSparse(const std::string &varname, std::vector v_delta; v_delta.resize(numel); - paddle::platform::CPUDeviceContext cpu_ctx; - auto blas = phi::funcs::GetBlas(cpu_ctx); + phi::CPUContext cpu_ctx; + auto blas = phi::funcs::GetBlas(cpu_ctx); for (auto j = 0; j < static_cast(keys.size()); ++j) { VLOG(5) << "DEBUG GeoCommunicator::RecvSparse recv sparse key" << keys[j] diff --git a/paddle/fluid/distributed/ps/service/communicator/communicator.h b/paddle/fluid/distributed/ps/service/communicator/communicator.h index 69589da8b30310082be1115cbcd2e643ea456fb1..f08208ed02d70e606d090bb5743d36b5e269e603 100644 --- a/paddle/fluid/distributed/ps/service/communicator/communicator.h +++ b/paddle/fluid/distributed/ps/service/communicator/communicator.h @@ -185,9 +185,8 @@ inline void MergeVars(const std::string &var_name, } // set output tensor to 0. - paddle::platform::CPUDeviceContext cpu_ctx; - phi::funcs::SetConstant - constant_functor; + phi::CPUContext cpu_ctx; + phi::funcs::SetConstant constant_functor; constant_functor(cpu_ctx, out_t, static_cast(0)); // sum all vars to out auto result = EigenVector::Flatten(*out_t); @@ -210,16 +209,13 @@ inline void MergeVars(const std::string &var_name, for (auto &var : vars) { inputs.push_back(&var->Get()); } - paddle::platform::CPUDeviceContext dev_ctx; + phi::CPUContext dev_ctx; if (merge_add) { - paddle::operators::math::scatter:: - MergeAdd - merge_add; + paddle::operators::math::scatter::MergeAdd merge_add; merge_add(dev_ctx, inputs, out_slr); } else { - paddle::operators::math::scatter:: - MergeAverage - merge_average; + paddle::operators::math::scatter::MergeAverage + merge_average; merge_average(dev_ctx, inputs, out_slr); } diff --git a/paddle/fluid/eager/nan_inf_utils.cc b/paddle/fluid/eager/nan_inf_utils.cc index 1d45ef696b88007940699d691647bd554bc0ad3c..6b2b9c9f34a6d00b1815886c2a5c66ed98747a45 100644 --- a/paddle/fluid/eager/nan_inf_utils.cc +++ b/paddle/fluid/eager/nan_inf_utils.cc @@ -48,8 +48,7 @@ void CheckTensorHasNanOrInf(const std::string& api_name, const Tensor& tensor) { #endif return; } - paddle::framework::details::tensor_check< - paddle::platform::CPUDeviceContext>( + paddle::framework::details::tensor_check( api_name, tensor_name, *dense_tensor, place); } } diff --git a/paddle/fluid/framework/data_device_transform_test.cu b/paddle/fluid/framework/data_device_transform_test.cu index a3a5a25eec842cb1c65c7fbd2e14f3db20bf4588..94e7918e800ef0d7bc8948e3ece381d90c64c249 100644 --- a/paddle/fluid/framework/data_device_transform_test.cu +++ b/paddle/fluid/framework/data_device_transform_test.cu @@ -90,9 +90,8 @@ REGISTER_OP_WITHOUT_GRADIENT( test_op, paddle::framework::TestOpWithKernel, paddle::framework::OpKernelTestProtoAndCheckerMaker); -REGISTER_OP_CPU_KERNEL( - test_op, - paddle::framework::TestKernel); +REGISTER_OP_CPU_KERNEL(test_op, + paddle::framework::TestKernel); REGISTER_OP_CUDA_KERNEL( test_op, paddle::framework::TestKernel); diff --git a/paddle/fluid/framework/data_layout_transform.cc b/paddle/fluid/framework/data_layout_transform.cc index 90639255c3aabf17e7130fa22080504e2d51a0d5..4bf81b46b345608b38503876a9df8e85f439b5b9 100644 --- a/paddle/fluid/framework/data_layout_transform.cc +++ b/paddle/fluid/framework/data_layout_transform.cc @@ -44,8 +44,8 @@ void CastDataLayout::apply() { auto place = ctx_->GetPlace(); if (platform::is_cpu_place(place)) { - phi::funcs::Transpose trans4; - auto* context = static_cast(ctx_); + phi::funcs::Transpose trans4; + auto* context = static_cast(ctx_); trans4(*context, in_, out_, axis_); } else { PADDLE_THROW(platform::errors::PreconditionNotMet( diff --git a/paddle/fluid/framework/data_type_transform.cc b/paddle/fluid/framework/data_type_transform.cc index 2576df3483412c576f2abd78e8bc58840021f60c..9333e246c68bc35fb7e1e5ebed5870f4069156ad 100644 --- a/paddle/fluid/framework/data_type_transform.cc +++ b/paddle/fluid/framework/data_type_transform.cc @@ -94,8 +94,8 @@ struct CastDataType { auto* out_begin = out_->mutable_data(in_.place()); if (platform::is_cpu_place(in_.place())) { - platform::Transform trans; - auto* context = static_cast(ctx_); + platform::Transform trans; + auto* context = static_cast(ctx_); trans(*context, in_begin, in_end, diff --git a/paddle/fluid/framework/details/broadcast_op_handle_test.h b/paddle/fluid/framework/details/broadcast_op_handle_test.h index 9c666d00ab9d13b27cd8e863de256ede4aa28d09..26ad71bafe6ff871cce937dc1fd40d11008a3aec 100644 --- a/paddle/fluid/framework/details/broadcast_op_handle_test.h +++ b/paddle/fluid/framework/details/broadcast_op_handle_test.h @@ -117,7 +117,7 @@ struct TestBroadcastOpHandle { for (int i = 0; i < count; ++i) { auto p = p::CPUPlace(); place_list_.push_back(p); - ctxs_.emplace_back(new p::CPUDeviceContext(p)); + ctxs_.emplace_back(new phi::CPUContext(p)); } #if defined(PADDLE_WITH_XPU_BKCL) bkcl_ctxs_.reset(nullptr); diff --git a/paddle/fluid/framework/details/gather_op_handle_test.cc b/paddle/fluid/framework/details/gather_op_handle_test.cc index ea63595cb2cfc652f3c7b41de6f68612c8b333ae..9cc1929e19ae8bf39689317a186db7b52a8cb673 100644 --- a/paddle/fluid/framework/details/gather_op_handle_test.cc +++ b/paddle/fluid/framework/details/gather_op_handle_test.cc @@ -69,7 +69,7 @@ struct TestGatherOpHandle { for (int i = 0; i < count; ++i) { auto p = p::CPUPlace(); gpu_list_.push_back(p); - ctxs_.emplace_back(new p::CPUDeviceContext(p)); + ctxs_.emplace_back(new phi::CPUContext(p)); } } } diff --git a/paddle/fluid/framework/details/nan_inf_utils_detail.cc b/paddle/fluid/framework/details/nan_inf_utils_detail.cc index cce26f1e0dca1eb9f9cf6bbf0e1ab9615c3a9c19..767f7b1e48b438cb52689c04b1428d4ec3b8ec5e 100644 --- a/paddle/fluid/framework/details/nan_inf_utils_detail.cc +++ b/paddle/fluid/framework/details/nan_inf_utils_detail.cc @@ -316,7 +316,7 @@ template <> template <> template -void TensorCheckerVisitor::apply( +void TensorCheckerVisitor::apply( typename std::enable_if< std::is_floating_point::value || std::is_same>::value || @@ -329,11 +329,11 @@ void TensorCheckerVisitor::apply( } template <> -void tensor_check(const std::string& op_type, - const std::string& var_name, - const framework::Tensor& tensor, - const platform::Place& place) { - TensorCheckerVisitor vistor( +void tensor_check(const std::string& op_type, + const std::string& var_name, + const framework::Tensor& tensor, + const platform::Place& place) { + TensorCheckerVisitor vistor( op_type, var_name, tensor, place); VisitDataType(framework::TransToProtoVarType(tensor.dtype()), vistor); } @@ -439,7 +439,7 @@ void CheckVarHasNanOrInf(const std::string& op_type, #endif return; } - tensor_check(op_type, var_name, *tensor, place); + tensor_check(op_type, var_name, *tensor, place); } void CheckVarHasNanOrInf(const std::string& op_type, diff --git a/paddle/fluid/framework/details/reduce_op_handle_test.cc b/paddle/fluid/framework/details/reduce_op_handle_test.cc index 2a7ac790e80498e8c3def65016eeae108b4d94d0..0d957bf81306f199a8eddde35e2e7821b9690765 100644 --- a/paddle/fluid/framework/details/reduce_op_handle_test.cc +++ b/paddle/fluid/framework/details/reduce_op_handle_test.cc @@ -81,7 +81,7 @@ struct TestReduceOpHandle { for (int i = 0; i < count; ++i) { auto p = p::CPUPlace(); gpu_list_.push_back(p); - ctxs_.emplace_back(new p::CPUDeviceContext(p)); + ctxs_.emplace_back(new phi::CPUContext(p)); } #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) nccl_ctxs_.reset(nullptr); diff --git a/paddle/fluid/framework/lod_tensor.h b/paddle/fluid/framework/lod_tensor.h index c0b4ac864cabcada186b06d3ef3180e5620c8848..33d293faad129882ec4867993e8ce26dc4dbcec6 100644 --- a/paddle/fluid/framework/lod_tensor.h +++ b/paddle/fluid/framework/lod_tensor.h @@ -144,7 +144,7 @@ LoDTensor LodExpand(const LoDTensor& source, auto slice = tensor.Slice(elem, elem + 1); TensorCopy(source.Slice(ins, ins + 1), platform::CPUPlace(), - platform::CPUDeviceContext(), + phi::CPUContext(), &slice); } } diff --git a/paddle/fluid/framework/op_registry_test.cc b/paddle/fluid/framework/op_registry_test.cc index a95bcdf94494363817cf36624c9fcec1040a2eae..fa0528d488297b3d868bd7658f954204ca47a446 100644 --- a/paddle/fluid/framework/op_registry_test.cc +++ b/paddle/fluid/framework/op_registry_test.cc @@ -232,9 +232,8 @@ class OpKernelTest : public paddle::framework::OpKernel { REGISTER_OP_WITHOUT_GRADIENT(op_with_kernel, paddle::framework::OpWithKernelTest, paddle::framework::OpKernelTestMaker); -REGISTER_OP_CPU_KERNEL( - op_with_kernel, - paddle::framework::OpKernelTest); +REGISTER_OP_CPU_KERNEL(op_with_kernel, + paddle::framework::OpKernelTest); REGISTER_OP_CUDA_KERNEL( op_with_kernel, @@ -264,10 +263,9 @@ TEST(OperatorRegistrar, CUDA) { } static int op_test_value = 0; - -using paddle::platform::CPUDeviceContext; using paddle::platform::CUDADeviceContext; using paddle::platform::DeviceContext; +using phi::CPUContext; namespace paddle { namespace framework { @@ -295,8 +293,7 @@ class OpMultiKernelTest : public paddle::framework::OpKernel { }; template -class OpMultiKernelTest - : public paddle::framework::OpKernel { +class OpMultiKernelTest : public paddle::framework::OpKernel { public: void Compute(const paddle::framework::ExecutionContext& ctx) const { ++op_test_value; @@ -319,7 +316,7 @@ class OpMultiKernelTest2 : public paddle::framework::OpKernel { }; template -class OpMultiKernelTest2 +class OpMultiKernelTest2 : public paddle::framework::OpKernel { public: void Compute(const paddle::framework::ExecutionContext& ctx) const { @@ -342,16 +339,14 @@ class OpMultiKernelTest2 REGISTER_OP_WITHOUT_GRADIENT(op_with_multi_kernel, paddle::framework::OpWithMultiKernelTest, paddle::framework::OpKernelTestMaker); -REGISTER_OP_KERNEL( - op_with_multi_kernel, - CPU, - paddle::platform::CPUPlace, - paddle::framework::OpMultiKernelTest); -REGISTER_OP_KERNEL( - op_with_multi_kernel, - MKLDNN, - paddle::platform::CPUPlace, - paddle::framework::OpMultiKernelTest2); +REGISTER_OP_KERNEL(op_with_multi_kernel, + CPU, + paddle::platform::CPUPlace, + paddle::framework::OpMultiKernelTest); +REGISTER_OP_KERNEL(op_with_multi_kernel, + MKLDNN, + paddle::platform::CPUPlace, + paddle::framework::OpMultiKernelTest2); REGISTER_OP_KERNEL( op_with_multi_kernel, CUDA, diff --git a/paddle/fluid/framework/operator_test.cc b/paddle/fluid/framework/operator_test.cc index d4dfd165259a2362755cd31336612429e6ca6664..ba7a5956ae0fd4c4df5be4eb5b20b0575cc87fe8 100644 --- a/paddle/fluid/framework/operator_test.cc +++ b/paddle/fluid/framework/operator_test.cc @@ -420,16 +420,13 @@ REGISTER_OP_WITHOUT_GRADIENT( REGISTER_OP_CPU_KERNEL( indicate_lod_tensor_data_type_test, - paddle::framework::EmptyTestKernel); + paddle::framework::EmptyTestKernel); REGISTER_OP_CPU_KERNEL( indicate_selected_rows_data_type_test, - paddle::framework::EmptyTestKernel); + paddle::framework::EmptyTestKernel); REGISTER_OP_CPU_KERNEL( indicate_other_data_type_test, - paddle::framework::EmptyTestKernel); + paddle::framework::EmptyTestKernel); TEST(IndicateVarDataTypeTest, lodtensor) { paddle::framework::InitDevices(); @@ -599,16 +596,14 @@ REGISTER_OP_WITHOUT_GRADIENT(get_lod_level_test, paddle::framework::GetSetLoDLevelTestMaker); REGISTER_OP_CPU_KERNEL( get_lod_level_test, - paddle::framework::EmptyTestKernel); + paddle::framework::EmptyTestKernel); REGISTER_OP_WITHOUT_GRADIENT(set_lod_level_test, paddle::framework::SetLoDLevelTest, paddle::framework::GetSetLoDLevelTestMaker); REGISTER_OP_CPU_KERNEL( set_lod_level_test, - paddle::framework::EmptyTestKernel); + paddle::framework::EmptyTestKernel); void SetGetLoDLevelTestMain(std::string op_type) { paddle::framework::InitDevices({}); diff --git a/paddle/fluid/framework/phi_utils.h b/paddle/fluid/framework/phi_utils.h index 535672f2e128840fae16049115318e8ebe1a9401..6c8e825157973592918cb2b67df25eea656acad6 100644 --- a/paddle/fluid/framework/phi_utils.h +++ b/paddle/fluid/framework/phi_utils.h @@ -66,7 +66,7 @@ struct ConvertToPhiContext { }; template <> -struct ConvertToPhiContext { +struct ConvertToPhiContext { using TYPE = phi::CPUContext; }; diff --git a/paddle/fluid/framework/selected_rows_utils_test.cc b/paddle/fluid/framework/selected_rows_utils_test.cc index db2c6c1f991b7c6b2116acdc3c08fc576d1b4155..340acf53efa9d7583361d71481fd2318993bf803 100644 --- a/paddle/fluid/framework/selected_rows_utils_test.cc +++ b/paddle/fluid/framework/selected_rows_utils_test.cc @@ -53,7 +53,7 @@ TEST_F(SelectedRowsTester, complete_dims) { TEST_F(SelectedRowsTester, SerializeAndDeseralize) { phi::SelectedRows dst_tensor; - platform::CPUDeviceContext cpu_ctx(place_); + phi::CPUContext cpu_ctx(place_); std::ostringstream oss; SerializeToStream(oss, *selected_rows_, cpu_ctx); diff --git a/paddle/fluid/framework/tensor_util.cc b/paddle/fluid/framework/tensor_util.cc index 2fe2b87fcd4aec195867ad43b7499907a62aa9c3..dd80458b624c6c8857515252f638fc7b1725788d 100644 --- a/paddle/fluid/framework/tensor_util.cc +++ b/paddle/fluid/framework/tensor_util.cc @@ -1253,7 +1253,7 @@ void TensorFromStream(std::istream& is, is.seekg(seekg, is.cur); void* buf; - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; size_t size = tensor->numel() * framework::SizeOfType(desc.data_type()); if (platform::is_gpu_place(dev_ctx.GetPlace()) || platform::is_xpu_place(dev_ctx.GetPlace()) || @@ -1336,7 +1336,7 @@ void TensorFromStream(std::istream& is, std::copy(desc.dims().begin(), desc.dims().end(), std::back_inserter(dims)); tensor->Resize(phi::make_ddim(dims)); void* buf; - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; size_t size = tensor->numel() * framework::SizeOfType(desc.data_type()); if (platform::is_gpu_place(dev_ctx.GetPlace()) || platform::is_xpu_place(dev_ctx.GetPlace()) || diff --git a/paddle/fluid/framework/tensor_util_test.cc b/paddle/fluid/framework/tensor_util_test.cc index 20fab1d20b0c06a95e4416f1c82794dabf811807..74454a5a09b7af3fb5d9ae0a4f1dc117cf1010ed 100644 --- a/paddle/fluid/framework/tensor_util_test.cc +++ b/paddle/fluid/framework/tensor_util_test.cc @@ -24,7 +24,7 @@ namespace framework { TEST(TensorCopy, Tensor) { Tensor src_tensor; Tensor dst_tensor; - platform::CPUDeviceContext cpu_ctx((platform::CPUPlace())); + phi::CPUContext cpu_ctx((platform::CPUPlace())); int* src_ptr = src_tensor.mutable_data(phi::make_ddim({3, 3}), platform::CPUPlace()); @@ -164,7 +164,7 @@ TEST(TensorFromVector, Tensor) { // Copy to CPU Tensor cpu_tensor.Resize(phi::make_ddim({3, 3})); auto cpu_place = new paddle::platform::CPUPlace(); - paddle::platform::CPUDeviceContext cpu_ctx(*cpu_place); + phi::CPUContext cpu_ctx(*cpu_place); paddle::framework::TensorFromVector(src_vec, cpu_ctx, &cpu_tensor); // Copy to GPUTensor @@ -255,20 +255,23 @@ TEST(TensorToVector, Tensor) { #endif } -TEST(TensorToVector, Tensor_bool){{paddle::framework::Tensor src; -bool* src_ptr = src.mutable_data({3, 3}, paddle::platform::CPUPlace()); -for (int i = 0; i < 3 * 3; ++i) { - src_ptr[i] = static_cast(i % 2); -} +TEST(TensorToVector, Tensor_bool) { +{ + paddle::framework::Tensor src; + bool* src_ptr = src.mutable_data({3, 3}, paddle::platform::CPUPlace()); + for (int i = 0; i < 3 * 3; ++i) { + src_ptr[i] = static_cast(i % 2); + } -paddle::platform::CPUPlace place; -std::vector dst; -paddle::framework::TensorToVector(src, &dst); + paddle::platform::CPUPlace place; + std::vector dst; + paddle::framework::TensorToVector(src, &dst); -for (int i = 0; i < 3 * 3; ++i) { - EXPECT_EQ(src_ptr[i], dst[i]); + for (int i = 0; i < 3 * 3; ++i) { + EXPECT_EQ(src_ptr[i], dst[i]); + } } -} // namespace framework + #ifdef PADDLE_WITH_CUDA { std::vector src_vec = { @@ -325,7 +328,7 @@ for (int i = 0; i < 3 * 3; ++i) { } } #endif -} // namespace paddle +} TEST(TensorFromDLPack, Tensor) { { @@ -334,7 +337,7 @@ TEST(TensorFromDLPack, Tensor) { cpu_tensor.Resize(phi::make_ddim({3, 3})); paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext cpu_ctx(cpu_place); + phi::CPUContext cpu_ctx(cpu_place); paddle::framework::TensorFromVector(src_vec, cpu_ctx, &cpu_tensor); paddle::framework::DLPackTensor dlpack_tensor(cpu_tensor, 1); @@ -360,7 +363,7 @@ TEST(TensorFromDLPack, Tensor) { // Copy to CPU Tensor cpu_tensor.Resize(phi::make_ddim({3, 3})); paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext cpu_ctx(cpu_place); + phi::CPUContext cpu_ctx(cpu_place); paddle::framework::TensorFromVector(src_vec, cpu_ctx, &cpu_tensor); // Copy to GPUTensor @@ -502,7 +505,7 @@ TEST(Tensor, FromAndToStream) { { framework::Tensor dst_tensor; auto place = new platform::CPUPlace(); - platform::CPUDeviceContext cpu_ctx(*place); + phi::CPUContext cpu_ctx(*place); std::ostringstream oss; TensorToStream(oss, src_tensor, cpu_ctx); diff --git a/paddle/fluid/imperative/gloo_context.cc b/paddle/fluid/imperative/gloo_context.cc index dd263f0f8f2fe6bdc1ffc1759464286f39291757..b6c21bead4182a246e1452b308f3d4dd13431e05 100644 --- a/paddle/fluid/imperative/gloo_context.cc +++ b/paddle/fluid/imperative/gloo_context.cc @@ -46,8 +46,8 @@ void GLOOParallelContext::Init() { int port = std::stoi(addr[1]); gloo_wrapper->SetHttpStore(host, port, "worker"); gloo_wrapper->Init(); - device_ = std::unique_ptr( - new platform::CPUDeviceContext(platform::CPUPlace())); + device_ = std::unique_ptr( + new phi::CPUContext(platform::CPUPlace())); device_->SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance() .GetAllocator(platform::CPUPlace()) .get()); @@ -200,7 +200,7 @@ void GLOOParallelContext::Broadcast(framework::Variable *src, int ring_id) { paddle::platform::DeviceContext *GLOOParallelContext::GetDeviceContext( int ring_id) { - // return the CPUDeviceContext + // return the CPUContext return device_.get(); } diff --git a/paddle/fluid/imperative/gloo_context.h b/paddle/fluid/imperative/gloo_context.h index 85aacc0d3f77be815be1fe3ffbfa5c51738c784d..5290e3d1315a418da8d29811e609b8cf53fc181a 100644 --- a/paddle/fluid/imperative/gloo_context.h +++ b/paddle/fluid/imperative/gloo_context.h @@ -64,7 +64,7 @@ class GLOOParallelContext : public ParallelContext { void AllReduce(const phi::SelectedRows& src, phi::SelectedRows* dst); private: - std::unique_ptr device_; + std::unique_ptr device_; }; } // namespace imperative diff --git a/paddle/fluid/imperative/gradient_accumulator.cc b/paddle/fluid/imperative/gradient_accumulator.cc index ba60c834f79ae5872f9176afca925ed8b1aa8379..4a8fc6a5d546ce150f1b46de7885e1a9f250dd91 100644 --- a/paddle/fluid/imperative/gradient_accumulator.cc +++ b/paddle/fluid/imperative/gradient_accumulator.cc @@ -85,9 +85,9 @@ class TensorAddFunctor : public boost::static_visitor<> { : numel_(numel), x_(x), y_(y) {} void operator()(const platform::CPUPlace& place) const { - platform::CPUDeviceContext* ctx = dynamic_cast( + phi::CPUContext* ctx = dynamic_cast( platform::DeviceContextPool::Instance().Get(place)); - auto blas = phi::funcs::GetBlas(*ctx); + auto blas = phi::funcs::GetBlas(*ctx); blas.AXPY(numel_, 1., x_, y_); } @@ -438,7 +438,7 @@ void TensorAdd(const VarType& src, VarType* dst) { place)); #endif } else if (platform::is_cpu_place(place)) { - return TensorAddImpl( + return TensorAddImpl( src_tensor, dst_tensor, place); } } @@ -455,7 +455,7 @@ void TensorAdd(const VarType& src, VarType* dst) { place)); #endif } else if (platform::is_cpu_place(place)) { - return TensorAddImpl( + return TensorAddImpl( src_tensor, dst_tensor, place); } } @@ -498,8 +498,8 @@ void SelectedRowsAddToTensor(const VarType& src, VarType* dst) { PADDLE_SELECTED_ROWS_ADD_TO_TENSOR(platform::CUDADeviceContext, double); } else { #endif - PADDLE_SELECTED_ROWS_ADD_TO_TENSOR(platform::CPUDeviceContext, float); - PADDLE_SELECTED_ROWS_ADD_TO_TENSOR(platform::CPUDeviceContext, double); + PADDLE_SELECTED_ROWS_ADD_TO_TENSOR(phi::CPUContext, float); + PADDLE_SELECTED_ROWS_ADD_TO_TENSOR(phi::CPUContext, double); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) } #endif @@ -550,8 +550,8 @@ void SelectedRowsAddTensor(const VarType& src_selected_rows_var, PADDLE_SELECTED_ROWS_ADD_TENSOR(platform::CUDADeviceContext, double); } else { #endif - PADDLE_SELECTED_ROWS_ADD_TENSOR(platform::CPUDeviceContext, float); - PADDLE_SELECTED_ROWS_ADD_TENSOR(platform::CPUDeviceContext, double); + PADDLE_SELECTED_ROWS_ADD_TENSOR(phi::CPUContext, float); + PADDLE_SELECTED_ROWS_ADD_TENSOR(phi::CPUContext, double); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) } #endif @@ -613,8 +613,8 @@ std::shared_ptr SelectedRowsMerge(const VarType& src1, PADDLE_SELECTED_ROWS_ADD(platform::CUDADeviceContext, double); } else { #endif - PADDLE_SELECTED_ROWS_ADD(platform::CPUDeviceContext, float); - PADDLE_SELECTED_ROWS_ADD(platform::CPUDeviceContext, double); + PADDLE_SELECTED_ROWS_ADD(phi::CPUContext, float); + PADDLE_SELECTED_ROWS_ADD(phi::CPUContext, double); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) } #endif diff --git a/paddle/fluid/imperative/reducer.cc b/paddle/fluid/imperative/reducer.cc index f06ed80a940f01dddc006533170a73de30b0ab59..9dd61b6f5e3cd4651cd7334ae4294c208bf57fba 100644 --- a/paddle/fluid/imperative/reducer.cc +++ b/paddle/fluid/imperative/reducer.cc @@ -53,12 +53,11 @@ void Group::DivNRanks(const platform::DeviceContext &context, int64_t nranks) { } framework::VisitDataTypeForHIP( dtype_, - DivNRanksForAllReduce( - tensor, nranks, context)); + DivNRanksForAllReduce(tensor, nranks, context)); #else - framework::VisitDataType(dtype_, - DivNRanksForAllReduce( - tensor, nranks, context)); + framework::VisitDataType( + dtype_, + DivNRanksForAllReduce(tensor, nranks, context)); #endif VLOG(4) << "after div 2" << *tensor; } else if (platform::is_xpu_place(tensor->place())) { @@ -328,11 +327,10 @@ void Group::ConcatTensors(const platform::DeviceContext &context) { "Please recompile or reinstall Paddle with CNCL support.")); #endif } else if (platform::is_cpu_place(place)) { - ConcatTensorsWithType( - static_cast(context), - dense_tensors_, - &dense_contents_, - dtype_); + ConcatTensorsWithType(static_cast(context), + dense_tensors_, + &dense_contents_, + dtype_); } else { PADDLE_THROW(platform::errors::Unimplemented( "Concat grad tensor not supported on place (%s)", place)); @@ -390,11 +388,10 @@ void Group::SplitTensors(const platform::DeviceContext &context) { "Please recompile or reinstall Paddle with CNCL support.")); #endif } else if (platform::is_cpu_place(place)) { - SplitTensorsWithType( - static_cast(context), - &dense_contents_, - &dense_tensors_, - dtype_); + SplitTensorsWithType(static_cast(context), + &dense_contents_, + &dense_tensors_, + dtype_); } else { PADDLE_THROW(platform::errors::Unimplemented( "Split grad tensor not supported on place (%s)", place)); diff --git a/paddle/fluid/inference/analysis/ir_passes/lite_subgraph_pass.cc b/paddle/fluid/inference/analysis/ir_passes/lite_subgraph_pass.cc index 4ba17aa126dc64bb16a784dfe53b2111eb821eff..e2108278b15c52364dd33c0f55cd03f4b77d9011 100644 --- a/paddle/fluid/inference/analysis/ir_passes/lite_subgraph_pass.cc +++ b/paddle/fluid/inference/analysis/ir_passes/lite_subgraph_pass.cc @@ -234,7 +234,7 @@ void LiteSubgraphPass::SetUpEngine( framework::Scope* scope, const std::vector& params) { std::ostringstream os; - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; for (const auto& param : params) { VLOG(3) << "Serialize param: " << param; PADDLE_ENFORCE_NOT_NULL( diff --git a/paddle/fluid/inference/analysis/passes/convert_to_mixed_precision.cc b/paddle/fluid/inference/analysis/passes/convert_to_mixed_precision.cc index 6b6651678f85e0c0e85c8fad6bc965bfbbc8c782..44e36647646fe44ae9f5cb9d61f5239d72270612 100644 --- a/paddle/fluid/inference/analysis/passes/convert_to_mixed_precision.cc +++ b/paddle/fluid/inference/analysis/passes/convert_to_mixed_precision.cc @@ -365,7 +365,7 @@ void ConvertToMixedPrecision(const std::string& model_file, [](framework::Scope* scope, const std::vector& params) -> std::string { std::ostringstream os; - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; for (const auto& param : params) { VLOG(3) << "Serialize param: " << param; PADDLE_ENFORCE_NOT_NULL( diff --git a/paddle/fluid/inference/lite/test_engine_lite.cc b/paddle/fluid/inference/lite/test_engine_lite.cc index dee83f70ba2a2feea5f65ad693b23ebc93d2c344..45b9d222c4c3ec62bed2928dc5916689dc3d1528 100644 --- a/paddle/fluid/inference/lite/test_engine_lite.cc +++ b/paddle/fluid/inference/lite/test_engine_lite.cc @@ -81,7 +81,7 @@ void make_fake_model(std::string* model, std::string* param) { ctx.PartialInitWithAllocator(); #else platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); #endif // Prepare variables. std::vector repetitive_params{"x", "y"}; diff --git a/paddle/fluid/inference/tensorrt/convert/test_io_converter.cc b/paddle/fluid/inference/tensorrt/convert/test_io_converter.cc index a2fe32b75f3de55363ef1942ceb156f79452af4f..d770ef5478abb5d17d2975c71ea52e26d601f6ac 100644 --- a/paddle/fluid/inference/tensorrt/convert/test_io_converter.cc +++ b/paddle/fluid/inference/tensorrt/convert/test_io_converter.cc @@ -62,7 +62,7 @@ void IOConverterTester(const platform::DeviceContext& ctx) { TEST(EngineIOConverterTester, DefaultCPU) { platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); IOConverterTester(ctx); } diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc index 8f443f6f165e590bdc05775bddc3589685f7e4b6..4a7f6cfbf0b315857f818903d967ebd6ec908ed0 100644 --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -1469,20 +1469,16 @@ namespace plat = paddle::platform; ops::ActivationOpGrad, \ ops::ActivationGradOpInplaceInferer); -#define REGISTER_ACTIVATION_CPU_KERNEL( \ - act_type, op_name, functor, grad_functor) \ - REGISTER_OP_CPU_KERNEL( \ - act_type, \ - ops::ActivationKernel>, \ - ops::ActivationKernel>); \ - REGISTER_OP_CPU_KERNEL( \ - act_type##_grad, \ - ops::ActivationGradKernel>, \ - ops::ActivationGradKernel>); +#define REGISTER_ACTIVATION_CPU_KERNEL( \ + act_type, op_name, functor, grad_functor) \ + REGISTER_OP_CPU_KERNEL( \ + act_type, \ + ops::ActivationKernel>, \ + ops::ActivationKernel>); \ + REGISTER_OP_CPU_KERNEL( \ + act_type##_grad, \ + ops::ActivationGradKernel>, \ + ops::ActivationGradKernel>); FOR_EACH_ACTIVATION_OP(REGISTER_ACTIVATION_OP); FOR_EACH_ACTIVATION_OP(REGISTER_ACTIVATION_CPU_KERNEL); diff --git a/paddle/fluid/operators/add_position_encoding_op.cc b/paddle/fluid/operators/add_position_encoding_op.cc index f58a838460ec3fa1ceb7e9cee4593118c3f6d10d..f4e7481bdd456bbfdbce0e1c5ca8eb2139e35e1e 100644 --- a/paddle/fluid/operators/add_position_encoding_op.cc +++ b/paddle/fluid/operators/add_position_encoding_op.cc @@ -122,12 +122,11 @@ REGISTER_OPERATOR( ops::AddPositionEncodingGradOpMaker); REGISTER_OPERATOR(add_position_encoding_grad, ops::AddPositionEncodingOpGrad); -REGISTER_OP_CPU_KERNEL( - add_position_encoding, - ops::AddPositionEncodingKernel, - ops::AddPositionEncodingKernel); +REGISTER_OP_CPU_KERNEL(add_position_encoding, + ops::AddPositionEncodingKernel, + ops::AddPositionEncodingKernel); REGISTER_OP_CPU_KERNEL( add_position_encoding_grad, - ops::AddPositionEncodingGradKernel, - ops::AddPositionEncodingGradKernel); + ops::AddPositionEncodingGradKernel, + ops::AddPositionEncodingGradKernel); diff --git a/paddle/fluid/operators/affine_channel_op.cc b/paddle/fluid/operators/affine_channel_op.cc index a72fd850d89bc9b588adab6338d6a4ed656a00d4..8c6360bfd89cfe96686b706dac0b2f72a7c1ca70 100644 --- a/paddle/fluid/operators/affine_channel_op.cc +++ b/paddle/fluid/operators/affine_channel_op.cc @@ -342,7 +342,7 @@ DECLARE_INPLACE_OP_INFERER(AffineChannelGradInplaceInferer, } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR(affine_channel, ops::AffineChannelOp, diff --git a/paddle/fluid/operators/affine_grid_op.cc b/paddle/fluid/operators/affine_grid_op.cc index 9efa8d0f863855f0689ecd50ba677a183bf1d07e..1977a33fc197e2220927b7f805c60bb4af258767 100644 --- a/paddle/fluid/operators/affine_grid_op.cc +++ b/paddle/fluid/operators/affine_grid_op.cc @@ -28,7 +28,7 @@ namespace operators { using Tensor = framework::Tensor; template -struct Linspace { +struct Linspace { void operator()(T start, T end, int count, @@ -282,14 +282,12 @@ REGISTER_OPERATOR(affine_grid, ops::AffineGridGradMaker); REGISTER_OPERATOR(affine_grid_grad, ops::AffineGridOpGrad); -REGISTER_OP_CPU_KERNEL( - affine_grid, - ops::AffineGridOpKernel, - ops::AffineGridOpKernel); -REGISTER_OP_CPU_KERNEL( - affine_grid_grad, - ops::AffineGridGradOpKernel, - ops::AffineGridGradOpKernel); +REGISTER_OP_CPU_KERNEL(affine_grid, + ops::AffineGridOpKernel, + ops::AffineGridOpKernel); +REGISTER_OP_CPU_KERNEL(affine_grid_grad, + ops::AffineGridGradOpKernel, + ops::AffineGridGradOpKernel); REGISTER_OP_VERSION(affine_grid) .AddCheckpoint( diff --git a/paddle/fluid/operators/allclose_op.cc b/paddle/fluid/operators/allclose_op.cc index 16c712b4a2751e4bf86dfb77ab4e00fba7151be6..aa3cd5d4149c401fc55a535941f3f748150af616 100644 --- a/paddle/fluid/operators/allclose_op.cc +++ b/paddle/fluid/operators/allclose_op.cc @@ -84,7 +84,7 @@ class AllcloseOpVarTypeInference : public framework::VarTypeInference { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; DECLARE_INFER_SHAPE_FUNCTOR(allclose, AllcloseInferShapeFunctor, diff --git a/paddle/fluid/operators/amp/alloc_float_status_op.cc b/paddle/fluid/operators/amp/alloc_float_status_op.cc index c27f0f159f51ed1fdbfa9e822e791834f0283819..fc96dd52e54a2b54ffa0eb7c0fd76cda0a2dc3d6 100644 --- a/paddle/fluid/operators/amp/alloc_float_status_op.cc +++ b/paddle/fluid/operators/amp/alloc_float_status_op.cc @@ -65,7 +65,7 @@ class AllocFloatStatusKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( alloc_float_status, diff --git a/paddle/fluid/operators/amp/check_finite_and_unscale_op.cc b/paddle/fluid/operators/amp/check_finite_and_unscale_op.cc index 20f986596063ebb798991a71f1d24384f9be65cb..8fc582c19845c421c6afa47550d0ed46fe298fd7 100644 --- a/paddle/fluid/operators/amp/check_finite_and_unscale_op.cc +++ b/paddle/fluid/operators/amp/check_finite_and_unscale_op.cc @@ -95,7 +95,7 @@ template class CheckFiniteAndUnscaleCpuKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const { - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); const auto xs = ctx.MultiInput("X"); const auto* scale = ctx.Input("Scale"); auto outs = ctx.MultiOutput("Out"); @@ -106,11 +106,10 @@ class CheckFiniteAndUnscaleCpuKernel : public framework::OpKernel { *found_inf_data = false; framework::Tensor is_finite = - ctx.AllocateTmpTensor({1}, dev_ctx); + ctx.AllocateTmpTensor({1}, dev_ctx); bool* is_finite_data = is_finite.template data(); - auto& dev = *ctx.template device_context() - .eigen_device(); + auto& dev = *ctx.template device_context().eigen_device(); T inverse_scale = Inverse(*scale_data); for (size_t i = 0; i < xs.size(); ++i) { diff --git a/paddle/fluid/operators/amp/clear_float_status_op.cc b/paddle/fluid/operators/amp/clear_float_status_op.cc index beef8076205926a0630ab01eec91d73f0f7f51c6..7bfc2d34d296e1135fb225c0a31280bdf1d9b607 100644 --- a/paddle/fluid/operators/amp/clear_float_status_op.cc +++ b/paddle/fluid/operators/amp/clear_float_status_op.cc @@ -68,7 +68,7 @@ class ClearFloatStatusKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( clear_float_status, diff --git a/paddle/fluid/operators/amp/get_float_status_op.cc b/paddle/fluid/operators/amp/get_float_status_op.cc index add662d8258ebc004decffa76fc32333ce6a5c3d..88a2affbcaabaff1633859242129b372bcaa5732 100644 --- a/paddle/fluid/operators/amp/get_float_status_op.cc +++ b/paddle/fluid/operators/amp/get_float_status_op.cc @@ -67,7 +67,7 @@ class GetFloatStatusKernel : public framework::OpKernel { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( get_float_status, diff --git a/paddle/fluid/operators/amp/update_loss_scaling_op.cc b/paddle/fluid/operators/amp/update_loss_scaling_op.cc index 346e981b3a99babf52c2f5ebe295ebc40bdb50f8..3bae775d30817379f4b8432f85cf82b53389ee55 100644 --- a/paddle/fluid/operators/amp/update_loss_scaling_op.cc +++ b/paddle/fluid/operators/amp/update_loss_scaling_op.cc @@ -169,9 +169,9 @@ decr_every_n_nan_or_inf steps and each step some gradients are infinite. }; template -class UpdateLossScalingFunctor { +class UpdateLossScalingFunctor { public: - void operator()(const platform::CPUDeviceContext& ctx, + void operator()(const phi::CPUContext& ctx, const bool* found_inf_data, const T* pre_loss_scaling_data, const int* good_in_data, @@ -203,9 +203,9 @@ class UpdateLossScalingFunctor { }; template -class LazyZeros { +class LazyZeros { public: - void operator()(const platform::CPUDeviceContext& dev_ctx, + void operator()(const phi::CPUContext& dev_ctx, const bool* found_inf_data, const std::vector& xs, const std::vector& outs) const { @@ -225,7 +225,7 @@ class LazyZeros { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( update_loss_scaling, diff --git a/paddle/fluid/operators/angle_op.cc b/paddle/fluid/operators/angle_op.cc index ae483f39e7f946582c2219da7a8c67d4b48c0dde..f925c7fa747594b66ec19010e07cc9f63284fa6e 100644 --- a/paddle/fluid/operators/angle_op.cc +++ b/paddle/fluid/operators/angle_op.cc @@ -116,20 +116,16 @@ REGISTER_OPERATOR(angle, REGISTER_OP_CPU_KERNEL( angle, - ops::AngleKernel, - ops::AngleKernel, - ops::AngleKernel>, - ops::AngleKernel>); + ops::AngleKernel, + ops::AngleKernel, + ops::AngleKernel>, + ops::AngleKernel>); REGISTER_OPERATOR(angle_grad, ops::AngleGradOp); REGISTER_OP_CPU_KERNEL( angle_grad, - ops::AngleGradKernel, - ops::AngleGradKernel, - ops::AngleGradKernel>, - ops::AngleGradKernel>); + ops::AngleGradKernel, + ops::AngleGradKernel, + ops::AngleGradKernel>, + ops::AngleGradKernel>); diff --git a/paddle/fluid/operators/array_to_lod_tensor_op.cc b/paddle/fluid/operators/array_to_lod_tensor_op.cc index ef8ab38d2f35e237f3872f9fc524a6644ff95f18..5b23ff604759acb302144c6506e6404e371051e6 100644 --- a/paddle/fluid/operators/array_to_lod_tensor_op.cc +++ b/paddle/fluid/operators/array_to_lod_tensor_op.cc @@ -51,7 +51,7 @@ struct ArrayToLoDFunctor : public boost::static_visitor { void operator()(Place place) const { auto &pool = platform::DeviceContextPool::Instance(); if (std::is_same::value) { - Apply(static_cast(pool.Get(place))); + Apply(static_cast(pool.Get(place))); } else { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) Apply(static_cast(pool.Get(place))); diff --git a/paddle/fluid/operators/assign_op_test.cc b/paddle/fluid/operators/assign_op_test.cc index fd6a793ec47323aac72bd1e1f73ca2d49cbef852..0b6245f17d38dd74210a5fefaf0c8fb814ab6589 100644 --- a/paddle/fluid/operators/assign_op_test.cc +++ b/paddle/fluid/operators/assign_op_test.cc @@ -22,7 +22,7 @@ limitations under the License. */ TEST(AssignOp, AssignLoDTensor) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); + phi::CPUContext ctx(cpu_place); paddle::framework::Variable output; paddle::operators::AssignFunctor assign_functor(&output, ctx); @@ -47,7 +47,7 @@ TEST(AssignOp, AssignLoDTensor) { TEST(AssignOp, AssignLoDTensorArray) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); + phi::CPUContext ctx(cpu_place); paddle::framework::Variable output; paddle::operators::AssignFunctor assign_functor(&output, ctx); @@ -78,7 +78,7 @@ TEST(AssignOp, AssignLoDTensorArray) { TEST(AssignOp, AssignSelectedRows) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); + phi::CPUContext ctx(cpu_place); paddle::framework::Variable output; paddle::operators::AssignFunctor assign_functor(&output, ctx); diff --git a/paddle/fluid/operators/attention_lstm_op.cc b/paddle/fluid/operators/attention_lstm_op.cc index e0d6e38e73fec6b497afc7e3beae8378ac7afc49..60e5912c4418db6d1a5e4b6f9fbe964ad2f6ec52 100644 --- a/paddle/fluid/operators/attention_lstm_op.cc +++ b/paddle/fluid/operators/attention_lstm_op.cc @@ -337,7 +337,7 @@ template class AttentionLSTMKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; auto* x = ctx.Input("X"); auto* h0 = ctx.Input("H0"); @@ -416,10 +416,10 @@ class AttentionLSTMKernel : public framework::OpKernel { T* lstm_x_data = lstm_x->mutable_data(ctx.GetPlace()); T* lstm_out_data = lstm_out->mutable_data(ctx.GetPlace()); - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); // x(TxM) * fc (Mx1) part of atten_wgt(M+D)x1 - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); phi::funcs::FCFunctor fc; fc(dev_ctx, total_T, diff --git a/paddle/fluid/operators/average_accumulates_op.cc b/paddle/fluid/operators/average_accumulates_op.cc index bb1973f96aaeac5ab51105b924bb126eec1a7618..856a703fd2b0687ce72f7927181d0ed2fbf42542 100644 --- a/paddle/fluid/operators/average_accumulates_op.cc +++ b/paddle/fluid/operators/average_accumulates_op.cc @@ -18,11 +18,10 @@ namespace paddle { namespace operators { template <> -void GetAccumulators( - const framework::ExecutionContext& ctx, - int64_t* num_updates, - int64_t* num_accumulates, - int64_t* old_num_accumulates) { +void GetAccumulators(const framework::ExecutionContext& ctx, + int64_t* num_updates, + int64_t* num_accumulates, + int64_t* old_num_accumulates) { auto* in_old_num_accumulates = ctx.Input("in_old_num_accumulates"); auto* in_num_accumulates = ctx.Input("in_num_accumulates"); auto* in_num_updates = ctx.Input("in_num_updates"); @@ -33,11 +32,10 @@ void GetAccumulators( } template <> -void SetAccumulators( - const framework::ExecutionContext& ctx, - int64_t num_updates, - int64_t num_accumulates, - int64_t old_num_accumulates) { +void SetAccumulators(const framework::ExecutionContext& ctx, + int64_t num_updates, + int64_t num_accumulates, + int64_t old_num_accumulates) { auto* out_old_num_accumulates = ctx.Output("out_old_num_accumulates"); auto* out_num_accumulates = ctx.Output("out_num_accumulates"); auto* out_num_updates = ctx.Output("out_num_updates"); @@ -217,7 +215,6 @@ REGISTER_OPERATOR( ops::AverageAccumulatesOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - average_accumulates, - ops::AverageAccumulatesKernel, - ops::AverageAccumulatesKernel); +REGISTER_OP_CPU_KERNEL(average_accumulates, + ops::AverageAccumulatesKernel, + ops::AverageAccumulatesKernel); diff --git a/paddle/fluid/operators/batch_fc_op.cc b/paddle/fluid/operators/batch_fc_op.cc index d8c11c04287c283b6b7fc0b9dad1878822cad43d..38504e3ecdf189ac5261e2697bc352636b968619 100644 --- a/paddle/fluid/operators/batch_fc_op.cc +++ b/paddle/fluid/operators/batch_fc_op.cc @@ -166,7 +166,6 @@ REGISTER_OPERATOR(batch_fc_grad, ops::BatchFCGradOp, ops::BatchFCGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - batch_fc, - ops::BatchFCKernel, - ops::BatchFCKernel); +REGISTER_OP_CPU_KERNEL(batch_fc, + ops::BatchFCKernel, + ops::BatchFCKernel); diff --git a/paddle/fluid/operators/beam_search_decode_op.h b/paddle/fluid/operators/beam_search_decode_op.h index f30b4e2379ef7f3441dc0cdbe29daff3914e5d0b..2800ef3907407643faa4a85d84ce7fc56c2585bd 100644 --- a/paddle/fluid/operators/beam_search_decode_op.h +++ b/paddle/fluid/operators/beam_search_decode_op.h @@ -141,7 +141,7 @@ void BeamSearchDecoder::ConvertSentenceVectorToLodTensor( auto cpu_place = std::unique_ptr( new paddle::platform::CPUPlace()); - paddle::platform::CPUDeviceContext cpu_ctx(*cpu_place); + phi::CPUContext cpu_ctx(*cpu_place); framework::LoD lod; lod.push_back(source_level_lod); diff --git a/paddle/fluid/operators/beam_search_op.cc b/paddle/fluid/operators/beam_search_op.cc index 3a2526fd52063b25d04107286e43a2fe80759f25..49ad3d166d9086316f019c1fe99e6e1a28da4bb5 100644 --- a/paddle/fluid/operators/beam_search_op.cc +++ b/paddle/fluid/operators/beam_search_op.cc @@ -143,9 +143,8 @@ REGISTER_OPERATOR(beam_search, ops::BeamSearchOp, ops::BeamSearchOpMaker, ops::BeamSearchInferVarType); -REGISTER_OP_CPU_KERNEL( - beam_search, - ops::BeamSearchOpKernel, - ops::BeamSearchOpKernel, - ops::BeamSearchOpKernel, - ops::BeamSearchOpKernel); +REGISTER_OP_CPU_KERNEL(beam_search, + ops::BeamSearchOpKernel, + ops::BeamSearchOpKernel, + ops::BeamSearchOpKernel, + ops::BeamSearchOpKernel); diff --git a/paddle/fluid/operators/bmm_op.cc b/paddle/fluid/operators/bmm_op.cc index a24d727e82727c93482ca8b00668a7215e791ea5..8cacc3c4f2277ae8a40f9990479c652e7b08948a 100644 --- a/paddle/fluid/operators/bmm_op.cc +++ b/paddle/fluid/operators/bmm_op.cc @@ -172,11 +172,9 @@ REGISTER_OPERATOR(bmm, ops::BmmOpGradMaker, ops::BmmOpGradMaker); REGISTER_OPERATOR(bmm_grad, ops::BmmOpGrad); -REGISTER_OP_CPU_KERNEL( - bmm, - ops::BmmKernel, - ops::BmmKernel); -REGISTER_OP_CPU_KERNEL( - bmm_grad, - ops::BmmGradKernel, - ops::BmmGradKernel); +REGISTER_OP_CPU_KERNEL(bmm, + ops::BmmKernel, + ops::BmmKernel); +REGISTER_OP_CPU_KERNEL(bmm_grad, + ops::BmmGradKernel, + ops::BmmGradKernel); diff --git a/paddle/fluid/operators/bpr_loss_op.cc b/paddle/fluid/operators/bpr_loss_op.cc index 7362a2e6530c38fa8506e0e9b37f119f7b313708..20ea0b187f64e2c3d9061427b20c37aaaec70af9 100644 --- a/paddle/fluid/operators/bpr_loss_op.cc +++ b/paddle/fluid/operators/bpr_loss_op.cc @@ -176,7 +176,7 @@ class BprLossGradMaker : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPUCtx = paddle::platform::CPUDeviceContext; +using CPUCtx = phi::CPUContext; REGISTER_OPERATOR(bpr_loss, ops::BprLossOp, diff --git a/paddle/fluid/operators/cast_op.cc b/paddle/fluid/operators/cast_op.cc index 4245c336e5dcc420b776b02c18c82985bee5ea89..b3903da7c3f2a04297e89b61b3700d6e3e3aa0d8 100644 --- a/paddle/fluid/operators/cast_op.cc +++ b/paddle/fluid/operators/cast_op.cc @@ -141,7 +141,7 @@ class CastOp : public framework::OperatorWithKernel { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; // cast use phi kernel, so no need to REGISTER_OP_CPU_KERNEL here. REGISTER_OPERATOR(cast, diff --git a/paddle/fluid/operators/center_loss_op.cc b/paddle/fluid/operators/center_loss_op.cc index a3a67177e2b47f1525403cd63d5806911656de0b..15cc71565091cb764662885b22216d43a34ddeb3 100644 --- a/paddle/fluid/operators/center_loss_op.cc +++ b/paddle/fluid/operators/center_loss_op.cc @@ -146,7 +146,7 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERER(CenterLossGradNoNeedBufVarsInferer, "X"); } // namespace paddle namespace ops = paddle::operators; -using CPUCtx = paddle::platform::CPUDeviceContext; +using CPUCtx = phi::CPUContext; REGISTER_OPERATOR(center_loss, ops::CenterLossOp, diff --git a/paddle/fluid/operators/cinn/cinn_instruction_run_op.cc b/paddle/fluid/operators/cinn/cinn_instruction_run_op.cc index 644de7e191faab6835f3f7ab4f55ba7b45b4e76d..b7600cbb4af41be11ac2f4abb7eab572e587a919 100644 --- a/paddle/fluid/operators/cinn/cinn_instruction_run_op.cc +++ b/paddle/fluid/operators/cinn/cinn_instruction_run_op.cc @@ -113,13 +113,11 @@ It accomplishes the execution of the instruction according to the following step } // namespace paddle::operators namespace ops = paddle::operators; -using CPUDeviceContext = paddle::platform::CPUDeviceContext; REGISTER_OPERATOR( cinn_instruction_run, ops::CinnInstructionRunOp, ops::CinnInstructionRunOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - cinn_instruction_run, - ops::CinnInstructionRunOpKernel); +REGISTER_OP_CPU_KERNEL(cinn_instruction_run, + ops::CinnInstructionRunOpKernel); diff --git a/paddle/fluid/operators/cinn/cinn_launch_op.cc b/paddle/fluid/operators/cinn/cinn_launch_op.cc index 4e0ed2cfb199c89b38b17753677e4c41c8b2bb60..cd0a31dc0cddd67f0d79b8c5961c4130574e360d 100644 --- a/paddle/fluid/operators/cinn/cinn_launch_op.cc +++ b/paddle/fluid/operators/cinn/cinn_launch_op.cc @@ -189,6 +189,5 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); /* see [Why use single type kernel] */ -REGISTER_OP_CPU_KERNEL( - cinn_launch, - ops::CinnLaunchOpKernel); +REGISTER_OP_CPU_KERNEL(cinn_launch, + ops::CinnLaunchOpKernel); diff --git a/paddle/fluid/operators/clip_by_norm_op.cc b/paddle/fluid/operators/clip_by_norm_op.cc index 9ce6f7bebc8370147a30a3185a12299b4a2b6dd0..cfb56a4b2a6b1bb0238dacdfde625a34e5af6d38 100644 --- a/paddle/fluid/operators/clip_by_norm_op.cc +++ b/paddle/fluid/operators/clip_by_norm_op.cc @@ -19,6 +19,5 @@ REGISTER_OP_WITHOUT_GRADIENT(clip_by_norm, ops::ClipByNormOp, ops::ClipByNormOpMaker); -REGISTER_OP_CPU_KERNEL( - clip_by_norm, - ops::ClipByNormKernel); +REGISTER_OP_CPU_KERNEL(clip_by_norm, + ops::ClipByNormKernel); diff --git a/paddle/fluid/operators/coalesce_tensor_op.cc b/paddle/fluid/operators/coalesce_tensor_op.cc index 5c0f5c39a34e5749bdf4f2ec545946bcb9d1ba38..561d2696fef8500c2125befb410f86f51a42e209 100644 --- a/paddle/fluid/operators/coalesce_tensor_op.cc +++ b/paddle/fluid/operators/coalesce_tensor_op.cc @@ -511,11 +511,10 @@ REGISTER_OPERATOR(coalesce_tensor, paddle::operators::CoalesceTensorOpMaker); namespace ops = paddle::operators; namespace plat = paddle::platform; -REGISTER_OP_CPU_KERNEL( - coalesce_tensor, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel); +REGISTER_OP_CPU_KERNEL(coalesce_tensor, + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) REGISTER_OP_CUDA_KERNEL( @@ -550,20 +549,18 @@ REGISTER_OP_XPU_KERNEL( #if defined(PADDLE_WITH_ASCEND_CL) REGISTER_OP_NPU_KERNEL( coalesce_tensor, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel); + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel); #endif #if defined(PADDLE_WITH_MLU) REGISTER_OP_MLU_KERNEL( coalesce_tensor, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel, - ops::CoalesceTensorOpKernel); + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel, + ops::CoalesceTensorOpKernel); #endif REGISTER_OP_VERSION(coalesce_tensor) diff --git a/paddle/fluid/operators/collective/allreduce_op.cc b/paddle/fluid/operators/collective/allreduce_op.cc index 6c365292f54fdcf847c75537cebe14c54831c10b..b3351dc82b7e755d43def2976f2aaf89edaa543c 100644 --- a/paddle/fluid/operators/collective/allreduce_op.cc +++ b/paddle/fluid/operators/collective/allreduce_op.cc @@ -73,10 +73,9 @@ REGISTER_OP_WITHOUT_GRADIENT(allreduce, ops::AllReduceOp, ops::AllReduceOpMaker); -REGISTER_OP_CPU_KERNEL( - allreduce, - ops::AllReduceOpKernel, - ops::AllReduceOpKernel, - ops::AllReduceOpKernel, - ops::AllReduceOpKernel, - ops::AllReduceOpKernel); +REGISTER_OP_CPU_KERNEL(allreduce, + ops::AllReduceOpKernel, + ops::AllReduceOpKernel, + ops::AllReduceOpKernel, + ops::AllReduceOpKernel, + ops::AllReduceOpKernel); diff --git a/paddle/fluid/operators/complex_op.cc b/paddle/fluid/operators/complex_op.cc index ebd0b2334529dfd57d34c99d6cb8770c4dce3df7..d6d93fe958118769b303ae95b374a6d81bbbb941 100644 --- a/paddle/fluid/operators/complex_op.cc +++ b/paddle/fluid/operators/complex_op.cc @@ -143,12 +143,10 @@ REGISTER_OPERATOR(complex, REGISTER_OPERATOR(complex_grad, ops::ComplexGradOp); -REGISTER_OP_CPU_KERNEL( - complex, - ops::ComplexKernel, - ops::ComplexKernel); - -REGISTER_OP_CPU_KERNEL( - complex_grad, - ops::ComplexGradKernel, - ops::ComplexGradKernel); +REGISTER_OP_CPU_KERNEL(complex, + ops::ComplexKernel, + ops::ComplexKernel); + +REGISTER_OP_CPU_KERNEL(complex_grad, + ops::ComplexGradKernel, + ops::ComplexGradKernel); diff --git a/paddle/fluid/operators/complex_view_op.cc b/paddle/fluid/operators/complex_view_op.cc index 344b2a1c48ad409723096389da61d4d0ff366330..6bdd2b48c450361051c9ea3168233355be4bf614 100644 --- a/paddle/fluid/operators/complex_view_op.cc +++ b/paddle/fluid/operators/complex_view_op.cc @@ -161,12 +161,10 @@ REGISTER_OPERATOR(as_real, ops::AsRealGradMaker, ops::AsRealGradMaker); -REGISTER_OP_CPU_KERNEL( - as_complex, - ops::AsComplexKernel, - ops::AsComplexKernel); - -REGISTER_OP_CPU_KERNEL( - as_real, - ops::AsRealKernel, - ops::AsRealKernel); +REGISTER_OP_CPU_KERNEL(as_complex, + ops::AsComplexKernel, + ops::AsComplexKernel); + +REGISTER_OP_CPU_KERNEL(as_real, + ops::AsRealKernel, + ops::AsRealKernel); diff --git a/paddle/fluid/operators/cos_sim_op.cc b/paddle/fluid/operators/cos_sim_op.cc index e6ecf6675cba909224bb4c01a17b33ab94e4498d..e3228104de38b96fa295c71f8dae7c564f7c8226 100644 --- a/paddle/fluid/operators/cos_sim_op.cc +++ b/paddle/fluid/operators/cos_sim_op.cc @@ -249,8 +249,6 @@ REGISTER_OPERATOR(cos_sim, ops::CosSimGradOpMaker, ops::CosSimGradOpMaker); REGISTER_OPERATOR(cos_sim_grad, ops::CosSimOpGrad); -REGISTER_OP_CPU_KERNEL( - cos_sim, ops::CosSimKernel); -REGISTER_OP_CPU_KERNEL( - cos_sim_grad, - ops::CosSimGradKernel); +REGISTER_OP_CPU_KERNEL(cos_sim, ops::CosSimKernel); +REGISTER_OP_CPU_KERNEL(cos_sim_grad, + ops::CosSimGradKernel); diff --git a/paddle/fluid/operators/crf_decoding_op.cc b/paddle/fluid/operators/crf_decoding_op.cc index 3bead0127b82311fa92e183b77462c4f5d5877d6..ee3ff671ede2d7823ae2ee726776d56dd2502c54 100644 --- a/paddle/fluid/operators/crf_decoding_op.cc +++ b/paddle/fluid/operators/crf_decoding_op.cc @@ -215,7 +215,6 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(crf_decoding, ops::CRFDecodingOp, ops::CRFDecodingOpMaker); -REGISTER_OP_CPU_KERNEL( - crf_decoding, - ops::CRFDecodingOpKernel, - ops::CRFDecodingOpKernel); +REGISTER_OP_CPU_KERNEL(crf_decoding, + ops::CRFDecodingOpKernel, + ops::CRFDecodingOpKernel); diff --git a/paddle/fluid/operators/crop_op.cc b/paddle/fluid/operators/crop_op.cc index d1358ca2f44e89e15f6eb55b6aca865cd4a22446..bdc1f61fbe0ebcfd6b0116dab80172c00a2b9ec6 100644 --- a/paddle/fluid/operators/crop_op.cc +++ b/paddle/fluid/operators/crop_op.cc @@ -223,14 +223,12 @@ REGISTER_OPERATOR(crop, ops::CropGradOpMaker, ops::GropNoNeedBufferVarInferer); REGISTER_OPERATOR(crop_grad, ops::CropOpGrad); -REGISTER_OP_CPU_KERNEL( - crop, - ops::CropKernel, - ops::CropKernel); -REGISTER_OP_CPU_KERNEL( - crop_grad, - ops::CropGradKernel, - ops::CropGradKernel); +REGISTER_OP_CPU_KERNEL(crop, + ops::CropKernel, + ops::CropKernel); +REGISTER_OP_CPU_KERNEL(crop_grad, + ops::CropGradKernel, + ops::CropGradKernel); REGISTER_OP_CUDA_KERNEL( crop, diff --git a/paddle/fluid/operators/crop_tensor_op.cc b/paddle/fluid/operators/crop_tensor_op.cc index 9422de60934414734f704025504321a79c075900..f72175d4d53387da1d303bba0ef9dd253df28613 100644 --- a/paddle/fluid/operators/crop_tensor_op.cc +++ b/paddle/fluid/operators/crop_tensor_op.cc @@ -320,18 +320,16 @@ REGISTER_OPERATOR(crop_tensor, ops::CropTensorGradOpMaker, ops::CropTensorGradOpMaker); REGISTER_OPERATOR(crop_tensor_grad, ops::CropTensorOpGrad); -REGISTER_OP_CPU_KERNEL( - crop_tensor, - ops::CropTensorKernel, - ops::CropTensorKernel, - ops::CropTensorKernel, - ops::CropTensorKernel); -REGISTER_OP_CPU_KERNEL( - crop_tensor_grad, - ops::CropTensorGradKernel, - ops::CropTensorGradKernel, - ops::CropTensorGradKernel, - ops::CropTensorGradKernel); +REGISTER_OP_CPU_KERNEL(crop_tensor, + ops::CropTensorKernel, + ops::CropTensorKernel, + ops::CropTensorKernel, + ops::CropTensorKernel); +REGISTER_OP_CPU_KERNEL(crop_tensor_grad, + ops::CropTensorGradKernel, + ops::CropTensorGradKernel, + ops::CropTensorGradKernel, + ops::CropTensorGradKernel); REGISTER_OP_CUDA_KERNEL( crop_tensor, diff --git a/paddle/fluid/operators/cross_entropy_op.cc b/paddle/fluid/operators/cross_entropy_op.cc index 5c0c2794bd65284080d7455f6e9bbd1b785c5bd8..0d98f5b75e4fb961b2a70ded655a42ccc5b03c14 100644 --- a/paddle/fluid/operators/cross_entropy_op.cc +++ b/paddle/fluid/operators/cross_entropy_op.cc @@ -421,7 +421,7 @@ class CrossEntropyGradOpMaker2 : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPUCtx = paddle::platform::CPUDeviceContext; +using CPUCtx = phi::CPUContext; REGISTER_OPERATOR(cross_entropy, ops::CrossEntropyOpBase, diff --git a/paddle/fluid/operators/ctc_align_op.cc b/paddle/fluid/operators/ctc_align_op.cc index 6d3da9982051774ededf4bb0935f7e64d4559b3b..dbab71e1619ec144c4bbd6671e5d8fd723aad6aa 100644 --- a/paddle/fluid/operators/ctc_align_op.cc +++ b/paddle/fluid/operators/ctc_align_op.cc @@ -129,7 +129,6 @@ REGISTER_OPERATOR( ops::CTCAlignOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - ctc_align, - ops::CTCAlignKernel, - ops::CTCAlignKernel); +REGISTER_OP_CPU_KERNEL(ctc_align, + ops::CTCAlignKernel, + ops::CTCAlignKernel); diff --git a/paddle/fluid/operators/cum_op.cc b/paddle/fluid/operators/cum_op.cc index 169f1919a7539f957bacc45a664a5eeaee5fc6c3..b42f26342ab9799ab1fe778585a38820fcb4fe06 100644 --- a/paddle/fluid/operators/cum_op.cc +++ b/paddle/fluid/operators/cum_op.cc @@ -145,7 +145,7 @@ class LogcumsumexpGradMaker : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; DECLARE_INFER_SHAPE_FUNCTOR(cumsum, CumsumInferShapeFunctor, PD_INFER_META(phi::CumInferMeta)); diff --git a/paddle/fluid/operators/data_norm_op.cc b/paddle/fluid/operators/data_norm_op.cc index e0997635cb42cba60cab7ff4b68b5321bcaf73bb..6685e54e43b603d8f006cc535207cb15b509a5c0 100644 --- a/paddle/fluid/operators/data_norm_op.cc +++ b/paddle/fluid/operators/data_norm_op.cc @@ -287,8 +287,7 @@ The required data format for this layer is one of the following: }; template -class DataNormKernel - : public framework::OpKernel { +class DataNormKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &ctx) const override { // const bool is_test = ctx.Attr("is_test"); @@ -533,8 +532,7 @@ class DataNormGradOp : public framework::OperatorWithKernel { }; template -class DataNormGradKernel - : public framework::OpKernel { +class DataNormGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &ctx) const override { const auto *x = ctx.Input("X"); @@ -788,14 +786,12 @@ REGISTER_OPERATOR(data_norm, ops::DataNormGradMaker); REGISTER_OPERATOR(data_norm_grad, ops::DataNormGradOp); -REGISTER_OP_CPU_KERNEL( - data_norm, - ops::DataNormKernel, - ops::DataNormKernel); -REGISTER_OP_CPU_KERNEL( - data_norm_grad, - ops::DataNormGradKernel, - ops::DataNormGradKernel); +REGISTER_OP_CPU_KERNEL(data_norm, + ops::DataNormKernel, + ops::DataNormKernel); +REGISTER_OP_CPU_KERNEL(data_norm_grad, + ops::DataNormGradKernel, + ops::DataNormGradKernel); REGISTER_OP_VERSION(data_norm).AddCheckpoint( R"ROC( upgrad data_norm op by adding scale_w to support scale and shift.)ROC", diff --git a/paddle/fluid/operators/deformable_psroi_pooling_op.cc b/paddle/fluid/operators/deformable_psroi_pooling_op.cc index 45ed3642f10663d16ced1733773deaf88e4ca1b3..f83a4c04a81627d2a20aa8c55c44c2c024938ca2 100644 --- a/paddle/fluid/operators/deformable_psroi_pooling_op.cc +++ b/paddle/fluid/operators/deformable_psroi_pooling_op.cc @@ -349,7 +349,7 @@ class DeformablePSROIPoolGradOp : public framework::OperatorWithKernel { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( deformable_psroi_pooling, ops::DeformablePSROIPoolOp, diff --git a/paddle/fluid/operators/dequantize_abs_max_op.cc b/paddle/fluid/operators/dequantize_abs_max_op.cc index 1c784d9891b4454abb3a62834635d9ba86451604..64807329a4043a97c4f4dd43466916e0b87ee745 100644 --- a/paddle/fluid/operators/dequantize_abs_max_op.cc +++ b/paddle/fluid/operators/dequantize_abs_max_op.cc @@ -33,8 +33,8 @@ namespace paddle { namespace operators { template -struct DequantizeFunctor { - void operator()(const platform::CPUDeviceContext& dev_ctx, +struct DequantizeFunctor { + void operator()(const phi::CPUContext& dev_ctx, const framework::Tensor* in, const framework::Tensor* scale, float max_range, @@ -49,8 +49,8 @@ struct DequantizeFunctor { } }; -template struct DequantizeFunctor; -template struct DequantizeFunctor; +template struct DequantizeFunctor; +template struct DequantizeFunctor; class DequantizeMaxAbsOp : public framework::OperatorWithKernel { public: @@ -102,7 +102,7 @@ $$Out = \frac{scale*X}{ max\_range }$$ } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( dequantize_abs_max, diff --git a/paddle/fluid/operators/dequantize_log_op.cc b/paddle/fluid/operators/dequantize_log_op.cc index 28d218ed3a85a7818ab7e55f3cb8d834175ffc61..c80c050b14afd75881a8a8c424291dd3d1d207cc 100644 --- a/paddle/fluid/operators/dequantize_log_op.cc +++ b/paddle/fluid/operators/dequantize_log_op.cc @@ -32,8 +32,8 @@ namespace paddle { namespace operators { template -struct DequantizeFunctor { - void operator()(const platform::CPUDeviceContext& dev_ctx, +struct DequantizeFunctor { + void operator()(const phi::CPUContext& dev_ctx, const framework::Tensor* in, const framework::Tensor* dict, framework::Tensor* out) { @@ -51,7 +51,7 @@ struct DequantizeFunctor { } }; -template struct DequantizeFunctor; +template struct DequantizeFunctor; class DequantizeLogOp : public framework::OperatorWithKernel { public: @@ -108,7 +108,7 @@ This calculation is an opposite operation of QuantizeLogOp: } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( dequantize_log, diff --git a/paddle/fluid/operators/detection/bipartite_match_op.cc b/paddle/fluid/operators/detection/bipartite_match_op.cc index 86b18f8920b875f922de59008b820c6177958d52..ef824d2d8cdcd7314df3f94e62ece6ebf25476ec 100644 --- a/paddle/fluid/operators/detection/bipartite_match_op.cc +++ b/paddle/fluid/operators/detection/bipartite_match_op.cc @@ -200,7 +200,7 @@ class BipartiteMatchKernel : public framework::OpKernel { auto* match_indices = context.Output("ColToRowMatchIndices"); auto* match_dist = context.Output("ColToRowMatchDist"); - auto& dev_ctx = context.device_context(); + auto& dev_ctx = context.device_context(); auto col = dist_mat->dims()[1]; @@ -216,9 +216,9 @@ class BipartiteMatchKernel : public framework::OpKernel { match_indices->mutable_data({n, col}, context.GetPlace()); match_dist->mutable_data({n, col}, context.GetPlace()); - phi::funcs::SetConstant iset; + phi::funcs::SetConstant iset; iset(dev_ctx, match_indices, static_cast(-1)); - phi::funcs::SetConstant tset; + phi::funcs::SetConstant tset; tset(dev_ctx, match_dist, static_cast(0)); int* indices = match_indices->data(); diff --git a/paddle/fluid/operators/detection/box_clip_op.cc b/paddle/fluid/operators/detection/box_clip_op.cc index ade3ed5f4de26c50aa6ca8aa46affd095d5a594e..cd17a8c9883df688e5c611599b6801a2abc7f0c3 100644 --- a/paddle/fluid/operators/detection/box_clip_op.cc +++ b/paddle/fluid/operators/detection/box_clip_op.cc @@ -104,7 +104,6 @@ REGISTER_OPERATOR( ops::BoxClipOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - box_clip, - ops::BoxClipKernel, - ops::BoxClipKernel); +REGISTER_OP_CPU_KERNEL(box_clip, + ops::BoxClipKernel, + ops::BoxClipKernel); diff --git a/paddle/fluid/operators/detection/box_clip_op.h b/paddle/fluid/operators/detection/box_clip_op.h index e27dd30896852c03aa05a9a5154801be5591a309..5c816ee3eb5e296f5fb12a1aff1840f4aa7d6933 100644 --- a/paddle/fluid/operators/detection/box_clip_op.h +++ b/paddle/fluid/operators/detection/box_clip_op.h @@ -29,8 +29,7 @@ class BoxClipKernel : public framework::OpKernel { auto* input_box = context.Input("Input"); auto* im_info = context.Input("ImInfo"); auto* output_box = context.Output("Output"); - auto& dev_ctx = - context.template device_context(); + auto& dev_ctx = context.template device_context(); output_box->mutable_data(context.GetPlace()); if (input_box->lod().size()) { PADDLE_ENFORCE_EQ(input_box->lod().size(), diff --git a/paddle/fluid/operators/detection/box_coder_op.cc b/paddle/fluid/operators/detection/box_coder_op.cc index 87edd80143a5562bf648b0612bf676f78d6c0b40..64aa86315622fb5441f7e00d6963f295dfffdc81 100644 --- a/paddle/fluid/operators/detection/box_coder_op.cc +++ b/paddle/fluid/operators/detection/box_coder_op.cc @@ -251,7 +251,6 @@ REGISTER_OPERATOR( ops::BoxCoderOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - box_coder, - ops::BoxCoderKernel, - ops::BoxCoderKernel); +REGISTER_OP_CPU_KERNEL(box_coder, + ops::BoxCoderKernel, + ops::BoxCoderKernel); diff --git a/paddle/fluid/operators/detection/box_decoder_and_assign_op.cc b/paddle/fluid/operators/detection/box_decoder_and_assign_op.cc index 05a44dda32a54e573b1018edd1cc47ada5cd9fbe..d641a6fd41ef7324328d5be6fa95c0a8074c7d0e 100644 --- a/paddle/fluid/operators/detection/box_decoder_and_assign_op.cc +++ b/paddle/fluid/operators/detection/box_decoder_and_assign_op.cc @@ -227,7 +227,6 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - box_decoder_and_assign, - ops::BoxDecoderAndAssignKernel, - ops::BoxDecoderAndAssignKernel); +REGISTER_OP_CPU_KERNEL(box_decoder_and_assign, + ops::BoxDecoderAndAssignKernel, + ops::BoxDecoderAndAssignKernel); diff --git a/paddle/fluid/operators/detection/generate_mask_labels_op.cc b/paddle/fluid/operators/detection/generate_mask_labels_op.cc index 93e9111f1ac619b2f7909d1e23cd2bc7c532e596..5473a57902b87e4f2137e7024d89bcbc0af5c1f8 100644 --- a/paddle/fluid/operators/detection/generate_mask_labels_op.cc +++ b/paddle/fluid/operators/detection/generate_mask_labels_op.cc @@ -122,7 +122,7 @@ class GenerateMaskLabelsOp : public framework::OperatorWithKernel { * to encode class specific mask targets. */ template -static inline void ExpandMaskTarget(const platform::CPUDeviceContext& ctx, +static inline void ExpandMaskTarget(const phi::CPUContext& ctx, const Tensor& masks, const Tensor& mask_class_labels, const int resolution, @@ -150,7 +150,7 @@ static inline void ExpandMaskTarget(const platform::CPUDeviceContext& ctx, } template -std::vector SampleMaskForOneImage(const platform::CPUDeviceContext& ctx, +std::vector SampleMaskForOneImage(const phi::CPUContext& ctx, const Tensor& im_info, const Tensor& gt_classes, const Tensor& is_crowd, @@ -391,7 +391,7 @@ class GenerateMaskLabelsKernel : public framework::OpKernel { std::vector lod0(1, 0); int64_t num_mask = 0; - auto& dev_ctx = ctx.device_context(); + auto& dev_ctx = ctx.device_context(); auto gt_classes_lod = gt_classes->lod().back(); auto is_crowd_lod = is_crowd->lod().back(); diff --git a/paddle/fluid/operators/detection/generate_proposal_labels_op.cc b/paddle/fluid/operators/detection/generate_proposal_labels_op.cc index 749e88c0a9975aa84dbf8f968d6194a741e9096d..7376e0993a506dac28a2a67fe9a80fb68f689f17 100644 --- a/paddle/fluid/operators/detection/generate_proposal_labels_op.cc +++ b/paddle/fluid/operators/detection/generate_proposal_labels_op.cc @@ -168,7 +168,7 @@ class GenerateProposalLabelsOp : public framework::OperatorWithKernel { }; template -void Concat(const platform::CPUDeviceContext& context, +void Concat(const phi::CPUContext& context, const Tensor& in_tensor_a, const Tensor& in_tensor_b, Tensor* out_tensor) { @@ -176,24 +176,23 @@ void Concat(const platform::CPUDeviceContext& context, std::vector inputs; inputs.emplace_back(in_tensor_a); inputs.emplace_back(in_tensor_b); - math::ConcatFunctor concat_functor; + math::ConcatFunctor concat_functor; concat_functor(context, inputs, axis, out_tensor); } template -std::vector> SampleFgBgGt( - const platform::CPUDeviceContext& context, - Tensor* iou, - const Tensor& is_crowd, - const int batch_size_per_im, - const float fg_fraction, - const float fg_thresh, - const float bg_thresh_hi, - const float bg_thresh_lo, - std::minstd_rand engine, - const bool use_random, - const bool is_cascade_rcnn, - const Tensor& rpn_rois) { +std::vector> SampleFgBgGt(const phi::CPUContext& context, + Tensor* iou, + const Tensor& is_crowd, + const int batch_size_per_im, + const float fg_fraction, + const float fg_thresh, + const float bg_thresh_hi, + const float bg_thresh_lo, + std::minstd_rand engine, + const bool use_random, + const bool is_cascade_rcnn, + const Tensor& rpn_rois) { std::vector fg_inds; std::vector bg_inds; std::vector mapped_gt_inds; @@ -286,7 +285,7 @@ std::vector> SampleFgBgGt( } template -void GatherBoxesLabels(const platform::CPUDeviceContext& context, +void GatherBoxesLabels(const phi::CPUContext& context, const Tensor& boxes, const Tensor& max_overlap, const Tensor& gt_boxes, @@ -335,7 +334,7 @@ void GatherBoxesLabels(const platform::CPUDeviceContext& context, template std::vector SampleRoisForOneImage( - const platform::CPUDeviceContext& context, + const phi::CPUContext& context, const Tensor& rpn_rois_in, const Tensor& gt_classes, const Tensor& is_crowd, @@ -372,7 +371,7 @@ std::vector SampleRoisForOneImage( Tensor roi_filter; // Tensor box_filter; if (keep.numel() == 0) { - phi::funcs::SetConstant set_zero; + phi::funcs::SetConstant set_zero; roi_filter.mutable_data({proposals_num, kBoxDim}, context.GetPlace()); set_zero(context, &roi_filter, static_cast(0)); } else { @@ -597,7 +596,7 @@ class GenerateProposalLabelsKernel : public framework::OpKernel { std::vector lod0(1, 0); int64_t num_rois = 0; - auto& dev_ctx = context.device_context(); + auto& dev_ctx = context.device_context(); auto rpn_rois_lod = rpn_rois->lod().back(); auto gt_classes_lod = gt_classes->lod().back(); diff --git a/paddle/fluid/operators/detection/generate_proposals_op.cc b/paddle/fluid/operators/detection/generate_proposals_op.cc index ba213f10852e79d5ab58da2e6d784c7f7631c852..29d7347f1ba75cb20f1c7ce25c5cd7163c53c063 100644 --- a/paddle/fluid/operators/detection/generate_proposals_op.cc +++ b/paddle/fluid/operators/detection/generate_proposals_op.cc @@ -98,8 +98,7 @@ class GenerateProposalsKernel : public framework::OpKernel { float min_size = context.Attr("min_size"); float eta = context.Attr("eta"); - auto &dev_ctx = - context.template device_context(); + auto &dev_ctx = context.template device_context(); auto &scores_dim = scores->dims(); int64_t num = scores_dim[0]; @@ -122,7 +121,7 @@ class GenerateProposalsKernel : public framework::OpKernel { scores_swap.mutable_data({num, h_score, w_score, c_score}, dev_ctx.GetPlace()); - phi::funcs::Transpose trans; + phi::funcs::Transpose trans; std::vector axis = {0, 2, 3, 1}; trans(dev_ctx, *bbox_deltas, &bbox_deltas_swap, axis); trans(dev_ctx, *scores, &scores_swap, axis); @@ -181,7 +180,7 @@ class GenerateProposalsKernel : public framework::OpKernel { } std::pair ProposalForOneImage( - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, const Tensor &im_info_slice, const Tensor &anchors, const Tensor &variances, @@ -234,7 +233,7 @@ class GenerateProposalsKernel : public framework::OpKernel { FilterBoxes(ctx, &proposals, min_size, im_info_slice, true, &keep); // Handle the case when there is no keep index left if (keep.numel() == 0) { - phi::funcs::SetConstant set_zero; + phi::funcs::SetConstant set_zero; bbox_sel.mutable_data({1, 4}, ctx.GetPlace()); set_zero(ctx, &bbox_sel, static_cast(0)); Tensor scores_filter; diff --git a/paddle/fluid/operators/detection/generate_proposals_v2_op.cc b/paddle/fluid/operators/detection/generate_proposals_v2_op.cc index 257716b6357249b792f9113068335689a5d35cae..450154bec4e17a1a949e8a39e2b70bd05f5fad4f 100644 --- a/paddle/fluid/operators/detection/generate_proposals_v2_op.cc +++ b/paddle/fluid/operators/detection/generate_proposals_v2_op.cc @@ -99,8 +99,7 @@ class GenerateProposalsV2Kernel : public framework::OpKernel { float eta = context.Attr("eta"); bool pixel_offset = context.Attr("pixel_offset"); - auto &dev_ctx = - context.template device_context(); + auto &dev_ctx = context.template device_context(); auto &scores_dim = scores->dims(); int64_t num = scores_dim[0]; @@ -123,7 +122,7 @@ class GenerateProposalsV2Kernel : public framework::OpKernel { scores_swap.mutable_data({num, h_score, w_score, c_score}, dev_ctx.GetPlace()); - phi::funcs::Transpose trans; + phi::funcs::Transpose trans; std::vector axis = {0, 2, 3, 1}; trans(dev_ctx, *bbox_deltas, &bbox_deltas_swap, axis); trans(dev_ctx, *scores, &scores_swap, axis); @@ -183,7 +182,7 @@ class GenerateProposalsV2Kernel : public framework::OpKernel { } std::pair ProposalForOneImage( - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, const Tensor &im_shape_slice, const Tensor &anchors, const Tensor &variances, @@ -240,7 +239,7 @@ class GenerateProposalsV2Kernel : public framework::OpKernel { ctx, &proposals, min_size, im_shape_slice, false, &keep, pixel_offset); // Handle the case when there is no keep index left if (keep.numel() == 0) { - phi::funcs::SetConstant set_zero; + phi::funcs::SetConstant set_zero; bbox_sel.mutable_data({1, 4}, ctx.GetPlace()); set_zero(ctx, &bbox_sel, static_cast(0)); Tensor scores_filter; diff --git a/paddle/fluid/operators/detection/iou_similarity_op.cc b/paddle/fluid/operators/detection/iou_similarity_op.cc index 504090cfaf7fe02bc2af586371e72a4347b87709..c31c630cd6ccd581bb0496a25ce36035eef0bb05 100644 --- a/paddle/fluid/operators/detection/iou_similarity_op.cc +++ b/paddle/fluid/operators/detection/iou_similarity_op.cc @@ -113,7 +113,6 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - iou_similarity, - ops::IOUSimilarityKernel, - ops::IOUSimilarityKernel); +REGISTER_OP_CPU_KERNEL(iou_similarity, + ops::IOUSimilarityKernel, + ops::IOUSimilarityKernel); diff --git a/paddle/fluid/operators/detection/locality_aware_nms_op.cc b/paddle/fluid/operators/detection/locality_aware_nms_op.cc index 6b0608d386f2ee40288f20ecdd70af9a160ab292..6fb48229517d3be070ea28fdd1153adc1b02e42b 100644 --- a/paddle/fluid/operators/detection/locality_aware_nms_op.cc +++ b/paddle/fluid/operators/detection/locality_aware_nms_op.cc @@ -356,7 +356,7 @@ class LocalityAwareNMSKernel : public framework::OpKernel { auto* outs = ctx.Output("Out"); auto& score_dims = scores_input->dims(); auto score_size = score_dims.size(); - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); LoDTensor scores; LoDTensor boxes; diff --git a/paddle/fluid/operators/detection/mine_hard_examples_op.cc b/paddle/fluid/operators/detection/mine_hard_examples_op.cc index e2157b02f92d22199b99581b42a2c6bdc356997c..163da3cdd9727201dc066887cb3c3eeae0a05677 100644 --- a/paddle/fluid/operators/detection/mine_hard_examples_op.cc +++ b/paddle/fluid/operators/detection/mine_hard_examples_op.cc @@ -403,7 +403,6 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - mine_hard_examples, - ops::MineHardExamplesKernel, - ops::MineHardExamplesKernel); +REGISTER_OP_CPU_KERNEL(mine_hard_examples, + ops::MineHardExamplesKernel, + ops::MineHardExamplesKernel); diff --git a/paddle/fluid/operators/detection/multiclass_nms_op.cc b/paddle/fluid/operators/detection/multiclass_nms_op.cc index 0fb02832be066f13ee613fc7f99e80bccc1b4f26..68b4ab20150bb2563384d500623c8728ba333c1c 100644 --- a/paddle/fluid/operators/detection/multiclass_nms_op.cc +++ b/paddle/fluid/operators/detection/multiclass_nms_op.cc @@ -219,7 +219,7 @@ class MultiClassNMSKernel : public framework::OpKernel { T nms_threshold = static_cast(ctx.Attr("nms_threshold")); T nms_eta = static_cast(ctx.Attr("nms_eta")); T score_threshold = static_cast(ctx.Attr("score_threshold")); - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); int num_det = 0; @@ -361,7 +361,7 @@ class MultiClassNMSKernel : public framework::OpKernel { auto rois_num = ctx.Input("RoisNum"); auto score_dims = scores->dims(); auto score_size = score_dims.size(); - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); std::vector>> all_indices; std::vector batch_starts = {0}; diff --git a/paddle/fluid/operators/detection/retinanet_detection_output_op.cc b/paddle/fluid/operators/detection/retinanet_detection_output_op.cc index a2a9358ca0d85e0fa596b7644048e809e32b066d..915b174f174c5bc17de07be4e0d69435544dc4ec 100644 --- a/paddle/fluid/operators/detection/retinanet_detection_output_op.cc +++ b/paddle/fluid/operators/detection/retinanet_detection_output_op.cc @@ -507,7 +507,7 @@ class RetinanetDetectionOutputKernel : public framework::OpKernel { int64_t box_dim = box_dims[2]; int64_t out_dim = box_dim + 2; - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); std::vector>> all_nmsed_out; std::vector batch_starts = {0}; diff --git a/paddle/fluid/operators/detection/rpn_target_assign_op.cc b/paddle/fluid/operators/detection/rpn_target_assign_op.cc index 4d7d9fec77dbe10988584f501c30f2d26015b2fc..8fbfe2ad8548c4057cac8ef034e6ab757b4b2b25 100644 --- a/paddle/fluid/operators/detection/rpn_target_assign_op.cc +++ b/paddle/fluid/operators/detection/rpn_target_assign_op.cc @@ -112,12 +112,11 @@ void AppendRpns(LoDTensor* out, int64_t offset, Tensor* to_add) { } template -std::vector FilterStraddleAnchor( - const platform::CPUDeviceContext& context, - const Tensor* anchor, - const float rpn_straddle_thresh, - T im_height, - T im_width) { +std::vector FilterStraddleAnchor(const phi::CPUContext& context, + const Tensor* anchor, + const float rpn_straddle_thresh, + T im_height, + T im_width) { std::vector inds_inside; int anchor_num = anchor->dims()[0]; auto* anchor_data = anchor->data(); @@ -154,7 +153,7 @@ std::vector FilterStraddleAnchor( } template -Tensor FilterCrowdGt(const platform::CPUDeviceContext& context, +Tensor FilterCrowdGt(const phi::CPUContext& context, Tensor* gt_boxes, Tensor* is_crowd) { int gt_num = gt_boxes->dims()[0]; @@ -300,7 +299,7 @@ void ScoreAssign(const T* anchor_by_gt_overlap_data, } template -std::vector SampleRpnFgBgGt(const platform::CPUDeviceContext& ctx, +std::vector SampleRpnFgBgGt(const phi::CPUContext& ctx, const Tensor& anchor_by_gt_overlap, const int rpn_batch_size_per_im, const float rpn_positive_overlap, @@ -437,7 +436,7 @@ class RpnTargetAssignKernel : public framework::OpKernel { tgt_bbox->mutable_data({max_num, 4}, place); tgt_lbl->mutable_data({max_num, 1}, place); bbox_inside_weight->mutable_data({max_num, 4}, place); - auto& dev_ctx = context.device_context(); + auto& dev_ctx = context.device_context(); std::random_device rnd; std::minstd_rand engine; @@ -857,11 +856,10 @@ class RetinanetTargetAssignOp : public framework::OperatorWithKernel { }; template -std::vector FilterCrowdGtBoxLabel( - const platform::CPUDeviceContext& context, - Tensor* gt_boxes, - Tensor* gt_labels, - Tensor* is_crowd) { +std::vector FilterCrowdGtBoxLabel(const phi::CPUContext& context, + Tensor* gt_boxes, + Tensor* gt_labels, + Tensor* is_crowd) { int gt_num = gt_boxes->dims()[0]; std::vector not_crowd_inds; auto* is_crowd_data = is_crowd->data(); @@ -893,7 +891,7 @@ std::vector FilterCrowdGtBoxLabel( } template -std::vector GetAllFgBgGt(const platform::CPUDeviceContext& ctx, +std::vector GetAllFgBgGt(const phi::CPUContext& ctx, const Tensor& anchor_by_gt_overlap, const Tensor& ncrowd_gt_labels, const float positive_overlap, @@ -1044,7 +1042,7 @@ class RetinanetTargetAssignKernel : public framework::OpKernel { tgt_lbl->mutable_data({max_num, 1}, place); bbox_inside_weight->mutable_data({max_num, 4}, place); fg_num->mutable_data({batch_num, 1}, place); - auto& dev_ctx = context.device_context(); + auto& dev_ctx = context.device_context(); std::random_device rnd; std::minstd_rand engine; diff --git a/paddle/fluid/operators/detection/sigmoid_focal_loss_op.cc b/paddle/fluid/operators/detection/sigmoid_focal_loss_op.cc index 9bdc1b645bfe62a9d1fc44991d1c035d2f1640cb..bc23c5105db94bbea771961d7ba06d85c2502229 100644 --- a/paddle/fluid/operators/detection/sigmoid_focal_loss_op.cc +++ b/paddle/fluid/operators/detection/sigmoid_focal_loss_op.cc @@ -266,12 +266,10 @@ REGISTER_OPERATOR(sigmoid_focal_loss, ops::SigmoidFocalLossGradOpMaker, ops::SigmoidFocalLossGradOpMaker); REGISTER_OPERATOR(sigmoid_focal_loss_grad, ops::SigmoidFocalLossGradOp); -REGISTER_OP_CPU_KERNEL( - sigmoid_focal_loss, - ops::SigmoidFocalLossKernel, - ops::SigmoidFocalLossKernel); +REGISTER_OP_CPU_KERNEL(sigmoid_focal_loss, + ops::SigmoidFocalLossKernel, + ops::SigmoidFocalLossKernel); REGISTER_OP_CPU_KERNEL( sigmoid_focal_loss_grad, - ops::SigmoidFocalLossGradKernel, - ops::SigmoidFocalLossGradKernel); + ops::SigmoidFocalLossGradKernel, + ops::SigmoidFocalLossGradKernel); diff --git a/paddle/fluid/operators/detection/target_assign_op.cc b/paddle/fluid/operators/detection/target_assign_op.cc index a6c1db5f78d0e1fd450eb09ab42849180fb70b34..99deee3f72aeafdcd69d7036e69e094368f4043c 100644 --- a/paddle/fluid/operators/detection/target_assign_op.cc +++ b/paddle/fluid/operators/detection/target_assign_op.cc @@ -149,8 +149,8 @@ for i-th instance and each `id` of NegIndices in this instance: }; template -struct NegTargetAssignFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct NegTargetAssignFunctor { + void operator()(const phi::CPUContext& ctx, const int* neg_indices, const size_t* lod, const int N, @@ -172,10 +172,8 @@ struct NegTargetAssignFunctor { } }; -template struct NegTargetAssignFunctor; -template struct NegTargetAssignFunctor; +template struct NegTargetAssignFunctor; +template struct NegTargetAssignFunctor; } // namespace operators } // namespace paddle @@ -187,7 +185,6 @@ REGISTER_OPERATOR( ops::TargetAssignOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - target_assign, - ops::TargetAssignKernel, - ops::TargetAssignKernel); +REGISTER_OP_CPU_KERNEL(target_assign, + ops::TargetAssignKernel, + ops::TargetAssignKernel); diff --git a/paddle/fluid/operators/determinant_op.cc b/paddle/fluid/operators/determinant_op.cc index b3af0853095da47178b63f4f89199412116235bb..b4724eb3c83a39d182ea72e522aba65386b2d6b6 100644 --- a/paddle/fluid/operators/determinant_op.cc +++ b/paddle/fluid/operators/determinant_op.cc @@ -179,12 +179,10 @@ REGISTER_OPERATOR(slogdeterminant, REGISTER_OPERATOR(slogdeterminant_grad, ops::SlogDeterminantGradOp) // reuse det grad op -REGISTER_OP_CPU_KERNEL( - slogdeterminant, - ops::SlogDeterminantKernel, - ops::SlogDeterminantKernel); - -REGISTER_OP_CPU_KERNEL( - slogdeterminant_grad, - ops::SlogDeterminantGradKernel, - ops::SlogDeterminantGradKernel); +REGISTER_OP_CPU_KERNEL(slogdeterminant, + ops::SlogDeterminantKernel, + ops::SlogDeterminantKernel); + +REGISTER_OP_CPU_KERNEL(slogdeterminant_grad, + ops::SlogDeterminantGradKernel, + ops::SlogDeterminantGradKernel); diff --git a/paddle/fluid/operators/dgc_clip_by_norm_op.cc b/paddle/fluid/operators/dgc_clip_by_norm_op.cc index 5d0cd4bbc357873b0fc8dc65dc554731f4875491..9949fefb1b18b59c4993ac9b2cf865b46912b718 100644 --- a/paddle/fluid/operators/dgc_clip_by_norm_op.cc +++ b/paddle/fluid/operators/dgc_clip_by_norm_op.cc @@ -66,6 +66,5 @@ REGISTER_OP_WITHOUT_GRADIENT(dgc_clip_by_norm, ops::DGCClipByNormOp, ops::DGCClipByNormOpMaker); -REGISTER_OP_CPU_KERNEL( - dgc_clip_by_norm, - ops::DGCClipByNormKernel); +REGISTER_OP_CPU_KERNEL(dgc_clip_by_norm, + ops::DGCClipByNormKernel); diff --git a/paddle/fluid/operators/diag_embed_op.cc b/paddle/fluid/operators/diag_embed_op.cc index 0377e40e0a2215c2fd98700a9c2425a2c241590a..531d6f92d8830ef25ef40802e0c94b522283b0ea 100644 --- a/paddle/fluid/operators/diag_embed_op.cc +++ b/paddle/fluid/operators/diag_embed_op.cc @@ -138,9 +138,8 @@ REGISTER_OPERATOR( ops::DiagEmbedOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - diag_embed, - ops::DiagEmbedKernel, - ops::DiagEmbedKernel, - ops::DiagEmbedKernel, - ops::DiagEmbedKernel); +REGISTER_OP_CPU_KERNEL(diag_embed, + ops::DiagEmbedKernel, + ops::DiagEmbedKernel, + ops::DiagEmbedKernel, + ops::DiagEmbedKernel); diff --git a/paddle/fluid/operators/diag_op.cc b/paddle/fluid/operators/diag_op.cc index 9f12e4af47fdd287bf1d86f45bc830e82b8d7343..8ccc5ff3891b9a1925593d5cbc52bf6caa6ae302 100644 --- a/paddle/fluid/operators/diag_op.cc +++ b/paddle/fluid/operators/diag_op.cc @@ -59,9 +59,8 @@ REGISTER_OPERATOR( ops::DiagOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - diag, - ops::DiagKernel, - ops::DiagKernel, - ops::DiagKernel, - ops::DiagKernel); +REGISTER_OP_CPU_KERNEL(diag, + ops::DiagKernel, + ops::DiagKernel, + ops::DiagKernel, + ops::DiagKernel); diff --git a/paddle/fluid/operators/dirichlet_op.cc b/paddle/fluid/operators/dirichlet_op.cc index 81a3e63192eb5990a5763f72038325a630c84cc0..ccbe3b62b73dd2d4252b38248fc6ef057bd84577 100644 --- a/paddle/fluid/operators/dirichlet_op.cc +++ b/paddle/fluid/operators/dirichlet_op.cc @@ -42,11 +42,11 @@ struct GammaCPUFunctor { }; template -struct DirichletSampler { +struct DirichletSampler { void operator()(const framework::ExecutionContext& ctx, const Tensor* alpha, Tensor* out) { - auto& dev_ctx = ctx.device_context(); + auto& dev_ctx = ctx.device_context(); auto p_gen = framework::DefaultCPUGenerator(); auto generator = p_gen->GetCPUEngine(); @@ -71,8 +71,7 @@ struct DirichletSampler { gamma_samples.data(), standard_uniform, standard_normal); - platform::ForRange for_range(dev_ctx, - alpha->numel()); + platform::ForRange for_range(dev_ctx, alpha->numel()); for_range(gamma_functor); // normalize them into a simplex, along the last axis @@ -81,10 +80,10 @@ struct DirichletSampler { new_shape[new_shape.size() - 1] = 1; gamma_sum.mutable_data(new_shape, dev_ctx.GetPlace()); - ReduceKernelFunctor( + ReduceKernelFunctor( &gamma_samples, &gamma_sum, {new_shape.size() - 1}, true, false, ctx) .template apply(); - ElementwiseComputeEx, platform::CPUDeviceContext, T, T>( + ElementwiseComputeEx, phi::CPUContext, T, T>( ctx, &gamma_samples, &gamma_sum, -1, DivFunctor(), out); } }; @@ -125,7 +124,5 @@ REGISTER_OP_WITHOUT_GRADIENT(dirichlet, paddle::operators::DirichletOpMaker); REGISTER_OP_CPU_KERNEL( dirichlet, - paddle::operators::DirichletKernel, - paddle::operators::DirichletKernel); + paddle::operators::DirichletKernel, + paddle::operators::DirichletKernel); diff --git a/paddle/fluid/operators/dropout_op_test.cc b/paddle/fluid/operators/dropout_op_test.cc index bdf08646f1d8b94d6d8d141d8a9fa9864cdc937b..7733d202e5781ab2c8ee884478c0ea87d7e2b9d0 100644 --- a/paddle/fluid/operators/dropout_op_test.cc +++ b/paddle/fluid/operators/dropout_op_test.cc @@ -91,7 +91,7 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx) { TEST(Dropout, CPUDense) { f::Scope scope; p::CPUPlace place; - p::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); Compare(scope, ctx); } diff --git a/paddle/fluid/operators/eig_op.cc b/paddle/fluid/operators/eig_op.cc index 2a7c738f979135c7d63d2ef7f8dd90e8c8a6ad19..b53bba9fac0c40ca46e7bbf23c53c6fedf825a21 100644 --- a/paddle/fluid/operators/eig_op.cc +++ b/paddle/fluid/operators/eig_op.cc @@ -164,19 +164,15 @@ REGISTER_OPERATOR(eig, REGISTER_OPERATOR(eig_grad, ops::EigGradOp); -REGISTER_OP_CPU_KERNEL( - eig, - ops::EigKernel, - ops::EigKernel, - ops::EigKernel, - ops::EigKernel); +REGISTER_OP_CPU_KERNEL(eig, + ops::EigKernel, + ops::EigKernel, + ops::EigKernel, + ops::EigKernel); REGISTER_OP_CPU_KERNEL( eig_grad, - ops::EigGradKernel, - ops::EigGradKernel, - ops:: - EigGradKernel, - ops::EigGradKernel); + ops::EigGradKernel, + ops::EigGradKernel, + ops::EigGradKernel, + ops::EigGradKernel); diff --git a/paddle/fluid/operators/eig_op.h b/paddle/fluid/operators/eig_op.h index b677acbe9666389a0ca75c05c708c6c1236f66c0..138a987a0bd9fa170bd6b99f9e0fabaa581b932c 100644 --- a/paddle/fluid/operators/eig_op.h +++ b/paddle/fluid/operators/eig_op.h @@ -70,7 +70,7 @@ void TransposeTwoAxis(const Tensor& input, permute[axis2] = axis1; transposed_input->mutable_data(input.dims(), context.GetPlace()); - auto& dev_ctx = context.template device_context(); + auto& dev_ctx = context.template device_context(); TransCompute( input.dims().size(), dev_ctx, input, transposed_input, permute); diff --git a/paddle/fluid/operators/eigvals_op.cc b/paddle/fluid/operators/eigvals_op.cc index a01316787f2472c0a31464f788b4f1b8a80d9e88..cb81a1a64d1d54ca3bc2e460fc2a1926a9c96a90 100644 --- a/paddle/fluid/operators/eigvals_op.cc +++ b/paddle/fluid/operators/eigvals_op.cc @@ -86,10 +86,9 @@ REGISTER_OPERATOR(eigvals, ops::EigvalsOp, ops::EigvalsOpMaker, ops::EigvalsOpVarTypeInference); -REGISTER_OP_CPU_KERNEL(eigvals, - ops::EigvalsKernel, - ops::EigvalsKernel, - ops::EigvalsKernel>, - ops::EigvalsKernel>); +REGISTER_OP_CPU_KERNEL( + eigvals, + ops::EigvalsKernel, + ops::EigvalsKernel, + ops::EigvalsKernel>, + ops::EigvalsKernel>); diff --git a/paddle/fluid/operators/eigvalsh_op.cc b/paddle/fluid/operators/eigvalsh_op.cc index 3684b926a1ac57c75b890d12541cc9e8aba7ef44..f7abdbee84f1db4a21512560ed952396dd9e3578 100644 --- a/paddle/fluid/operators/eigvalsh_op.cc +++ b/paddle/fluid/operators/eigvalsh_op.cc @@ -151,24 +151,23 @@ REGISTER_OPERATOR(eigvalsh, ops::EigvalshGradOpMaker); REGISTER_OPERATOR(eigvalsh_grad, ops::EigvalshGradOp); -REGISTER_OP_CPU_KERNEL( - eigvalsh, - ops::EigvalshKernel, - ops::EigvalshKernel, - ops::EigvalshKernel>, - ops::EigvalshKernel>); +REGISTER_OP_CPU_KERNEL(eigvalsh, + ops::EigvalshKernel, + ops::EigvalshKernel, + ops::EigvalshKernel>, + ops::EigvalshKernel>); REGISTER_OP_CPU_KERNEL( eigvalsh_grad, - ops::EigvalshGradKernel, - ops::EigvalshGradKernel, - ops::EigvalshGradKernel, + ops::EigvalshGradKernel, + ops::EigvalshGradKernel>, - ops::EigvalshGradKernel>); diff --git a/paddle/fluid/operators/expand_as_op.cc b/paddle/fluid/operators/expand_as_op.cc index af6510ae3b93189f792c4f5f451ea7f59c4b5d12..6f1e04ebfa6cfaf666fbd09eeddb341884425371 100644 --- a/paddle/fluid/operators/expand_as_op.cc +++ b/paddle/fluid/operators/expand_as_op.cc @@ -146,19 +146,17 @@ REGISTER_OPERATOR(expand_as, REGISTER_OPERATOR(expand_as_grad, ops::ExpandAsGradOp, ops::ExpandAsGradNoNeedBufVarsInferer); -REGISTER_OP_CPU_KERNEL( - expand_as, - ops::ExpandAsKernel, - ops::ExpandAsKernel, - ops::ExpandAsKernel, - ops::ExpandAsKernel, - ops::ExpandAsKernel); -REGISTER_OP_CPU_KERNEL( - expand_as_grad, - ops::ExpandAsGradKernel, - ops::ExpandAsGradKernel, - ops::ExpandAsGradKernel, - ops::ExpandAsGradKernel); +REGISTER_OP_CPU_KERNEL(expand_as, + ops::ExpandAsKernel, + ops::ExpandAsKernel, + ops::ExpandAsKernel, + ops::ExpandAsKernel, + ops::ExpandAsKernel); +REGISTER_OP_CPU_KERNEL(expand_as_grad, + ops::ExpandAsGradKernel, + ops::ExpandAsGradKernel, + ops::ExpandAsGradKernel, + ops::ExpandAsGradKernel); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) REGISTER_OP_CUDA_KERNEL( expand_as, diff --git a/paddle/fluid/operators/expand_op.cc b/paddle/fluid/operators/expand_op.cc index 100158ce9c21e72a06dc1f5479bd1b6563f57fb4..d8c66f95a1395e9a8f344785d536c66cf0aeae96 100644 --- a/paddle/fluid/operators/expand_op.cc +++ b/paddle/fluid/operators/expand_op.cc @@ -280,19 +280,17 @@ REGISTER_OPERATOR(expand_grad, ops::ExpandDoubleGradOpMaker, ops::ExpandDoubleGradOpMaker, ops::ExpandGradNoNeedBufVarsInferer); -REGISTER_OP_CPU_KERNEL( - expand, - ops::ExpandKernel, - ops::ExpandKernel, - ops::ExpandKernel, - ops::ExpandKernel, - ops::ExpandKernel); -REGISTER_OP_CPU_KERNEL( - expand_grad, - ops::ExpandGradKernel, - ops::ExpandGradKernel, - ops::ExpandGradKernel, - ops::ExpandGradKernel); +REGISTER_OP_CPU_KERNEL(expand, + ops::ExpandKernel, + ops::ExpandKernel, + ops::ExpandKernel, + ops::ExpandKernel, + ops::ExpandKernel); +REGISTER_OP_CPU_KERNEL(expand_grad, + ops::ExpandGradKernel, + ops::ExpandGradKernel, + ops::ExpandGradKernel, + ops::ExpandGradKernel); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) REGISTER_OP_CUDA_KERNEL( expand, diff --git a/paddle/fluid/operators/exponential_op.cc b/paddle/fluid/operators/exponential_op.cc index 03fbdfcd5ae7786aa397dcf9401302b5fb62d938..5a75063fba7c1b5fa303501a7b7fe908703f6258 100644 --- a/paddle/fluid/operators/exponential_op.cc +++ b/paddle/fluid/operators/exponential_op.cc @@ -62,8 +62,7 @@ class ExponentialOpInferVarType }; template -class ExponentialKernel - : public framework::OpKernel { +class ExponentialKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &ctx) const override { auto *out = ctx.Output("Out"); @@ -135,9 +134,8 @@ REGISTER_OPERATOR(exponential_grad, ExponentialGradInferer); REGISTER_OP_CPU_KERNEL(exponential, - ops::ExponentialKernel, - ops::ExponentialKernel); -REGISTER_OP_CPU_KERNEL( - exponential_grad, - ops::ExponentialGradKernel, - ops::ExponentialGradKernel); + ops::ExponentialKernel, + ops::ExponentialKernel); +REGISTER_OP_CPU_KERNEL(exponential_grad, + ops::ExponentialGradKernel, + ops::ExponentialGradKernel); diff --git a/paddle/fluid/operators/fake_dequantize_op.cc b/paddle/fluid/operators/fake_dequantize_op.cc index 58022ee6400fdc5f4e837c6682064d2e7a75cfe9..4e1df4f98ab5712db4868a685b602a447c8fc951 100644 --- a/paddle/fluid/operators/fake_dequantize_op.cc +++ b/paddle/fluid/operators/fake_dequantize_op.cc @@ -23,8 +23,8 @@ namespace paddle { namespace operators { template -struct DequantizeFunctor { - void operator()(const platform::CPUDeviceContext& dev_ctx, +struct DequantizeFunctor { + void operator()(const phi::CPUContext& dev_ctx, const framework::Tensor* in, const framework::Tensor* scale, T max_range, @@ -39,8 +39,8 @@ struct DequantizeFunctor { }; template -struct ChannelDequantizeFunctor { - void operator()(const platform::CPUDeviceContext& dev_ctx, +struct ChannelDequantizeFunctor { + void operator()(const phi::CPUContext& dev_ctx, const framework::Tensor* in, const framework::Tensor** scales, const int scale_num, @@ -139,10 +139,10 @@ struct ChannelDequantizeFunctor { } }; -template struct DequantizeFunctor; -template struct DequantizeFunctor; -template struct ChannelDequantizeFunctor; -template struct ChannelDequantizeFunctor; +template struct DequantizeFunctor; +template struct DequantizeFunctor; +template struct ChannelDequantizeFunctor; +template struct ChannelDequantizeFunctor; class FakeDequantizeMaxAbsOp : public framework::OperatorWithKernel { public: @@ -269,7 +269,7 @@ Notes: In general, the per-channel quantization is only applied to weights and t } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( fake_dequantize_max_abs, diff --git a/paddle/fluid/operators/fake_quantize_op.cc b/paddle/fluid/operators/fake_quantize_op.cc index 61ee9d49ebeec941c8d00ffd2a857b21ce6ecfd0..cb8263714a5e47b1397a62b78588f2d9b9d9aaae 100644 --- a/paddle/fluid/operators/fake_quantize_op.cc +++ b/paddle/fluid/operators/fake_quantize_op.cc @@ -32,8 +32,8 @@ struct Compare { }; template -struct FindAbsMaxFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct FindAbsMaxFunctor { + void operator()(const phi::CPUContext &ctx, const T *in, const int num, T *out) { @@ -41,11 +41,11 @@ struct FindAbsMaxFunctor { } }; -template struct FindAbsMaxFunctor; +template struct FindAbsMaxFunctor; template -struct FindChannelAbsMaxFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct FindChannelAbsMaxFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in_tensor, const int quant_axis, T *out_abs_max) { @@ -86,11 +86,11 @@ struct FindChannelAbsMaxFunctor { } }; -template struct FindChannelAbsMaxFunctor; +template struct FindChannelAbsMaxFunctor; template -struct ClipAndFakeQuantFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct ClipAndFakeQuantFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in, const framework::Tensor &scale, const int bin_cnt, @@ -98,7 +98,7 @@ struct ClipAndFakeQuantFunctor { framework::Tensor *out) { T s = scale.data()[0]; T inv_s = inverse(s); - platform::Transform trans; + platform::Transform trans; if (round_type == 0) { trans(ctx, in.data(), @@ -117,11 +117,11 @@ struct ClipAndFakeQuantFunctor { } }; -template struct ClipAndFakeQuantFunctor; +template struct ClipAndFakeQuantFunctor; template -struct ClipAndFakeQuantDequantFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct ClipAndFakeQuantDequantFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in, const framework::Tensor &scale, const int bin_cnt, @@ -130,7 +130,7 @@ struct ClipAndFakeQuantDequantFunctor { T s = scale.data()[0]; T inv_s = inverse(s); - platform::Transform trans; + platform::Transform trans; if (round_type == 0) { trans(ctx, in.data(), @@ -151,12 +151,11 @@ struct ClipAndFakeQuantDequantFunctor { } } }; -template struct ClipAndFakeQuantDequantFunctor; +template struct ClipAndFakeQuantDequantFunctor; template -struct ChannelClipAndFakeQuantFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct ChannelClipAndFakeQuantFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in, const framework::Tensor &scale, const int bin_cnt, @@ -176,7 +175,7 @@ struct ChannelClipAndFakeQuantFunctor { auto *out_data = out->mutable_data(ctx.GetPlace()); auto in_dims = in.dims(); const int64_t channel = in_dims[quant_axis]; - platform::Transform trans; + platform::Transform trans; if (quant_axis == 0) { const int64_t channel_size = in.numel() / channel; for (int64_t i = 0; i < channel; i++) { @@ -235,11 +234,10 @@ struct ChannelClipAndFakeQuantFunctor { } }; -template struct ChannelClipAndFakeQuantFunctor; +template struct ChannelClipAndFakeQuantFunctor; template -struct ChannelClipFakeQuantDequantFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct ChannelClipFakeQuantDequantFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in, const framework::Tensor &scale, const int bin_cnt, @@ -258,7 +256,7 @@ struct ChannelClipFakeQuantDequantFunctor { auto *out_data = out->mutable_data(ctx.GetPlace()); auto in_dims = in.dims(); const int64_t channel = in_dims[quant_axis]; - platform::Transform trans; + platform::Transform trans; if (quant_axis == 0) { const int64_t channel_size = in.numel() / channel; for (int i = 0; i < channel; i++) { @@ -326,11 +324,10 @@ struct ChannelClipFakeQuantDequantFunctor { } }; -template struct ChannelClipFakeQuantDequantFunctor; +template struct ChannelClipFakeQuantDequantFunctor; template -struct FindRangeAbsMaxFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct FindRangeAbsMaxFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &cur_scale, const framework::Tensor &last_scale, const framework::Tensor &iter, @@ -349,18 +346,17 @@ struct FindRangeAbsMaxFunctor { max = cur; } else if (fabs(removed - max) < 1e-6) { int size = (it > window_size) ? window_size : it; - FindAbsMaxFunctor()( - ctx, scale_arr, size, &max); + FindAbsMaxFunctor()(ctx, scale_arr, size, &max); } out_scale->mutable_data(ctx.GetPlace())[0] = max; } }; -template struct FindRangeAbsMaxFunctor; +template struct FindRangeAbsMaxFunctor; template -struct FindMovingAverageAbsMaxFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct FindMovingAverageAbsMaxFunctor { + void operator()(const phi::CPUContext &ctx, const framework::Tensor &in_accum, const framework::Tensor &in_state, const T *cur_scale, @@ -382,8 +378,7 @@ struct FindMovingAverageAbsMaxFunctor { } }; -template struct FindMovingAverageAbsMaxFunctor; +template struct FindMovingAverageAbsMaxFunctor; class FakeQuantOrWithDequantAbsMaxOp : public framework::OperatorWithKernel { public: @@ -968,7 +963,7 @@ class StrightThroughEstimatorMaker : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( fake_quantize_abs_max, diff --git a/paddle/fluid/operators/fc_op.cc b/paddle/fluid/operators/fc_op.cc index a851a6db5657fc4a25710d4ee5ffdf4d1723aed7..43bb6089a87dd2d56105e24732193bbf10289a48 100644 --- a/paddle/fluid/operators/fc_op.cc +++ b/paddle/fluid/operators/fc_op.cc @@ -223,7 +223,6 @@ REGISTER_OPERATOR( ops::FCOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - fc, - ops::FCOpKernel, - ops::FCOpKernel); +REGISTER_OP_CPU_KERNEL(fc, + ops::FCOpKernel, + ops::FCOpKernel); diff --git a/paddle/fluid/operators/fill_any_op.cc b/paddle/fluid/operators/fill_any_op.cc index ddbfe226b647e91612a0f79e88dfde89af55c741..853ebbdd9e57cb2f769ac874ea4d241e7d56d164 100644 --- a/paddle/fluid/operators/fill_any_op.cc +++ b/paddle/fluid/operators/fill_any_op.cc @@ -95,20 +95,18 @@ REGISTER_OPERATOR(fill_any_grad, REGISTER_OP_CPU_KERNEL( fill_any, - ops::FillAnyKernel, - ops::FillAnyKernel, - ops::FillAnyKernel, - ops::FillAnyKernel, - ops::FillAnyKernel, - ops::FillAnyKernel); + ops::FillAnyKernel, + ops::FillAnyKernel, + ops::FillAnyKernel, + ops::FillAnyKernel, + ops::FillAnyKernel, + ops::FillAnyKernel); REGISTER_OP_CPU_KERNEL( fill_any_grad, - ops::FillAnyGradKernel, - ops::FillAnyGradKernel, - ops::FillAnyGradKernel, - ops::FillAnyGradKernel, - ops::FillAnyGradKernel, - ops::FillAnyGradKernel); + ops::FillAnyGradKernel, + ops::FillAnyGradKernel, + ops::FillAnyGradKernel, + ops::FillAnyGradKernel, + ops::FillAnyGradKernel, + ops::FillAnyGradKernel); diff --git a/paddle/fluid/operators/fill_constant_batch_size_like_op_mlu.cc b/paddle/fluid/operators/fill_constant_batch_size_like_op_mlu.cc index 425222bcd660c8a0739a3bf50dc177b621ded773..32a19750f420a9c06fe4a2734e24048e0db932c5 100644 --- a/paddle/fluid/operators/fill_constant_batch_size_like_op_mlu.cc +++ b/paddle/fluid/operators/fill_constant_batch_size_like_op_mlu.cc @@ -68,10 +68,10 @@ class FillConstantBatchSizeLikeOpMLUKernel : public framework::OpKernel { bool cpu_place = force_cpu || ctx.GetPlace() == platform::CPUPlace(); if (cpu_place) { auto &dev_ctx = *pool.Get(platform::CPUPlace()); - phi::funcs::SetConstant functor; + phi::funcs::SetConstant functor; out->mutable_data(platform::CPUPlace(), framework::TransToPhiDataType(data_type)); - functor(reinterpret_cast(dev_ctx), + functor(reinterpret_cast(dev_ctx), out, static_cast(value)); } else { diff --git a/paddle/fluid/operators/fill_constant_batch_size_like_op_npu.cc b/paddle/fluid/operators/fill_constant_batch_size_like_op_npu.cc index ad4efbb3e0c6321fa1dc506555d4207ea10a9137..02f89cfdd2691231a60e8e6076911f2eda36a483 100644 --- a/paddle/fluid/operators/fill_constant_batch_size_like_op_npu.cc +++ b/paddle/fluid/operators/fill_constant_batch_size_like_op_npu.cc @@ -70,10 +70,10 @@ class FillConstantBatchSizeLikeOpNPUKernel : public framework::OpKernel { bool cpu_place = force_cpu || ctx.GetPlace() == platform::CPUPlace(); if (cpu_place) { auto &dev_ctx = *pool.Get(platform::CPUPlace()); - phi::funcs::SetConstant functor; + phi::funcs::SetConstant functor; out->mutable_data(platform::CPUPlace(), framework::TransToPhiDataType(data_type)); - functor(reinterpret_cast(dev_ctx), + functor(reinterpret_cast(dev_ctx), out, static_cast(value)); } else { diff --git a/paddle/fluid/operators/fill_constant_op.h b/paddle/fluid/operators/fill_constant_op.h index dc5079ddb605f115412430a8de2d826357ef319f..8e51c203d4122cd53c501129e1ea201b8247ddca 100644 --- a/paddle/fluid/operators/fill_constant_op.h +++ b/paddle/fluid/operators/fill_constant_op.h @@ -124,9 +124,9 @@ class FillConstantKernel : public framework::OpKernel { : ""); tensor->mutable_data(platform::CPUPlace(), framework::TransToPhiDataType(data_type)); - phi::funcs::SetConstant functor; + phi::funcs::SetConstant functor; auto &dev_ctx = *pool.Get(platform::CPUPlace()); - functor(reinterpret_cast(dev_ctx), + functor(reinterpret_cast(dev_ctx), tensor, static_cast(value)); } else if (actual_place == 1) { diff --git a/paddle/fluid/operators/fill_zeros_like_op.cc b/paddle/fluid/operators/fill_zeros_like_op.cc index b9e91baa1e707d1692680f92f5aaabaed326822f..8bd0e328c1f5b6a9cbb9bb377d5f3b5c4259f856 100644 --- a/paddle/fluid/operators/fill_zeros_like_op.cc +++ b/paddle/fluid/operators/fill_zeros_like_op.cc @@ -94,24 +94,22 @@ REGISTER_OPERATOR( REGISTER_OP_CPU_KERNEL( fill_zeros_like, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel>, - ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel>, + ops::FillZerosLikeKernel>); REGISTER_OP_CPU_KERNEL( fill_zeros_like2, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel, - ops::FillZerosLikeKernel>, - ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel, + ops::FillZerosLikeKernel>, + ops::FillZerosLikeKernel>); diff --git a/paddle/fluid/operators/flatten_op.cc b/paddle/fluid/operators/flatten_op.cc index c584dd114e0eb666b9572b62b9a281b76b5cf0e4..e160fc6f09ad0ad822e4ae95d67ca12df8c050dd 100644 --- a/paddle/fluid/operators/flatten_op.cc +++ b/paddle/fluid/operators/flatten_op.cc @@ -438,35 +438,31 @@ REGISTER_OPERATOR(flatten_contiguous_range_grad, ops::FlattenContiguousRangeGradOp, ops::FlattenGradInplaceInferer); -REGISTER_OP_CPU_KERNEL( - flatten, - ops::FlattenKernel, - ops::FlattenKernel, - ops::FlattenKernel, - ops::FlattenKernel, - ops::FlattenKernel, - ops::FlattenKernel); -REGISTER_OP_CPU_KERNEL( - flatten_grad, - ops::FlattenGradKernel, - ops::FlattenGradKernel, - ops::FlattenGradKernel, - ops::FlattenGradKernel, - ops::FlattenGradKernel, - ops::FlattenGradKernel); -REGISTER_OP_CPU_KERNEL( - flatten2, - ops::Flatten2Kernel, - ops::Flatten2Kernel, - ops::Flatten2Kernel, - ops::Flatten2Kernel, - ops::Flatten2Kernel, - ops::Flatten2Kernel); -REGISTER_OP_CPU_KERNEL( - flatten2_grad, - ops::Flatten2GradKernel, - ops::Flatten2GradKernel, - ops::Flatten2GradKernel, - ops::Flatten2GradKernel, - ops::Flatten2GradKernel, - ops::Flatten2GradKernel); +REGISTER_OP_CPU_KERNEL(flatten, + ops::FlattenKernel, + ops::FlattenKernel, + ops::FlattenKernel, + ops::FlattenKernel, + ops::FlattenKernel, + ops::FlattenKernel); +REGISTER_OP_CPU_KERNEL(flatten_grad, + ops::FlattenGradKernel, + ops::FlattenGradKernel, + ops::FlattenGradKernel, + ops::FlattenGradKernel, + ops::FlattenGradKernel, + ops::FlattenGradKernel); +REGISTER_OP_CPU_KERNEL(flatten2, + ops::Flatten2Kernel, + ops::Flatten2Kernel, + ops::Flatten2Kernel, + ops::Flatten2Kernel, + ops::Flatten2Kernel, + ops::Flatten2Kernel); +REGISTER_OP_CPU_KERNEL(flatten2_grad, + ops::Flatten2GradKernel, + ops::Flatten2GradKernel, + ops::Flatten2GradKernel, + ops::Flatten2GradKernel, + ops::Flatten2GradKernel, + ops::Flatten2GradKernel); diff --git a/paddle/fluid/operators/fold_op.cc b/paddle/fluid/operators/fold_op.cc index 21e92e6d37511e34e3ed6d84f686f94d8a6e2565..5ec5a93ada46d3af533f7bd4011a1d3fdecaba87 100644 --- a/paddle/fluid/operators/fold_op.cc +++ b/paddle/fluid/operators/fold_op.cc @@ -341,11 +341,9 @@ REGISTER_OPERATOR(fold_grad, ops::FoldGradOp, ops::FoldGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - fold, - ops::FoldOpKernel, - ops::FoldOpKernel); -REGISTER_OP_CPU_KERNEL( - fold_grad, - ops::FoldGradOpKernel, - ops::FoldGradOpKernel); +REGISTER_OP_CPU_KERNEL(fold, + ops::FoldOpKernel, + ops::FoldOpKernel); +REGISTER_OP_CPU_KERNEL(fold_grad, + ops::FoldGradOpKernel, + ops::FoldGradOpKernel); diff --git a/paddle/fluid/operators/frame_op.cc b/paddle/fluid/operators/frame_op.cc index 25efd98d37afd6138a9c10160597c6a7eabdeb30..45a6bc9994db7acd52621e63d0b4b491c611619e 100644 --- a/paddle/fluid/operators/frame_op.cc +++ b/paddle/fluid/operators/frame_op.cc @@ -185,22 +185,18 @@ REGISTER_OPERATOR(frame_grad, ops::FrameOpGrad); REGISTER_OP_CPU_KERNEL( frame, - ops::FrameKernel, - ops::FrameKernel, - ops::FrameKernel, - ops::FrameKernel, - ops::FrameKernel>, - ops::FrameKernel>); + ops::FrameKernel, + ops::FrameKernel, + ops::FrameKernel, + ops::FrameKernel, + ops::FrameKernel>, + ops::FrameKernel>); REGISTER_OP_CPU_KERNEL( frame_grad, - ops::FrameGradKernel, - ops::FrameGradKernel, - ops::FrameGradKernel, - ops::FrameGradKernel, - ops::FrameGradKernel>, - ops::FrameGradKernel>); + ops::FrameGradKernel, + ops::FrameGradKernel, + ops::FrameGradKernel, + ops::FrameGradKernel, + ops::FrameGradKernel>, + ops::FrameGradKernel>); diff --git a/paddle/fluid/operators/fsp_op.cc b/paddle/fluid/operators/fsp_op.cc index e1f82fb27ad0bbc100785db27539e24555ea3221..ff3a5a638daf0a526253a3f5e028a4d0100bc388 100644 --- a/paddle/fluid/operators/fsp_op.cc +++ b/paddle/fluid/operators/fsp_op.cc @@ -169,11 +169,9 @@ REGISTER_OPERATOR(fsp, ops::FSPGradOpMaker, ops::FSPGradOpMaker); REGISTER_OPERATOR(fsp_grad, ops::FSPOpGrad); -REGISTER_OP_CPU_KERNEL( - fsp, - ops::FSPOpKernel, - ops::FSPOpKernel); -REGISTER_OP_CPU_KERNEL( - fsp_grad, - ops::FSPGradOpKernel, - ops::FSPGradOpKernel); +REGISTER_OP_CPU_KERNEL(fsp, + ops::FSPOpKernel, + ops::FSPOpKernel); +REGISTER_OP_CPU_KERNEL(fsp_grad, + ops::FSPGradOpKernel, + ops::FSPGradOpKernel); diff --git a/paddle/fluid/operators/fused/fused_elemwise_activation_op.cc b/paddle/fluid/operators/fused/fused_elemwise_activation_op.cc index d9405aa021dc145911a716609d52fea81925f5f5..31bb78922a5a56b886b907705351ffc2bd9e60ca 100644 --- a/paddle/fluid/operators/fused/fused_elemwise_activation_op.cc +++ b/paddle/fluid/operators/fused/fused_elemwise_activation_op.cc @@ -463,17 +463,13 @@ REGISTER_OPERATOR(fused_elemwise_activation_grad, REGISTER_OP_CPU_KERNEL( fused_elemwise_activation, - ops::FusedElemwiseActivationKernel, - ops::FusedElemwiseActivationKernel); + ops::FusedElemwiseActivationKernel, + ops::FusedElemwiseActivationKernel); REGISTER_OP_CPU_KERNEL( fused_elemwise_activation_grad, - ops::FusedElemwiseActivationGradKernel, - ops::FusedElemwiseActivationGradKernel); + ops::FusedElemwiseActivationGradKernel, + ops::FusedElemwiseActivationGradKernel); // for memory optimization, we register the fused_elemwise_add_activation OP REGISTER_OPERATOR( @@ -488,14 +484,10 @@ REGISTER_OPERATOR(fused_elemwise_add_activation_grad, REGISTER_OP_CPU_KERNEL( fused_elemwise_add_activation, - ops::FusedElemwiseActivationKernel, - ops::FusedElemwiseActivationKernel); + ops::FusedElemwiseActivationKernel, + ops::FusedElemwiseActivationKernel); REGISTER_OP_CPU_KERNEL( fused_elemwise_add_activation_grad, - ops::FusedElemwiseActivationGradKernel, - ops::FusedElemwiseActivationGradKernel); + ops::FusedElemwiseActivationGradKernel, + ops::FusedElemwiseActivationGradKernel); diff --git a/paddle/fluid/operators/fused/fused_embedding_fc_lstm_op.cc b/paddle/fluid/operators/fused/fused_embedding_fc_lstm_op.cc index aae3be9aca5683df997ffb3b82d8ba38e82a530a..8f413f34242a8c4b1130de87cf0d01c102506116 100644 --- a/paddle/fluid/operators/fused/fused_embedding_fc_lstm_op.cc +++ b/paddle/fluid/operators/fused/fused_embedding_fc_lstm_op.cc @@ -391,7 +391,7 @@ class FusedEmbeddingFCLSTMKernel : public framework::OpKernel { GET_Ht(ct, gates, ht) void SeqCompute(const framework::ExecutionContext& ctx) const { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; INIT_BASE_INPUT_OUTPUT INIT_BASE_SIZES INIT_VEC_FUNC @@ -496,7 +496,7 @@ class FusedEmbeddingFCLSTMKernel : public framework::OpKernel { } void BatchCompute(const framework::ExecutionContext& ctx) const { - using DeviceContext = platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; INIT_BASE_INPUT_OUTPUT if (ids->lod()[0].size() == 2) { SeqCompute(ctx); diff --git a/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.h b/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.h index 937203c92fbf4464f15ecf3c70c1980bae65ffca..c593c65618d788f952e3a696bc8716cb19d8190b 100644 --- a/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.h +++ b/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.h @@ -197,7 +197,7 @@ class FusedEmbeddingSeqPoolKernel : public framework::OpKernel { const int m = batch_size * idx_width; const int n = table_width; const int k = table_height; - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); blas.CSRMM(&transa, &m, &n, @@ -313,7 +313,7 @@ class FusedEmbeddingSeqPoolGradKernel : public framework::OpKernel { padding_idx); auto *d_output_data = d_output->data(); - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); int width = static_cast(table_dim[1]); int num_seq = batch_size * idx_width; LOG(INFO) << "num seq = " << num_seq << " width = " << width; diff --git a/paddle/fluid/operators/fused/fusion_gru_op.cc b/paddle/fluid/operators/fused/fusion_gru_op.cc index 9e31d6cfcfb6e6891efed9017a3f39f5fb2655ed..9556ed12880aecb45baa7a62d74c7cd9e2ccd050 100644 --- a/paddle/fluid/operators/fused/fusion_gru_op.cc +++ b/paddle/fluid/operators/fused/fusion_gru_op.cc @@ -310,7 +310,7 @@ class FusionGRUKernel : public framework::OpKernel { T* xx_data = xx->mutable_data(place) void SeqCompute(const framework::ExecutionContext& ctx) const { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; INIT_BASE_DEFINES; INIT_OTHER_DEFINES; const int N = x_lod[0].size() - 1; @@ -400,7 +400,7 @@ class FusionGRUKernel : public framework::OpKernel { } void BatchCompute(const framework::ExecutionContext& ctx) const { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; INIT_BASE_DEFINES; if (x_lod[0].size() == 2) { xx->Resize({total_T, D3}); diff --git a/paddle/fluid/operators/fused/fusion_lstm_op.cc b/paddle/fluid/operators/fused/fusion_lstm_op.cc index 282b0a22a8cbe5cbc6306df5e7e43c471dc173b6..5454c90b3c59618fc8c028265adfec1ce81d4b1f 100644 --- a/paddle/fluid/operators/fused/fusion_lstm_op.cc +++ b/paddle/fluid/operators/fused/fusion_lstm_op.cc @@ -306,23 +306,23 @@ This operator fuse the X into LSTM, more details can refer to LSTM op. template class FuisonLSTMKernel : public framework::OpKernel { public: -#define INIT_BASE_DEFINES \ - using DeviceContext = paddle::platform::CPUDeviceContext; \ - auto* x = ctx.Input("X"); \ - auto* h0 = ctx.Input("H0"); \ - auto* c0 = ctx.Input("C0"); \ - auto* wx = ctx.Input("WeightX"); \ - auto* wh = ctx.Input("WeightH"); \ - auto* bias = ctx.Input("Bias"); \ - auto* xx = ctx.Output("XX"); \ - auto* hidden_out = ctx.Output("Hidden"); \ - auto* cell_out = ctx.Output("Cell"); \ - bool is_reverse = ctx.Attr("is_reverse"); \ - bool use_peepholes = ctx.Attr("use_peepholes"); \ - auto x_dims = x->dims(); /* T x M*/ \ - auto wh_dims = wh->dims(); /* D x 4D*/ \ - const int M = x_dims[1]; \ - const int D = wh_dims[0]; \ +#define INIT_BASE_DEFINES \ + using DeviceContext = phi::CPUContext; \ + auto* x = ctx.Input("X"); \ + auto* h0 = ctx.Input("H0"); \ + auto* c0 = ctx.Input("C0"); \ + auto* wx = ctx.Input("WeightX"); \ + auto* wh = ctx.Input("WeightH"); \ + auto* bias = ctx.Input("Bias"); \ + auto* xx = ctx.Output("XX"); \ + auto* hidden_out = ctx.Output("Hidden"); \ + auto* cell_out = ctx.Output("Cell"); \ + bool is_reverse = ctx.Attr("is_reverse"); \ + bool use_peepholes = ctx.Attr("use_peepholes"); \ + auto x_dims = x->dims(); /* T x M*/ \ + auto wh_dims = wh->dims(); /* D x 4D*/ \ + const int M = x_dims[1]; \ + const int D = wh_dims[0]; \ const int D4 = wh_dims[1] #define INIT_OTHER_DEFINES \ diff --git a/paddle/fluid/operators/fused/fusion_seqconv_eltadd_relu_op.cc b/paddle/fluid/operators/fused/fusion_seqconv_eltadd_relu_op.cc index e88deeae21431dc9fc7e43abf4e82822acaee870..2ebac6d7f71249e7fc08d7c3fb24882893cfc59c 100644 --- a/paddle/fluid/operators/fused/fusion_seqconv_eltadd_relu_op.cc +++ b/paddle/fluid/operators/fused/fusion_seqconv_eltadd_relu_op.cc @@ -149,7 +149,7 @@ template class FusionSeqConvEltAddReluKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; auto* x = ctx.Input("X"); auto* w = ctx.Input("Filter"); auto* b = ctx.Input("Bias"); diff --git a/paddle/fluid/operators/fused/fusion_seqexpand_concat_fc_op.cc b/paddle/fluid/operators/fused/fusion_seqexpand_concat_fc_op.cc index f022d4156f4fa43f7468000146a8dafab68545f5..6655c6756a5c889ee156168bb861557b0495436a 100644 --- a/paddle/fluid/operators/fused/fusion_seqexpand_concat_fc_op.cc +++ b/paddle/fluid/operators/fused/fusion_seqexpand_concat_fc_op.cc @@ -149,7 +149,7 @@ template class FusionSeqExpandConcatFCOpKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; auto ins = ctx.MultiInput("X"); auto* w = ctx.Input("FCWeight"); auto* b = ctx.Input("FCBias"); @@ -239,7 +239,7 @@ class FusionSeqExpandConcatFCOpKernel : public framework::OpKernel { auto blas = phi::funcs::GetBlas(ctx); - auto& dev_ctx = ctx.template device_context(); + auto& dev_ctx = ctx.template device_context(); phi::funcs::FCFunctor fc; fc(dev_ctx, total_T, diff --git a/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc b/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc index 7b72f84191e044b97a842aa53b25e3c2b06ec62a..ff983684708aaadf8a1613c36ad5d76527003ed5 100644 --- a/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc +++ b/paddle/fluid/operators/fused/mkldnn/fusion_gru_mkldnn_op.cc @@ -22,9 +22,9 @@ namespace operators { using paddle::framework::LoDTensor; using paddle::framework::Tensor; -using paddle::platform::CPUDeviceContext; using paddle::platform::MKLDNNGetDataType; using paddle::platform::MKLDNNMemDesc; +using phi::CPUContext; using platform::to_void_cast; template diff --git a/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc b/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc index 1258e6bfaf21c357385e3e8908e7d1b53adff26d..748de5dae9520a6b238213cf77751ce3cdc7af74 100644 --- a/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc +++ b/paddle/fluid/operators/fused/mkldnn/fusion_lstm_mkldnn_op.cc @@ -22,9 +22,9 @@ namespace operators { using paddle::framework::LoDTensor; using paddle::framework::Tensor; -using paddle::platform::CPUDeviceContext; using paddle::platform::MKLDNNGetDataType; using paddle::platform::MKLDNNMemDesc; +using phi::CPUContext; using platform::to_void_cast; template diff --git a/paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h b/paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h index b999dddf8cfb034b93daa7f891c1e5950f1eaabd..a357a59a09420be8bf89000643270a4c854b472f 100644 --- a/paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h +++ b/paddle/fluid/operators/fused/mkldnn/fusion_rnn_mkldnn.h @@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#pragma once + #include "paddle/fluid/platform/mkldnn_reuse.h" namespace paddle { @@ -19,10 +21,10 @@ namespace operators { using paddle::framework::LoDTensor; using paddle::framework::Tensor; -using paddle::platform::CPUDeviceContext; using paddle::platform::CreateKey; using paddle::platform::MKLDNNGetDataType; using paddle::platform::MKLDNNMemDesc; +using phi::CPUContext; using platform::to_void_cast; template diff --git a/paddle/fluid/operators/fused/mkldnn/multi_gru_mkldnn_op.cc b/paddle/fluid/operators/fused/mkldnn/multi_gru_mkldnn_op.cc index 44b39b7a80ab721b2d931ccd9d0f49df8f8d1215..c59e7d661607c7c8b1deceaeb80898c6bfdcdc34 100644 --- a/paddle/fluid/operators/fused/mkldnn/multi_gru_mkldnn_op.cc +++ b/paddle/fluid/operators/fused/mkldnn/multi_gru_mkldnn_op.cc @@ -28,10 +28,10 @@ namespace operators { using paddle::framework::LoDTensor; using paddle::framework::Tensor; -using paddle::platform::CPUDeviceContext; using paddle::platform::CreateKey; using paddle::platform::MKLDNNGetDataType; using paddle::platform::MKLDNNMemDesc; +using phi::CPUContext; using phi::vectorize; using platform::to_void_cast; using Direction = dnnl::rnn_direction; diff --git a/paddle/fluid/operators/fused_softmax_mask_op.cc b/paddle/fluid/operators/fused_softmax_mask_op.cc index 013e214b426e52d45c9b752d264ba988bab35140..11c1fa4af8560341c807a672dc2a8ff9f34b487f 100644 --- a/paddle/fluid/operators/fused_softmax_mask_op.cc +++ b/paddle/fluid/operators/fused_softmax_mask_op.cc @@ -117,7 +117,6 @@ REGISTER_OPERATOR(fused_softmax_mask, ops::SoftmaxMaskFuseGradOpMaker, ops::SoftmaxMaskFuseGradOpMaker); REGISTER_OPERATOR(fused_softmax_mask_grad, ops::SoftmaxMaskFuseOpGrad); -REGISTER_OP_CPU_KERNEL( - fused_softmax_mask, - ops::SoftmaxMaskFuseCPUKernel, - ops::SoftmaxMaskFuseCPUKernel); +REGISTER_OP_CPU_KERNEL(fused_softmax_mask, + ops::SoftmaxMaskFuseCPUKernel, + ops::SoftmaxMaskFuseCPUKernel); diff --git a/paddle/fluid/operators/fused_softmax_mask_upper_triangle_op.cc b/paddle/fluid/operators/fused_softmax_mask_upper_triangle_op.cc index f1748ad93124722cc1b003bef518b5ecec340c77..5992fa2dfc6e42f7f5c4a53370ca03d0be160741 100644 --- a/paddle/fluid/operators/fused_softmax_mask_upper_triangle_op.cc +++ b/paddle/fluid/operators/fused_softmax_mask_upper_triangle_op.cc @@ -104,10 +104,7 @@ REGISTER_OPERATOR( ops::SoftmaxMaskFuseUpperTriangleGradOpMaker); REGISTER_OPERATOR(fused_softmax_mask_upper_triangle_grad, ops::SoftmaxMaskFuseUpperTriangleOpGrad); -REGISTER_OP_CPU_KERNEL(fused_softmax_mask_upper_triangle, - ops::SoftmaxMaskFuseUpperTriangleCPUKernel< - paddle::platform::CPUDeviceContext, - float>, - ops::SoftmaxMaskFuseUpperTriangleCPUKernel< - paddle::platform::CPUDeviceContext, - double>); +REGISTER_OP_CPU_KERNEL( + fused_softmax_mask_upper_triangle, + ops::SoftmaxMaskFuseUpperTriangleCPUKernel, + ops::SoftmaxMaskFuseUpperTriangleCPUKernel); diff --git a/paddle/fluid/operators/gather_test.cc b/paddle/fluid/operators/gather_test.cc index 676143bf01145c546ccb0ef8a24ab75e7f2c2ac7..11c46d1772957073aefd0d30eae39f6b1079a2af 100644 --- a/paddle/fluid/operators/gather_test.cc +++ b/paddle/fluid/operators/gather_test.cc @@ -39,7 +39,7 @@ TEST(Gather, GatherData) { paddle::platform::CPUPlace()); auto* cpu_place = new paddle::platform::CPUPlace(); - paddle::platform::CPUDeviceContext ctx(*cpu_place); + phi::CPUContext ctx(*cpu_place); phi::funcs::CPUGather(ctx, *src, *index, output); delete cpu_place; cpu_place = NULL; diff --git a/paddle/fluid/operators/graph_khop_sampler_op.cc b/paddle/fluid/operators/graph_khop_sampler_op.cc index 7f45b495185948e91c8a84e06326ddfb749b2106..4702d66c3ccb3ff1b9aab68f429f6a6a288882d0 100644 --- a/paddle/fluid/operators/graph_khop_sampler_op.cc +++ b/paddle/fluid/operators/graph_khop_sampler_op.cc @@ -132,7 +132,7 @@ Graph Learning Sampling Neighbors operator, for graphsage sampling method. } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR(graph_khop_sampler, ops::GraphKhopSamplerOP, diff --git a/paddle/fluid/operators/gru_op.cc b/paddle/fluid/operators/gru_op.cc index d3c06ea496f1a13f57c84b7f9db692c743a89eca..f5cfd7a162c8da1d8ea126423d8ed662ae22a01d 100644 --- a/paddle/fluid/operators/gru_op.cc +++ b/paddle/fluid/operators/gru_op.cc @@ -318,7 +318,7 @@ template class GRUCPUKernel : public framework::OpKernel { public: void BatchCompute(const framework::ExecutionContext& context) const { - using DeviceContext = paddle::platform::CPUDeviceContext; + using DeviceContext = phi::CPUContext; using LodTensorPtr = LoDTensor*; bool is_test = context.Attr("is_test"); @@ -588,7 +588,6 @@ REGISTER_OPERATOR(gru_grad, REGISTER_OP_CPU_KERNEL(gru, ops::GRUCPUKernel, ops::GRUCPUKernel); -REGISTER_OP_CPU_KERNEL( - gru_grad, - ops::GRUGradKernel, - ops::GRUGradKernel); +REGISTER_OP_CPU_KERNEL(gru_grad, + ops::GRUGradKernel, + ops::GRUGradKernel); diff --git a/paddle/fluid/operators/gru_unit_op.cc b/paddle/fluid/operators/gru_unit_op.cc index 404d434a88058af92f33488b86cac6a0be8d5590..24d4771fac539d602aaf8d62bdd25f6b0875529c 100644 --- a/paddle/fluid/operators/gru_unit_op.cc +++ b/paddle/fluid/operators/gru_unit_op.cc @@ -325,11 +325,9 @@ REGISTER_OPERATOR(gru_unit_grad, ops::GRUUnitGradOp, ops::GRUUnitGradOpNoNeedBufferVarInferer); -REGISTER_OP_CPU_KERNEL( - gru_unit, - ops::GRUUnitKernel, - ops::GRUUnitKernel); -REGISTER_OP_CPU_KERNEL( - gru_unit_grad, - ops::GRUUnitGradKernel, - ops::GRUUnitGradKernel); +REGISTER_OP_CPU_KERNEL(gru_unit, + ops::GRUUnitKernel, + ops::GRUUnitKernel); +REGISTER_OP_CPU_KERNEL(gru_unit_grad, + ops::GRUUnitGradKernel, + ops::GRUUnitGradKernel); diff --git a/paddle/fluid/operators/hinge_loss_op.cc b/paddle/fluid/operators/hinge_loss_op.cc index 8de20d53ba8fa5ada910874762ec5fff95de4d5b..835312851b2e42210c54992938cb217faf73ae91 100644 --- a/paddle/fluid/operators/hinge_loss_op.cc +++ b/paddle/fluid/operators/hinge_loss_op.cc @@ -150,12 +150,10 @@ REGISTER_OPERATOR(hinge_loss, ops::HingeLossGradOpMaker, ops::HingeLossGradOpMaker); REGISTER_OPERATOR(hinge_loss_grad, ops::HingeLossGradOp); -REGISTER_OP_CPU_KERNEL( - hinge_loss, - ops::HingeLossKernel); -REGISTER_OP_CPU_KERNEL( - hinge_loss_grad, - ops::HingeLossGradKernel); +REGISTER_OP_CPU_KERNEL(hinge_loss, + ops::HingeLossKernel); +REGISTER_OP_CPU_KERNEL(hinge_loss_grad, + ops::HingeLossGradKernel); REGISTER_OP_CUDA_KERNEL( hinge_loss, diff --git a/paddle/fluid/operators/im2sequence_op.cc b/paddle/fluid/operators/im2sequence_op.cc index ae8c91e2444ab68511905343ea7b3a3e28eaf851..dce0ca7a646fd54dfcac352977164e5509c2e68e 100644 --- a/paddle/fluid/operators/im2sequence_op.cc +++ b/paddle/fluid/operators/im2sequence_op.cc @@ -195,12 +195,10 @@ REGISTER_OPERATOR(im2sequence, ops::Im2SequenceGradMaker, ops::Im2SequenceGradMaker); REGISTER_OPERATOR(im2sequence_grad, ops::Im2SequenceGradOp); -REGISTER_OP_CPU_KERNEL( - im2sequence, - ops::Im2SequenceKernel); -REGISTER_OP_CPU_KERNEL( - im2sequence_grad, - ops::Im2SequenceGradKernel); +REGISTER_OP_CPU_KERNEL(im2sequence, + ops::Im2SequenceKernel); +REGISTER_OP_CPU_KERNEL(im2sequence_grad, + ops::Im2SequenceGradKernel); REGISTER_OP_CUDA_KERNEL( im2sequence, diff --git a/paddle/fluid/operators/inplace_abn_op.cc b/paddle/fluid/operators/inplace_abn_op.cc index dfff354c4bd5ea82c3a81964e4326e154db2fb93..c1880d2a1a19410c916e3acae8c770cedf50dd10 100644 --- a/paddle/fluid/operators/inplace_abn_op.cc +++ b/paddle/fluid/operators/inplace_abn_op.cc @@ -382,11 +382,9 @@ REGISTER_OPERATOR(inplace_abn, InplaceAbnOpInplaceInferer) REGISTER_OPERATOR(inplace_abn_grad, ops::InplaceABNGradOp) -REGISTER_OP_CPU_KERNEL( - inplace_abn, - ops::InplaceABNKernel, - ops::InplaceABNKernel); -REGISTER_OP_CPU_KERNEL( - inplace_abn_grad, - ops::InplaceABNGradKernel, - ops::InplaceABNGradKernel); +REGISTER_OP_CPU_KERNEL(inplace_abn, + ops::InplaceABNKernel, + ops::InplaceABNKernel); +REGISTER_OP_CPU_KERNEL(inplace_abn_grad, + ops::InplaceABNGradKernel, + ops::InplaceABNGradKernel); diff --git a/paddle/fluid/operators/interpolate_op.h b/paddle/fluid/operators/interpolate_op.h index fd8d88ac940dee884b99c94b944807a441656818..ff474cfff9727c6c912576e1bb403e1f48bc11af 100644 --- a/paddle/fluid/operators/interpolate_op.h +++ b/paddle/fluid/operators/interpolate_op.h @@ -1201,8 +1201,8 @@ static void Interpolate1DCPUBwd(const framework::ExecutionContext& ctx, } input_grad->mutable_data(dim_grad, ctx.GetPlace()); - auto& device_ctx = ctx.template device_context(); - phi::funcs::SetConstant zero; + auto& device_ctx = ctx.template device_context(); + phi::funcs::SetConstant zero; zero(device_ctx, input_grad, static_cast(0.0)); if (in_w == out_w) { @@ -1279,8 +1279,8 @@ static void Interpolate2DCPUBwd(const framework::ExecutionContext& ctx, } input_grad->mutable_data(dim_grad, ctx.GetPlace()); - auto& device_ctx = ctx.template device_context(); - phi::funcs::SetConstant zero; + auto& device_ctx = ctx.template device_context(); + phi::funcs::SetConstant zero; zero(device_ctx, input_grad, static_cast(0.0)); if (in_h == out_h && in_w == out_w) { @@ -1393,8 +1393,8 @@ static void Interpolate3DCPUBwd(const framework::ExecutionContext& ctx, dim_grad = {n, in_d, in_h, in_w, c}; } input_grad->mutable_data(dim_grad, ctx.GetPlace()); - auto& device_ctx = ctx.template device_context(); - phi::funcs::SetConstant zero; + auto& device_ctx = ctx.template device_context(); + phi::funcs::SetConstant zero; zero(device_ctx, input_grad, static_cast(0.0)); if (in_d == out_d && in_h == out_h && in_w == out_w) { diff --git a/paddle/fluid/operators/inverse_op.cc b/paddle/fluid/operators/inverse_op.cc index 3c84b7c983effa236ddec0ffa699a6adb0dd7bc4..e93ca5ad54035d16e64a85ebb0ddc1147e9be6b5 100644 --- a/paddle/fluid/operators/inverse_op.cc +++ b/paddle/fluid/operators/inverse_op.cc @@ -137,11 +137,9 @@ REGISTER_OPERATOR(inverse, REGISTER_OPERATOR(inverse_grad, ops::InverseGradOp); -REGISTER_OP_CPU_KERNEL( - inverse, - ops::InverseKernel, - ops::InverseKernel); -REGISTER_OP_CPU_KERNEL( - inverse_grad, - ops::InverseGradKernel, - ops::InverseGradKernel); +REGISTER_OP_CPU_KERNEL(inverse, + ops::InverseKernel, + ops::InverseKernel); +REGISTER_OP_CPU_KERNEL(inverse_grad, + ops::InverseGradKernel, + ops::InverseGradKernel); diff --git a/paddle/fluid/operators/isfinite_op.cc b/paddle/fluid/operators/isfinite_op.cc index bcab28df3a155aae89ec9aca0ab3c26d1aa5b817..77583fd2d30f156741189d73c588612036245568 100644 --- a/paddle/fluid/operators/isfinite_op.cc +++ b/paddle/fluid/operators/isfinite_op.cc @@ -122,64 +122,35 @@ namespace ops = paddle::operators; paddle::framework::EmptyGradOpMaker, \ paddle::framework::EmptyGradOpMaker) -#define REGISTER_OVERFLOW_CPU_KERNEL(op_type, functor) \ - REGISTER_OP_CPU_KERNEL( \ - op_type, \ - ops::OverflowKernel, \ - ops::OverflowKernel, \ - ops::OverflowKernel, \ - ops::OverflowKernel); +#define REGISTER_OVERFLOW_CPU_KERNEL(op_type, functor) \ + REGISTER_OP_CPU_KERNEL( \ + op_type, \ + ops::OverflowKernel, \ + ops::OverflowKernel, \ + ops::OverflowKernel, \ + ops::OverflowKernel); REGISTER_OP_MAKER(isinf, "isinf(X)"); REGISTER_OP_MAKER(isnan, "isnan(X)"); REGISTER_OP_MAKER(isfinite, "isfinite(X)"); -REGISTER_OP_CPU_KERNEL(isinf, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CPU_KERNEL(isnan, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); - -REGISTER_OP_CPU_KERNEL(isfinite, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel, - ops::OverflowKernel); +REGISTER_OP_CPU_KERNEL( + isinf, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel); + +REGISTER_OP_CPU_KERNEL( + isnan, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel); + +REGISTER_OP_CPU_KERNEL( + isfinite, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel, + ops::OverflowKernel); diff --git a/paddle/fluid/operators/l1_norm_op.cc b/paddle/fluid/operators/l1_norm_op.cc index 56e1c19721378acacb5fd2d220e1ec7aab09a3f0..c7bf0d538bd97912463a4675e4907bd65136983a 100644 --- a/paddle/fluid/operators/l1_norm_op.cc +++ b/paddle/fluid/operators/l1_norm_op.cc @@ -93,11 +93,9 @@ REGISTER_OPERATOR(l1_norm, ops::L1NormGradMaker, ops::L1NormGradMaker); REGISTER_OPERATOR(l1_norm_grad, ops::L1NormGradOp); -REGISTER_OP_CPU_KERNEL( - l1_norm, ops::L1NormKernel); -REGISTER_OP_CPU_KERNEL( - l1_norm_grad, - ops::L1NormGradKernel); +REGISTER_OP_CPU_KERNEL(l1_norm, ops::L1NormKernel); +REGISTER_OP_CPU_KERNEL(l1_norm_grad, + ops::L1NormGradKernel); REGISTER_OP_CUDA_KERNEL( l1_norm, ops::L1NormKernel); diff --git a/paddle/fluid/operators/linear_chain_crf_op.cc b/paddle/fluid/operators/linear_chain_crf_op.cc index 397b26e119416393f0e2f27cc179a5a16c0dee78..99c10e868a396e8f9d5787ec915b3e48484f3611 100644 --- a/paddle/fluid/operators/linear_chain_crf_op.cc +++ b/paddle/fluid/operators/linear_chain_crf_op.cc @@ -395,12 +395,10 @@ REGISTER_OPERATOR(linear_chain_crf, REGISTER_OPERATOR(linear_chain_crf_grad, ops::LinearChainCRFGradOp, ops::LinearChainCRFGradNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - linear_chain_crf, - ops::LinearChainCRFOpKernel, - ops::LinearChainCRFOpKernel); +REGISTER_OP_CPU_KERNEL(linear_chain_crf, + ops::LinearChainCRFOpKernel, + ops::LinearChainCRFOpKernel); REGISTER_OP_CPU_KERNEL( linear_chain_crf_grad, - ops::LinearChainCRFGradOpKernel, - ops::LinearChainCRFGradOpKernel); + ops::LinearChainCRFGradOpKernel, + ops::LinearChainCRFGradOpKernel); diff --git a/paddle/fluid/operators/linear_chain_crf_op.h b/paddle/fluid/operators/linear_chain_crf_op.h index 8d345b237bfc53b8b4f3d03f5c1ee2907869048a..de6daf33f8426f3531dfc2673c1c629c583b0bef 100644 --- a/paddle/fluid/operators/linear_chain_crf_op.h +++ b/paddle/fluid/operators/linear_chain_crf_op.h @@ -129,8 +129,8 @@ class LinearChainCRFOpKernel : public framework::OpKernel { emission_row_max.mutable_data( phi::make_ddim({static_cast(batch_size), 1}), platform::CPUPlace()); - auto& place = *ctx.template device_context() - .eigen_device(); + auto& place = + *ctx.template device_context().eigen_device(); auto x = framework::EigenMatrix::From(emission_weights_tmp); auto x_row_max = framework::EigenMatrix::From(emission_row_max); x_row_max.device(place) = @@ -325,21 +325,20 @@ class LinearChainCRFGradOpKernel : public framework::OpKernel { Tensor one_seq_beta = beta.Slice(start_pos, end_pos); Tensor one_seq_emission_grad = emission_grad_tmp.Slice(start_pos, end_pos); - BackwardOneSequence( - ctx.template device_context(), - ll_grad[i], - one_seq_emission_exps, - *transition_exps, - one_seq_alpha, - one_seq_label, - &one_seq_beta, - transition_grad, - &one_seq_emission_grad); + BackwardOneSequence(ctx.template device_context(), + ll_grad[i], + one_seq_emission_exps, + *transition_exps, + one_seq_alpha, + one_seq_label, + &one_seq_beta, + transition_grad, + &one_seq_emission_grad); } }; private: - void BackwardOneSequence(const platform::CPUDeviceContext& ctx, + void BackwardOneSequence(const phi::CPUContext& ctx, const T ll_grad, const Tensor& emission_exps, const Tensor& transition_exps, diff --git a/paddle/fluid/operators/lite/lite_engine_op_test.cc b/paddle/fluid/operators/lite/lite_engine_op_test.cc index c38386365f3dcf14bdf0ba555f85fde6a601e488..fed71abe16637ff5d791fcca51d5398e162d5eb0 100644 --- a/paddle/fluid/operators/lite/lite_engine_op_test.cc +++ b/paddle/fluid/operators/lite/lite_engine_op_test.cc @@ -79,7 +79,7 @@ TEST(LiteEngineOp, engine_op) { ctx.PartialInitWithAllocator(); #else platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); #endif // Prepare variables. CreateTensor(&scope, "x", std::vector({2, 4}), true); diff --git a/paddle/fluid/operators/lite/ut_helper.h b/paddle/fluid/operators/lite/ut_helper.h index c1a67edbfd4559063b11758e11798a9e64fe786d..574b7cbec28ce9f7ffcd1157f0be677a957a50f1 100644 --- a/paddle/fluid/operators/lite/ut_helper.h +++ b/paddle/fluid/operators/lite/ut_helper.h @@ -60,7 +60,7 @@ void serialize_params(std::string* str, platform::CUDAPlace place; platform::CUDADeviceContext ctx(place); #else - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; #endif for (const auto& param : params) { PADDLE_ENFORCE_NOT_NULL( diff --git a/paddle/fluid/operators/load_combine_op.cc b/paddle/fluid/operators/load_combine_op.cc index 65d8a03245f8f2742368955ee81b4d43cfa0929d..94bfc44977fb34e72515abc2acfbd92a48687222 100644 --- a/paddle/fluid/operators/load_combine_op.cc +++ b/paddle/fluid/operators/load_combine_op.cc @@ -86,10 +86,9 @@ REGISTER_OPERATOR(load_combine, REGISTER_OP_CPU_KERNEL( load_combine, - ops::LoadCombineOpKernel, - ops::LoadCombineOpKernel, - ops::LoadCombineOpKernel, - ops::LoadCombineOpKernel, - ops::LoadCombineOpKernel, - ops::LoadCombineOpKernel); + ops::LoadCombineOpKernel, + ops::LoadCombineOpKernel, + ops::LoadCombineOpKernel, + ops::LoadCombineOpKernel, + ops::LoadCombineOpKernel, + ops::LoadCombineOpKernel); diff --git a/paddle/fluid/operators/load_op.cc b/paddle/fluid/operators/load_op.cc index c1a9782b97a4c1c70fdd6564187a898b8b6612a9..4eebda7d53a3c0f4f1d02f01813a6325bca5c0d9 100644 --- a/paddle/fluid/operators/load_op.cc +++ b/paddle/fluid/operators/load_op.cc @@ -68,10 +68,9 @@ REGISTER_OPERATOR(load, ops::LoadOp, ops::LoadOpProtoMaker); REGISTER_OP_CPU_KERNEL( load, - ops::LoadOpKernel, - ops::LoadOpKernel, - ops::LoadOpKernel, - ops::LoadOpKernel, - ops::LoadOpKernel, - ops::LoadOpKernel); + ops::LoadOpKernel, + ops::LoadOpKernel, + ops::LoadOpKernel, + ops::LoadOpKernel, + ops::LoadOpKernel, + ops::LoadOpKernel); diff --git a/paddle/fluid/operators/lod_tensor_to_array_op.cc b/paddle/fluid/operators/lod_tensor_to_array_op.cc index 4c1a2deeaf4806d887723410efb68849d7644062..147b23f56acdcfca0c3daf265a3121a6fbbe42e7 100644 --- a/paddle/fluid/operators/lod_tensor_to_array_op.cc +++ b/paddle/fluid/operators/lod_tensor_to_array_op.cc @@ -62,7 +62,7 @@ struct LoDTensorToArrayFunctor : public boost::static_visitor { auto &pool = platform::DeviceContextPool::Instance(); auto *dev_ctx = pool.Get(place); if (std::is_same::value) { - Apply(static_cast(dev_ctx)); + Apply(static_cast(dev_ctx)); } else { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) Apply(static_cast(dev_ctx)); diff --git a/paddle/fluid/operators/lookup_table_op.h b/paddle/fluid/operators/lookup_table_op.h index 3ca39e621b2a49043610715463cf4445d9eb90ac..31a3e40f12e828ec3ead10b0a7590ea732903c48 100644 --- a/paddle/fluid/operators/lookup_table_op.h +++ b/paddle/fluid/operators/lookup_table_op.h @@ -116,8 +116,7 @@ class LookupTableKernel : public framework::OpKernel { table + id_index * row_width, row_width * sizeof(T)); } else { - auto blas = - phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); blas.VCOPY(row_width, table + id_index * row_width, output + i * row_width); @@ -148,8 +147,7 @@ class LookupTableKernel : public framework::OpKernel { table + id_index * row_width, row_width * sizeof(T)); } else { - auto blas = - phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); blas.VCOPY(row_width, table + id_index * row_width, output + i * row_width); diff --git a/paddle/fluid/operators/lookup_table_v2_op.h b/paddle/fluid/operators/lookup_table_v2_op.h index 9f9dbe9b336bdf92f79459984a7cd65df51330a2..1e12b00ebb944c8691c7ead7303712c376066db3 100644 --- a/paddle/fluid/operators/lookup_table_v2_op.h +++ b/paddle/fluid/operators/lookup_table_v2_op.h @@ -132,8 +132,7 @@ struct LookupTableV2CPUFunctor { table + id_index * row_width, row_width * sizeof(T)); } else { - auto blas = - phi::funcs::GetBlas(context_); + auto blas = phi::funcs::GetBlas(context_); blas.VCOPY(row_width, table + id_index * row_width, output + i * row_width); diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index 8ec7f3a142c307489a604389fc95eb08e40ba9f8..73fe170f6d5e856b627065602400515d5c8ea62e 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -31,7 +31,7 @@ using framework::Tensor; using DataLayout = framework::DataLayout; template -struct LRNFunctor { +struct LRNFunctor { void operator()(const framework::ExecutionContext& ctx, const framework::Tensor& input, framework::Tensor* out, @@ -46,9 +46,9 @@ struct LRNFunctor { T beta, const DataLayout data_layout) { auto place = ctx.GetPlace(); - auto blas = phi::funcs::GetBlas(ctx); - phi::funcs::Transpose transpose; - auto& dev_ctx = ctx.template device_context(); + auto blas = phi::funcs::GetBlas(ctx); + phi::funcs::Transpose transpose; + auto& dev_ctx = ctx.template device_context(); Tensor in_transpose, mid_transpose, out_transpose; // if channel_last, transpose to channel_first if (data_layout == DataLayout::kNHWC) { @@ -116,11 +116,11 @@ struct LRNFunctor { } } }; -template struct LRNFunctor; -template struct LRNFunctor; +template struct LRNFunctor; +template struct LRNFunctor; template -struct LRNGradFunctor { +struct LRNGradFunctor { void operator()(const framework::ExecutionContext& ctx, const framework::Tensor& x, const framework::Tensor& out, @@ -183,8 +183,8 @@ struct LRNGradFunctor { } } }; -template struct LRNGradFunctor; -template struct LRNGradFunctor; +template struct LRNGradFunctor; +template struct LRNGradFunctor; class LRNOp : public framework::OperatorWithKernel { public: @@ -435,7 +435,5 @@ REGISTER_OPERATOR(lrn, ops::LRNGradOpMaker); REGISTER_OPERATOR(lrn_grad, ops::LRNOpGrad); -REGISTER_OP_CPU_KERNEL( - lrn, ops::LRNKernel); -REGISTER_OP_CPU_KERNEL( - lrn_grad, ops::LRNGradKernel); +REGISTER_OP_CPU_KERNEL(lrn, ops::LRNKernel); +REGISTER_OP_CPU_KERNEL(lrn_grad, ops::LRNGradKernel); diff --git a/paddle/fluid/operators/lstm_op.cc b/paddle/fluid/operators/lstm_op.cc index 668200cf4ff5d7e3fa15d932afbf7fbf9508051c..ba56eeddf89d18a344c043f05c905ef4681e3d73 100644 --- a/paddle/fluid/operators/lstm_op.cc +++ b/paddle/fluid/operators/lstm_op.cc @@ -356,11 +356,9 @@ REGISTER_OPERATOR(lstm, ops::LSTMGradOpMaker, ops::LSTMGradOpMaker); REGISTER_OPERATOR(lstm_grad, ops::LSTMGradOp); -REGISTER_OP_CPU_KERNEL( - lstm, - ops::LSTMKernel, - ops::LSTMKernel); -REGISTER_OP_CPU_KERNEL( - lstm_grad, - ops::LSTMGradKernel, - ops::LSTMGradKernel); +REGISTER_OP_CPU_KERNEL(lstm, + ops::LSTMKernel, + ops::LSTMKernel); +REGISTER_OP_CPU_KERNEL(lstm_grad, + ops::LSTMGradKernel, + ops::LSTMGradKernel); diff --git a/paddle/fluid/operators/lstmp_op.cc b/paddle/fluid/operators/lstmp_op.cc index bc064fb61caa4235a4690382d50544ded2d27e48..84e4e5cd2cdf837b13fe383dcc52cc34e713c623 100644 --- a/paddle/fluid/operators/lstmp_op.cc +++ b/paddle/fluid/operators/lstmp_op.cc @@ -400,11 +400,9 @@ REGISTER_OPERATOR(lstmp, ops::LSTMPGradMaker, ops::LSTMPGradMaker); REGISTER_OPERATOR(lstmp_grad, ops::LSTMPGradOp); -REGISTER_OP_CPU_KERNEL( - lstmp, - ops::LSTMPKernel, - ops::LSTMPKernel); -REGISTER_OP_CPU_KERNEL( - lstmp_grad, - ops::LSTMPGradKernel, - ops::LSTMPGradKernel); +REGISTER_OP_CPU_KERNEL(lstmp, + ops::LSTMPKernel, + ops::LSTMPKernel); +REGISTER_OP_CPU_KERNEL(lstmp_grad, + ops::LSTMPGradKernel, + ops::LSTMPGradKernel); diff --git a/paddle/fluid/operators/lstsq_op.cc b/paddle/fluid/operators/lstsq_op.cc index 792ede9959f77c791e1a0b8ef07a1cf204b01de2..70ce5082ced304069483a6e9fd435b42b0b0818e 100644 --- a/paddle/fluid/operators/lstsq_op.cc +++ b/paddle/fluid/operators/lstsq_op.cc @@ -150,7 +150,6 @@ This API processes Lstsq functor for general matrices. namespace ops = paddle::operators; REGISTER_OPERATOR(lstsq, ops::LstsqOp, ops::LstsqOpMaker) -REGISTER_OP_CPU_KERNEL( - lstsq, - ops::LstsqCPUKernel, - ops::LstsqCPUKernel); +REGISTER_OP_CPU_KERNEL(lstsq, + ops::LstsqCPUKernel, + ops::LstsqCPUKernel); diff --git a/paddle/fluid/operators/lu_op.cc b/paddle/fluid/operators/lu_op.cc index 1021b157ba374802f8d4b53e6e0a50fa82fa5f33..1f569950dad521e46c05f9cce887ca35c1a97748 100644 --- a/paddle/fluid/operators/lu_op.cc +++ b/paddle/fluid/operators/lu_op.cc @@ -114,9 +114,7 @@ class LUKernel : public framework::OpKernel { "lu without pivoting is not implemented on the CPU, " "but got pivots=False")); - math::DeviceIndependenceTensorOperations - helper(ctx); + math::DeviceIndependenceTensorOperations helper(ctx); *out = helper.Transpose(*xin); auto outdims = out->dims(); @@ -235,5 +233,5 @@ REGISTER_OPERATOR(lu_grad, REGISTER_OP_CPU_KERNEL(lu, ops::LUKernel, ops::LUKernel); REGISTER_OP_CPU_KERNEL(lu_grad, - ops::LUGradKernel, - ops::LUGradKernel); + ops::LUGradKernel, + ops::LUGradKernel); diff --git a/paddle/fluid/operators/lu_unpack_op.cc b/paddle/fluid/operators/lu_unpack_op.cc index b696f3fbd04bb95d10251f485e9ab9b8795f3401..4c6b37ed3e55e0b53a5747aa81518c58cfff1190 100644 --- a/paddle/fluid/operators/lu_unpack_op.cc +++ b/paddle/fluid/operators/lu_unpack_op.cc @@ -186,9 +186,8 @@ REGISTER_OPERATOR(lu_unpack_grad, ops::LU_UnpackGradOpVarTypeInference); REGISTER_OP_CPU_KERNEL(lu_unpack, - ops::LU_UnpackKernel, - ops::LU_UnpackKernel); -REGISTER_OP_CPU_KERNEL( - lu_unpack_grad, - ops::LU_UnpackGradKernel, - ops::LU_UnpackGradKernel); + ops::LU_UnpackKernel, + ops::LU_UnpackKernel); +REGISTER_OP_CPU_KERNEL(lu_unpack_grad, + ops::LU_UnpackGradKernel, + ops::LU_UnpackGradKernel); diff --git a/paddle/fluid/operators/margin_rank_loss_op.cc b/paddle/fluid/operators/margin_rank_loss_op.cc index 4b11497058e43cf22b3a994d380b45d601a9bd6f..44f77afee00054758033212c46accd4ecc95b36f 100644 --- a/paddle/fluid/operators/margin_rank_loss_op.cc +++ b/paddle/fluid/operators/margin_rank_loss_op.cc @@ -181,9 +181,7 @@ REGISTER_OPERATOR(margin_rank_loss, ops::MarginRankLossGradMaker, ops::MarginRankLossGradMaker); REGISTER_OPERATOR(margin_rank_loss_grad, ops::MarginRankLossGradOp); -REGISTER_OP_CPU_KERNEL( - margin_rank_loss, - ops::MarginRankLossKernel); -REGISTER_OP_CPU_KERNEL( - margin_rank_loss_grad, - ops::MarginRankLossGradKernel); +REGISTER_OP_CPU_KERNEL(margin_rank_loss, + ops::MarginRankLossKernel); +REGISTER_OP_CPU_KERNEL(margin_rank_loss_grad, + ops::MarginRankLossGradKernel); diff --git a/paddle/fluid/operators/match_matrix_tensor_op.cc b/paddle/fluid/operators/match_matrix_tensor_op.cc index d6a39faea519c0c0053a3a2684b34083d3ba9994..992d9e9f276c44d71643d6f59d4c5edf1086b725 100644 --- a/paddle/fluid/operators/match_matrix_tensor_op.cc +++ b/paddle/fluid/operators/match_matrix_tensor_op.cc @@ -273,7 +273,7 @@ class CPUMatchMatrixTensorOPKernel : public framework::OpKernel { memset( bottom_l_trans_data, 0.0, tmp->dims()[0] * tmp->dims()[1] * sizeof(T)); - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); call_gemm(blas, CblasNoTrans, @@ -295,7 +295,7 @@ class CPUMatchMatrixTensorOPKernel : public framework::OpKernel { const auto* l_t_data = bottom_l_trans_data + offset_l[b] * dim_t * dim_in + t * dim_in; const auto* r_data = bottom_r_data + offset_r[b] * dim_in; - auto blas_2 = phi::funcs::GetBlas(ctx); + auto blas_2 = phi::funcs::GetBlas(ctx); call_gemm_with_lda(blas_2, CblasNoTrans, CblasTrans, @@ -388,7 +388,7 @@ class CPUMatchMatrixTensorOPGradKernel : public framework::OpKernel { } } - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); auto* t_data = w->data(); auto* d_w = ctx.Output(framework::GradVarName("W")); @@ -456,10 +456,8 @@ REGISTER_OPERATOR(match_matrix_tensor_grad, ops::MatchMatrixTensorOpGrad); REGISTER_OP_CPU_KERNEL( match_matrix_tensor, - ops::CPUMatchMatrixTensorOPKernel); + ops::CPUMatchMatrixTensorOPKernel); REGISTER_OP_CPU_KERNEL( match_matrix_tensor_grad, - ops::CPUMatchMatrixTensorOPGradKernel); + ops::CPUMatchMatrixTensorOPGradKernel); diff --git a/paddle/fluid/operators/math/beam_search_test.cc b/paddle/fluid/operators/math/beam_search_test.cc index b51b9ee0d675a536c18b67dc774be8fca889b010..f6b0349f1ca28124ecd5b6c3e0b894f027d7ab97 100644 --- a/paddle/fluid/operators/math/beam_search_test.cc +++ b/paddle/fluid/operators/math/beam_search_test.cc @@ -230,8 +230,7 @@ void TestBeamSearch(); + TestBeamSearch(); } #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) diff --git a/paddle/fluid/operators/math/concat_and_split.cc b/paddle/fluid/operators/math/concat_and_split.cc index 3df69e200190f85e041f746acd211405eff28902..603584629cc92adfe831c8df30a428003e5fcf74 100644 --- a/paddle/fluid/operators/math/concat_and_split.cc +++ b/paddle/fluid/operators/math/concat_and_split.cc @@ -38,9 +38,9 @@ namespace math { * each dimension must be the same, except the axis dimension. */ template -class ConcatFunctor { +class ConcatFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const std::vector& input, int axis, framework::Tensor* output) { @@ -54,9 +54,9 @@ class ConcatFunctor { * each dimension must be the same, except the axis dimension. */ template -class SplitFunctor { +class SplitFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::Tensor& input, const std::vector& ref_inputs, const int axis, @@ -335,9 +335,9 @@ class SplitFunctor { }; #endif -#define DEFINE_FUNCTOR(type) \ - template class ConcatFunctor; \ - template class SplitFunctor; +#define DEFINE_FUNCTOR(type) \ + template class ConcatFunctor; \ + template class SplitFunctor; FOR_ALL_TYPES(DEFINE_FUNCTOR); diff --git a/paddle/fluid/operators/math/concat_test.cc b/paddle/fluid/operators/math/concat_test.cc index 3ae314e55d87d5e44cf4cd4340d744a94780fb8c..4f0fee91e5919ad924299c75190ee523247f585b 100644 --- a/paddle/fluid/operators/math/concat_test.cc +++ b/paddle/fluid/operators/math/concat_test.cc @@ -493,8 +493,7 @@ void TestConcatMain(); + TestConcatMain(); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) TestConcatMain(); diff --git a/paddle/fluid/operators/math/cos_sim_functor.cc b/paddle/fluid/operators/math/cos_sim_functor.cc index 85f012afb505a05da35c04b9c9e86d90eff175ad..0daf46d36fd2170242c78c3f19f47acb6623d123 100644 --- a/paddle/fluid/operators/math/cos_sim_functor.cc +++ b/paddle/fluid/operators/math/cos_sim_functor.cc @@ -18,8 +18,8 @@ namespace paddle { namespace operators { namespace math { template -struct CosSimDyFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct CosSimDyFunctor { + void operator()(const phi::CPUContext& ctx, const T* x_norm, const T* y_norm, const T* x, @@ -46,8 +46,8 @@ struct CosSimDyFunctor { } }; -template struct CosSimDyFunctor; -template struct CosSimDyFunctor; +template struct CosSimDyFunctor; +template struct CosSimDyFunctor; } // namespace math } // namespace operators } // namespace paddle diff --git a/paddle/fluid/operators/math/eigen_values_vectors.h b/paddle/fluid/operators/math/eigen_values_vectors.h index dcbd66c12b91e652a8fbf20dbab4a1e919a4190f..a056341c3bf3ce44f8282da9fb9dd1971ac5492c 100644 --- a/paddle/fluid/operators/math/eigen_values_vectors.h +++ b/paddle/fluid/operators/math/eigen_values_vectors.h @@ -66,7 +66,7 @@ struct MatrixEighFunctor { // symmetric matrices, and uses the variable has_vectors to // control whether to return the eigenvectors. template -struct MatrixEighFunctor { +struct MatrixEighFunctor { public: void operator()(const framework::ExecutionContext &ctx, const Tensor &input, @@ -78,8 +78,7 @@ struct MatrixEighFunctor { auto *out_value = eigen_values->mutable_data(ctx.GetPlace()); auto dito = - math::DeviceIndependenceTensorOperations( - ctx); + math::DeviceIndependenceTensorOperations(ctx); Tensor input_trans; // lapack is a column-major storge, transpose make the input to diff --git a/paddle/fluid/operators/math/gru_compute.cc b/paddle/fluid/operators/math/gru_compute.cc index 7e543a63afc9e86e4d094b69b68b6c8bf44e6471..857d870847ee8c777daf56e638b2f41835bf1bd7 100644 --- a/paddle/fluid/operators/math/gru_compute.cc +++ b/paddle/fluid/operators/math/gru_compute.cc @@ -20,8 +20,8 @@ namespace operators { namespace math { template -struct GRUUnitFunctor { - static void compute(const platform::CPUDeviceContext &context, +struct GRUUnitFunctor { + static void compute(const phi::CPUContext &context, GRUMetaValue value, int frame_size, int batch_size, @@ -29,7 +29,7 @@ struct GRUUnitFunctor { const detail::ActivationType active_gate, bool origin_mode) { #if !defined(__NVCC__) && !defined(__HIPCC___) - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (value.prev_out_value) { blas.GEMM(false, false, @@ -83,8 +83,8 @@ struct GRUUnitFunctor { }; template -struct GRUUnitGradFunctor { - static void compute(const platform::CPUDeviceContext &context, +struct GRUUnitGradFunctor { + static void compute(const phi::CPUContext &context, GRUMetaValue value, GRUMetaGrad grad, int frame_size, @@ -100,7 +100,7 @@ struct GRUUnitGradFunctor { batch_size, active_node, origin_mode); - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (value.prev_out_value && grad.prev_out_grad) { blas.GEMM(false, true, @@ -175,15 +175,15 @@ struct GRUUnitGradFunctor { }; template -struct GRUUnitFunctorV2 { - static void compute(const platform::CPUDeviceContext &context, +struct GRUUnitFunctorV2 { + static void compute(const phi::CPUContext &context, GRUMetaValue value, int frame_size, int batch_size, const detail::ActivationType active_node, const detail::ActivationType active_gate) { #if !defined(__NVCC__) && !defined(__HIPCC___) - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (value.prev_out_value) { blas.GEMM(CblasNoTrans, CblasTrans, @@ -226,8 +226,8 @@ struct GRUUnitFunctorV2 { }; template -struct GRUUnitGradFunctorV2 { - static void compute(const platform::CPUDeviceContext &context, +struct GRUUnitGradFunctorV2 { + static void compute(const phi::CPUContext &context, GRUMetaValue value, GRUMetaGrad grad, int frame_size, @@ -245,7 +245,7 @@ struct GRUUnitGradFunctorV2 { batch_size, active_node, active_gate); - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (grad.prev_out_grad && value.prev_out_value) { // update prev_out_grad blas.GEMM(false, @@ -349,15 +349,15 @@ struct GRUUnitGradFunctorV2 { } }; -template struct GRUUnitFunctor; -template struct GRUUnitFunctor; -template struct GRUUnitGradFunctor; -template struct GRUUnitGradFunctor; +template struct GRUUnitFunctor; +template struct GRUUnitFunctor; +template struct GRUUnitGradFunctor; +template struct GRUUnitGradFunctor; -template struct GRUUnitFunctorV2; -template struct GRUUnitFunctorV2; -template struct GRUUnitGradFunctorV2; -template struct GRUUnitGradFunctorV2; +template struct GRUUnitFunctorV2; +template struct GRUUnitFunctorV2; +template struct GRUUnitGradFunctorV2; +template struct GRUUnitGradFunctorV2; } // namespace math } // namespace operators diff --git a/paddle/fluid/operators/math/im2col_test.cc b/paddle/fluid/operators/math/im2col_test.cc index fc045ba8be4580a2aea18a7928ddcdda2bb8d195..93ee9d3a15bade59fbd07964178eaa6cbf81364e 100644 --- a/paddle/fluid/operators/math/im2col_test.cc +++ b/paddle/fluid/operators/math/im2col_test.cc @@ -341,7 +341,7 @@ void testIm2col(); + testIm2col(); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) testIm2col(); @@ -350,7 +350,7 @@ TEST(math, im2col) { #define PREPARE_IM2COL_CPU \ paddle::platform::CPUPlace place; \ - paddle::platform::CPUDeviceContext context(place); \ + phi::CPUContext context(place); \ paddle::framework::Tensor input; \ paddle::framework::Tensor out; \ paddle::framework::Tensor ref; \ @@ -367,7 +367,7 @@ TEST(math, im2col) { ref.mutable_data({ic, fh, fw, output_height, output_width}, place); \ paddle::operators::math::Im2ColFunctor< \ paddle::operators::math::ColFormat::kCFO, \ - paddle::platform::CPUDeviceContext, \ + phi::CPUContext, \ float> \ im2col diff --git a/paddle/fluid/operators/math/matrix_bit_code.cc b/paddle/fluid/operators/math/matrix_bit_code.cc index 133680ca9a8c79f6e3ac00823f8d6906db1d1b9e..8a6f098baefd9539425fa4882a95a34b72c92728 100644 --- a/paddle/fluid/operators/math/matrix_bit_code.cc +++ b/paddle/fluid/operators/math/matrix_bit_code.cc @@ -137,8 +137,7 @@ struct MatrixBitCodeFunctorMul : public boost::static_visitor { template void operator()(const CodeTable &code_table) { - auto blas = phi::funcs::GetBlas( - platform::CPUDeviceContext()); + auto blas = phi::funcs::GetBlas(phi::CPUContext()); size_t num_samples = tmat_->dims()[0]; size_t tmat_width = tmat_->dims()[1]; size_t input_width = input_.dims()[1]; @@ -185,8 +184,7 @@ struct MatrixBitCodeFunctorMulGradWeight : public boost::static_visitor { : tmat_(tmat), weight_(weight), input_(input) {} template void operator()(const CodeTable &code_table) { - auto blas = phi::funcs::GetBlas( - platform::CPUDeviceContext()); + auto blas = phi::funcs::GetBlas(phi::CPUContext()); size_t num_samples = tmat_.dims()[0]; size_t input_width = input_.dims()[1]; size_t tmat_width = tmat_.dims()[1]; @@ -239,8 +237,7 @@ struct MatrixBitCodeFunctorMulGradWeightSR template void operator()(const CodeTable &code_table) { - auto blas = phi::funcs::GetBlas( - platform::CPUDeviceContext()); + auto blas = phi::funcs::GetBlas(phi::CPUContext()); size_t num_samples = tmat_.dims()[0]; size_t input_width = input_.dims()[1]; size_t tmat_width = tmat_.dims()[1]; diff --git a/paddle/fluid/operators/math/matrix_solve.cc b/paddle/fluid/operators/math/matrix_solve.cc index 4d38dc7137935da4cf2fe31a523099e214b6713c..b0f8843a530c07b5008a8d403b595986435ee87a 100644 --- a/paddle/fluid/operators/math/matrix_solve.cc +++ b/paddle/fluid/operators/math/matrix_solve.cc @@ -23,18 +23,18 @@ namespace operators { namespace math { template -class MatrixSolveFunctor { +class MatrixSolveFunctor { public: - void operator()(const platform::CPUDeviceContext& dev_ctx, + void operator()(const phi::CPUContext& dev_ctx, const framework::Tensor& a, const framework::Tensor& b, framework::Tensor* out) { - compute_solve_eigen(dev_ctx, a, b, out); + compute_solve_eigen(dev_ctx, a, b, out); } }; -template class MatrixSolveFunctor; -template class MatrixSolveFunctor; +template class MatrixSolveFunctor; +template class MatrixSolveFunctor; } // namespace math } // namespace operators diff --git a/paddle/fluid/operators/math/selected_rows_functor.cc b/paddle/fluid/operators/math/selected_rows_functor.cc index 399a1b6dc4ccd07b677312a5ee42bfd8b74b5885..9ec1172c410d8d4525c6bf61ca77eea6277cd822 100644 --- a/paddle/fluid/operators/math/selected_rows_functor.cc +++ b/paddle/fluid/operators/math/selected_rows_functor.cc @@ -25,8 +25,8 @@ namespace paddle { namespace operators { namespace math { template -struct SelectedRowsAdd { - void operator()(const platform::CPUDeviceContext& context, +struct SelectedRowsAdd { + void operator()(const phi::CPUContext& context, const phi::SelectedRows& input1, const phi::SelectedRows& input2, phi::SelectedRows* output) { @@ -106,12 +106,12 @@ struct SelectedRowsAdd { } }; -template struct SelectedRowsAdd; -template struct SelectedRowsAdd; +template struct SelectedRowsAdd; +template struct SelectedRowsAdd; template -struct SelectedRowsAddTensor { - void operator()(const platform::CPUDeviceContext& context, +struct SelectedRowsAddTensor { + void operator()(const phi::CPUContext& context, const phi::SelectedRows& input1, const framework::Tensor& input2, framework::Tensor* output) { @@ -156,7 +156,7 @@ struct SelectedRowsAddTensor { in1_row_numel, output->numel() / in1_height)); - phi::funcs::SetConstant functor; + phi::funcs::SetConstant functor; functor(context, output, 0.0); auto* in1_data = in1_value.data(); @@ -175,12 +175,12 @@ struct SelectedRowsAddTensor { } }; -template struct SelectedRowsAddTensor; -template struct SelectedRowsAddTensor; +template struct SelectedRowsAddTensor; +template struct SelectedRowsAddTensor; template -struct SelectedRowsAddTo { - void operator()(const platform::CPUDeviceContext& context, +struct SelectedRowsAddTo { + void operator()(const phi::CPUContext& context, const phi::SelectedRows& input1, const int64_t input2_offset, phi::SelectedRows* input2) { @@ -225,14 +225,14 @@ struct SelectedRowsAddTo { } }; -template struct SelectedRowsAddTo; -template struct SelectedRowsAddTo; -template struct SelectedRowsAddTo; -template struct SelectedRowsAddTo; +template struct SelectedRowsAddTo; +template struct SelectedRowsAddTo; +template struct SelectedRowsAddTo; +template struct SelectedRowsAddTo; template -struct SelectedRowsSumTo { - void operator()(const platform::CPUDeviceContext& context, +struct SelectedRowsSumTo { + void operator()(const phi::CPUContext& context, const std::vector& input1, const std::vector& input2_offsets, phi::SelectedRows* input2) { @@ -262,7 +262,7 @@ struct SelectedRowsSumTo { auto* in2_value = input2->mutable_value(); auto* in2_data = in2_value->data(); - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); size_t offset = 0u; for (size_t i = 0u; i != input1.size(); ++i) { auto& in_value = input1[i]->value(); @@ -273,8 +273,8 @@ struct SelectedRowsSumTo { } }; -template struct SelectedRowsSumTo; -template struct SelectedRowsSumTo; +template struct SelectedRowsSumTo; +template struct SelectedRowsSumTo; template struct SelectedRowsAddToTensor { @@ -734,15 +734,15 @@ struct MergeAdd { #endif template -struct MergeAverage { - phi::SelectedRows operator()(const platform::CPUDeviceContext& context, +struct MergeAverage { + phi::SelectedRows operator()(const phi::CPUContext& context, const phi::SelectedRows& input) { phi::SelectedRows out; (*this)(context, input, &out); return out; } - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const phi::SelectedRows& input, phi::SelectedRows* output) { std::vector inputs; @@ -750,7 +750,7 @@ struct MergeAverage { (*this)(context, inputs, output); } - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const std::vector& inputs, phi::SelectedRows* output) { if (inputs.size() == 0) { @@ -803,7 +803,7 @@ struct MergeAverage { out.set_rows(merge_rows); - phi::funcs::SetConstant constant_functor; + phi::funcs::SetConstant constant_functor; constant_functor(context, out.mutable_value(), 0.0); std::unordered_map rows_to_id; @@ -811,7 +811,7 @@ struct MergeAverage { rows_to_id[merge_rows[i]] = i; } - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); for (auto* input : inputs) { if (input->rows().size() == 0) { continue; @@ -841,14 +841,14 @@ struct MergeAverage { template struct MergeAdd; #endif -template struct MergeAverage; -template struct MergeAverage; -template struct MergeAverage; -template struct MergeAverage; +template struct MergeAverage; +template struct MergeAverage; +template struct MergeAverage; +template struct MergeAverage; template -struct UpdateToTensor { - void operator()(const platform::CPUDeviceContext& context, +struct UpdateToTensor { + void operator()(const phi::CPUContext& context, const ScatterOps& op, const phi::SelectedRows& input1, framework::Tensor* input2) { diff --git a/paddle/fluid/operators/math/selected_rows_functor_test.cc b/paddle/fluid/operators/math/selected_rows_functor_test.cc index d0383ee5fc21df47b76455c7df5ba9ccc61927bc..ecb8aa7824724b3e20985c8f2a3cdb33819ff0fc 100644 --- a/paddle/fluid/operators/math/selected_rows_functor_test.cc +++ b/paddle/fluid/operators/math/selected_rows_functor_test.cc @@ -19,8 +19,8 @@ limitations under the License. */ TEST(selected_rows_functor, cpu_add) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; @@ -48,9 +48,7 @@ TEST(selected_rows_functor, cpu_add) { // simplely concat two SelectedRows out_value->mutable_data(phi::make_ddim({7, 10}), cpu_place); - paddle::operators::math::SelectedRowsAdd - add_functor; + paddle::operators::math::SelectedRowsAdd add_functor; add_functor(ctx, *selected_rows1, *selected_rows2, output.get()); auto out_height = output->height(); @@ -90,9 +88,8 @@ TEST(selected_rows_functor, cpu_add) { new paddle::framework::Tensor()}; tensor2->mutable_data(phi::make_ddim({height, row_numel}), cpu_place); - paddle::operators::math:: - SelectedRowsAddTensor - add_tensor_functor; + paddle::operators::math::SelectedRowsAddTensor + add_tensor_functor; add_tensor_functor(ctx, *output, *tensor1, tensor2.get()); auto* tensor2_data = tensor2->data(); @@ -114,8 +111,8 @@ TEST(selected_rows_functor, cpu_add) { TEST(selected_rows_functor, cpu_add_to) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; @@ -144,8 +141,7 @@ TEST(selected_rows_functor, cpu_add_to) { // simplely concat two SelectedRows out_value->mutable_data(phi::make_ddim({7, 10}), cpu_place); - paddle::operators::math::SelectedRowsAddTo + paddle::operators::math::SelectedRowsAddTo add_to_functor; add_to_functor(ctx, *selected_rows1, 0, output.get()); add_to_functor(ctx, *selected_rows2, in1_value->numel(), output.get()); @@ -183,9 +179,8 @@ TEST(selected_rows_functor, cpu_add_to) { tensor1->mutable_data(phi::make_ddim({height, row_numel}), cpu_place); functor(ctx, tensor1.get(), 3.0); - paddle::operators::math:: - SelectedRowsAddToTensor - add_to_tensor_functor; + paddle::operators::math::SelectedRowsAddToTensor + add_to_tensor_functor; add_to_tensor_functor(ctx, *output, tensor1.get()); auto* tensor1_data = tensor1->data(); @@ -207,8 +202,8 @@ TEST(selected_rows_functor, cpu_add_to) { TEST(selected_rows_functor, cpu_merge_average_float) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; @@ -221,9 +216,8 @@ TEST(selected_rows_functor, cpu_merge_average_float) { cpu_place); functor(ctx, in_value, 1.0); - paddle::operators::math::scatter:: - MergeAverage - merge_average_functor; + paddle::operators::math::scatter::MergeAverage + merge_average_functor; phi::SelectedRows output = merge_average_functor(ctx, *selected_rows); auto out_height = output.height(); @@ -243,8 +237,8 @@ TEST(selected_rows_functor, cpu_merge_average_float) { TEST(selected_rows_functor, cpu_merge_add_float) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; @@ -259,8 +253,7 @@ TEST(selected_rows_functor, cpu_merge_add_float) { std::unique_ptr output{new phi::SelectedRows()}; - paddle::operators::math::scatter::MergeAdd + paddle::operators::math::scatter::MergeAdd merge_add_functor; merge_add_functor(ctx, *selected_rows, output.get()); @@ -281,8 +274,8 @@ TEST(selected_rows_functor, cpu_merge_add_float) { TEST(selected_rows_functor, cpu_merge_add_int) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; @@ -297,8 +290,7 @@ TEST(selected_rows_functor, cpu_merge_add_int) { std::unique_ptr output{new phi::SelectedRows()}; - paddle::operators::math::scatter::MergeAdd + paddle::operators::math::scatter::MergeAdd merge_add_functor; merge_add_functor(ctx, *selected_rows, output.get()); @@ -319,8 +311,8 @@ TEST(selected_rows_functor, cpu_merge_add_int) { TEST(selected_rows_functor, cpu_merge_add_multi) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant set_const; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant set_const; int64_t height = 10; int64_t row_numel = 8; @@ -345,8 +337,7 @@ TEST(selected_rows_functor, cpu_merge_add_multi) { std::unique_ptr output{new phi::SelectedRows()}; output->set_height(height); - paddle::operators::math::scatter::MergeAdd + paddle::operators::math::scatter::MergeAdd merge_add_functor; std::vector inputs; @@ -370,8 +361,8 @@ TEST(selected_rows_functor, cpu_merge_add_multi) { TEST(selected_rows_functor, cpu_merge_add_multi_noduplicated) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant set_const; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant set_const; int64_t height = 10; int64_t row_numel = 8; @@ -396,8 +387,7 @@ TEST(selected_rows_functor, cpu_merge_add_multi_noduplicated) { std::unique_ptr output{new phi::SelectedRows()}; output->set_height(height); - paddle::operators::math::scatter::MergeAdd + paddle::operators::math::scatter::MergeAdd merge_add_functor; std::vector inputs; @@ -427,8 +417,8 @@ TEST(selected_rows_functor, cpu_merge_add_multi_noduplicated) { TEST(selected_rows_functor, cpu_sum_to) { paddle::platform::CPUPlace cpu_place; - paddle::platform::CPUDeviceContext ctx(cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext ctx(cpu_place); + phi::funcs::SetConstant functor; int64_t height = 10; int64_t row_numel = 10; std::vector rows1{0, 4, 7}; @@ -454,8 +444,7 @@ TEST(selected_rows_functor, cpu_sum_to) { auto* out_value = output->mutable_value(); // simplely concat two SelectedRows out_value->mutable_data(phi::make_ddim({7, 10}), cpu_place); - paddle::operators::math::SelectedRowsSumTo + paddle::operators::math::SelectedRowsSumTo sum_to_functor; sum_to_functor(ctx, std::vector( @@ -490,9 +479,8 @@ TEST(selected_rows_functor, cpu_sum_to) { new paddle::framework::Tensor()}; tensor1->mutable_data(phi::make_ddim({height, row_numel}), cpu_place); functor(ctx, tensor1.get(), 3.0); - paddle::operators::math:: - SelectedRowsAddToTensor - add_to_tensor_functor; + paddle::operators::math::SelectedRowsAddToTensor + add_to_tensor_functor; add_to_tensor_functor(ctx, *output, tensor1.get()); auto* tensor1_data = tensor1->data(); // row0: 1.0 + 2.0 + 3.0 diff --git a/paddle/fluid/operators/math/sequence_padding_test.cc b/paddle/fluid/operators/math/sequence_padding_test.cc index 3b30f9358a3a01e19191a2e3719e84c1bef69c74..06eca480ec622e4bcbe87eacd3ddb8e000fc0a32 100644 --- a/paddle/fluid/operators/math/sequence_padding_test.cc +++ b/paddle/fluid/operators/math/sequence_padding_test.cc @@ -101,18 +101,16 @@ void TestSequencePadding(const DeviceContext &context, TEST(Seq2BatchPadding, CPU) { auto place = paddle::platform::CPUPlace(); - auto *context = static_cast( + auto *context = static_cast( paddle::platform::DeviceContextPool::Instance().Get(place)); paddle::framework::LoD lod1; lod1.push_back(std::vector{0, 10}); - TestSequencePadding( - *context, lod1, 16); + TestSequencePadding(*context, lod1, 16); paddle::framework::LoD lod2; lod2.push_back(std::vector{0, 2, 7, 10}); - TestSequencePadding( - *context, lod2, 128); + TestSequencePadding(*context, lod2, 128); } #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) diff --git a/paddle/fluid/operators/math/sequence_pooling.cc b/paddle/fluid/operators/math/sequence_pooling.cc index 69675f5e9219a634f29eb5810d9988ba2bfaf9cf..a600c37a891085930862a3a3420cca4882a76e88 100644 --- a/paddle/fluid/operators/math/sequence_pooling.cc +++ b/paddle/fluid/operators/math/sequence_pooling.cc @@ -38,7 +38,7 @@ using EigenMatrix = framework::EigenMatrix; template class MaxSeqPoolFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& input, T pad_value, framework::LoDTensor* output, @@ -117,7 +117,7 @@ class MaxSeqPoolFunctor { template class MaxSeqPoolFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& input, T pad_value, framework::LoDTensor* output, @@ -178,7 +178,7 @@ class MaxSeqPoolFunctor { template class MaxSeqPoolGradFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& out_grad, const framework::Tensor& index, framework::LoDTensor* in_grad) { @@ -224,7 +224,7 @@ class MaxSeqPoolGradFunctor { const int* max_index = index.data(); T* ig_data = in_grad->data(); - phi::funcs::SetConstant set_zero; + phi::funcs::SetConstant set_zero; set_zero(context, in_grad, static_cast(0.0)); int64_t num_seq = og_dims[0]; int64_t dim = out_grad.numel() / num_seq; @@ -241,7 +241,7 @@ class MaxSeqPoolGradFunctor { template class LastSeqPoolFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& input, T pad_value, framework::LoDTensor* output) { @@ -275,7 +275,7 @@ class LastSeqPoolFunctor { template class FirstSeqPoolFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& input, T pad_value, framework::LoDTensor* output) { @@ -309,7 +309,7 @@ class FirstSeqPoolFunctor { template class SumSeqPoolGradFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::LoDTensor& out_grad, framework::LoDTensor* in_grad) { auto lod_level = in_grad->lod().size(); @@ -328,7 +328,7 @@ class SumSeqPoolGradFunctor { out_w)); const T* out_g_data = out_grad.data(); T* in_g_data = in_grad->mutable_data(context.GetPlace()); - auto blas = phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); for (int i = 0; i < static_cast(lod.size()) - 1; ++i) { int64_t h = static_cast(lod[i + 1] - lod[i]); if (h == 0) continue; @@ -343,10 +343,10 @@ class SumSeqPoolGradFunctor { }; template -class SequencePoolFunctor { +class SequencePoolFunctor { public: /* max pool has index output */ - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const std::string pooltype, T pad_value, const framework::LoDTensor& input, @@ -435,9 +435,9 @@ class SequencePoolFunctor { }; template -class SequencePoolGradFunctor { +class SequencePoolGradFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const std::string pooltype, const framework::LoDTensor& out_grad, framework::LoDTensor* in_grad, @@ -451,7 +451,7 @@ class SequencePoolGradFunctor { if (pooltype == "LAST" || pooltype == "FIRST") { // set X@Grad be zero at first when pooltype is LAST/FIRST - phi::funcs::SetConstant functor; + phi::funcs::SetConstant functor; functor(context, in_grad, 0); } @@ -495,10 +495,10 @@ class SequencePoolGradFunctor { } }; -template class SequencePoolFunctor; -template class SequencePoolFunctor; -template class SequencePoolGradFunctor; -template class SequencePoolGradFunctor; +template class SequencePoolFunctor; +template class SequencePoolFunctor; +template class SequencePoolGradFunctor; +template class SequencePoolGradFunctor; } // namespace math } // namespace operators diff --git a/paddle/fluid/operators/math/sequence_pooling_test.cc b/paddle/fluid/operators/math/sequence_pooling_test.cc index ec82a2439a6c3bc055486d916917b5f7b070b848..63d922b7ebb80ff2c21159f9d71ab9294f300f88 100644 --- a/paddle/fluid/operators/math/sequence_pooling_test.cc +++ b/paddle/fluid/operators/math/sequence_pooling_test.cc @@ -117,18 +117,16 @@ void TestSequencePoolingSum(const DeviceContext &context, TEST(SequencePoolingGrad, CPU_SUM) { auto place = paddle::platform::CPUPlace(); - auto *context = static_cast( + auto *context = static_cast( paddle::platform::DeviceContextPool::Instance().Get(place)); paddle::framework::LoD lod1; lod1.push_back(std::vector{0, 10}); - TestSequencePoolingSum( - *context, lod1, 128); + TestSequencePoolingSum(*context, lod1, 128); paddle::framework::LoD lod2; lod2.push_back(std::vector{0, 2, 7, 10}); - TestSequencePoolingSum( - *context, lod2, 128); + TestSequencePoolingSum(*context, lod2, 128); } #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) diff --git a/paddle/fluid/operators/math/softmax_impl.h b/paddle/fluid/operators/math/softmax_impl.h index 93ae9cad7674e59d2bdca243be1b6dbae6e73e0c..18cd3e7261dd7967229c6d7f4658d3f7dde6e682 100644 --- a/paddle/fluid/operators/math/softmax_impl.h +++ b/paddle/fluid/operators/math/softmax_impl.h @@ -226,7 +226,7 @@ void SoftmaxFunctor::operator()( template using enable_if_CPU = typename std::enable_if< - std::is_same::value>::type; + std::is_same::value>::type; template class SoftmaxFunctor> { diff --git a/paddle/fluid/operators/math/squared_l2_norm.h b/paddle/fluid/operators/math/squared_l2_norm.h index ba584953a0d1e5f7eb14cc558efad107fe99a9c9..3054d5f8f00298a03dbd9e1f2ccc287c7a75eecb 100644 --- a/paddle/fluid/operators/math/squared_l2_norm.h +++ b/paddle/fluid/operators/math/squared_l2_norm.h @@ -34,7 +34,7 @@ namespace operators { namespace math { template -void SquaredL2Norm(const platform::CPUDeviceContext& ctx, +void SquaredL2Norm(const phi::CPUContext& ctx, const T1* x, T2* y, size_t numel, diff --git a/paddle/fluid/operators/math/tree2col.cc b/paddle/fluid/operators/math/tree2col.cc index fae1122fa0596e7dc0e7f952f5f6a369669f27aa..70f377e42e59ff403bdf2712e7111bef3c12384f 100644 --- a/paddle/fluid/operators/math/tree2col.cc +++ b/paddle/fluid/operators/math/tree2col.cc @@ -84,9 +84,9 @@ void Tree2ColUtil::construct_tree(const framework::Tensor &EdgeSet, } template -class Tree2ColFunctor { +class Tree2ColFunctor { public: - void operator()(const platform::CPUDeviceContext &context, + void operator()(const phi::CPUContext &context, const framework::Tensor &EdgeSet, const framework::Tensor &node_features, framework::Tensor *patch, @@ -94,7 +94,7 @@ class Tree2ColFunctor { std::vector> tr; const auto &feature_dims = node_features.dims(); auto cpu_place = context.GetPlace(); - phi::funcs::SetConstant constant; + phi::funcs::SetConstant constant; int64_t feature_size = feature_dims[1]; size_t patch_elem_size = 3 * static_cast(feature_size); size_t node_count = 0, patch_count = 0, patch_size; @@ -138,9 +138,9 @@ class Tree2ColFunctor { } }; template -class Col2TreeFunctor { +class Col2TreeFunctor { public: - void operator()(const platform::CPUDeviceContext &context, + void operator()(const phi::CPUContext &context, const framework::Tensor &EdgeSet, const framework::Tensor &out_grad, framework::Tensor *in_grad, @@ -148,7 +148,7 @@ class Col2TreeFunctor { std::vector> tr; const auto &output_dims = out_grad.dims(); auto cpu_place = context.GetPlace(); - phi::funcs::SetConstant constant; + phi::funcs::SetConstant constant; int64_t output_size = output_dims[1]; size_t grad_elem_size = 3 * static_cast(output_size); size_t node_count = 0, grad_count = 0; @@ -195,10 +195,10 @@ class Col2TreeFunctor { } }; -template class Tree2ColFunctor; -template class Tree2ColFunctor; -template class Col2TreeFunctor; -template class Col2TreeFunctor; +template class Tree2ColFunctor; +template class Tree2ColFunctor; +template class Col2TreeFunctor; +template class Col2TreeFunctor; } // namespace math } // namespace operators } // namespace paddle diff --git a/paddle/fluid/operators/math/unpooling.cc b/paddle/fluid/operators/math/unpooling.cc index c834a03f9731b2d48629589ee90e41d8024a325f..d119e814585b5ecf04707b83b7894b3f508359a0 100644 --- a/paddle/fluid/operators/math/unpooling.cc +++ b/paddle/fluid/operators/math/unpooling.cc @@ -18,9 +18,9 @@ namespace paddle { namespace operators { namespace math { template -class Unpool2dMaxFunctor { +class Unpool2dMaxFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::Tensor& input, const framework::Tensor& indices, framework::Tensor* output) { @@ -61,9 +61,9 @@ class Unpool2dMaxFunctor { } }; template -class Unpool2dMaxGradFunctor { +class Unpool2dMaxGradFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::Tensor& input, const framework::Tensor& indices, const framework::Tensor& output, @@ -107,9 +107,9 @@ class Unpool2dMaxGradFunctor { }; template -class Unpool3dMaxFunctor { +class Unpool3dMaxFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::Tensor& input, const framework::Tensor& indices, framework::Tensor* output) { @@ -153,9 +153,9 @@ class Unpool3dMaxFunctor { } }; template -class Unpool3dMaxGradFunctor { +class Unpool3dMaxGradFunctor { public: - void operator()(const platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const framework::Tensor& input, const framework::Tensor& indices, const framework::Tensor& output, @@ -201,14 +201,14 @@ class Unpool3dMaxGradFunctor { } }; -template class Unpool2dMaxGradFunctor; -template class Unpool2dMaxGradFunctor; -template class Unpool2dMaxFunctor; -template class Unpool2dMaxFunctor; -template class Unpool3dMaxGradFunctor; -template class Unpool3dMaxGradFunctor; -template class Unpool3dMaxFunctor; -template class Unpool3dMaxFunctor; +template class Unpool2dMaxGradFunctor; +template class Unpool2dMaxGradFunctor; +template class Unpool2dMaxFunctor; +template class Unpool2dMaxFunctor; +template class Unpool3dMaxGradFunctor; +template class Unpool3dMaxGradFunctor; +template class Unpool3dMaxFunctor; +template class Unpool3dMaxFunctor; } // namespace math } // namespace operators } // namespace paddle diff --git a/paddle/fluid/operators/math/vol2col_test.cc b/paddle/fluid/operators/math/vol2col_test.cc index f2c5fa88fda60952128fd9f05b3ebfb44e7b2cec..ec3926b95ee8768eed0c061c830082f26c786a9c 100644 --- a/paddle/fluid/operators/math/vol2col_test.cc +++ b/paddle/fluid/operators/math/vol2col_test.cc @@ -254,7 +254,7 @@ void testVol2col(); + testVol2col(); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) testVol2col(); diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index 13df41852dd5ac3f9583ea22cbe36a2ac00bf724..c79073861ab6e01beb52f703e3ecfcbec1681b18 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -1041,19 +1041,16 @@ REGISTER_OPERATOR(matmul_grad, ops::MatMulOpDoubleGradMaker, ops::MatMulOpDoubleGradMaker); REGISTER_OPERATOR(matmul_grad_grad, ops::MatMulOpDoubleGrad); -REGISTER_OP_CPU_KERNEL( - matmul, - ops::MatMulKernel, - ops::MatMulKernel); -REGISTER_OP_CPU_KERNEL( - matmul_grad, - ops::MatMulGradKernel, - ops::MatMulGradKernel); - -REGISTER_OP_CPU_KERNEL( - matmul_grad_grad, - ops::MatMulDoubleGradKernel, - ops::MatMulDoubleGradKernel); +REGISTER_OP_CPU_KERNEL(matmul, + ops::MatMulKernel, + ops::MatMulKernel); +REGISTER_OP_CPU_KERNEL(matmul_grad, + ops::MatMulGradKernel, + ops::MatMulGradKernel); + +REGISTER_OP_CPU_KERNEL(matmul_grad_grad, + ops::MatMulDoubleGradKernel, + ops::MatMulDoubleGradKernel); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) REGISTER_OP_CUDA_KERNEL( diff --git a/paddle/fluid/operators/mean_iou_op.h b/paddle/fluid/operators/mean_iou_op.h index 88f8be63f26c83993c4a0b02655c14b4d10c69bc..b5ac6fd677bacc2f971a804322973351ed97bcf7 100644 --- a/paddle/fluid/operators/mean_iou_op.h +++ b/paddle/fluid/operators/mean_iou_op.h @@ -31,8 +31,8 @@ template class MeanIoUKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - auto& place = *ctx.template device_context() - .eigen_device(); + auto& place = + *ctx.template device_context().eigen_device(); // get input and output tensor auto* predictions = ctx.Input("Predictions"); auto* labels = ctx.Input("Labels"); diff --git a/paddle/fluid/operators/merge_selected_rows_op.cc b/paddle/fluid/operators/merge_selected_rows_op.cc index fc1944b2ad6fb815ba6e2751652aae1a37f51cf7..ef89a730a0ff9fd73c2caf299325a23fdb2ea994 100644 --- a/paddle/fluid/operators/merge_selected_rows_op.cc +++ b/paddle/fluid/operators/merge_selected_rows_op.cc @@ -100,7 +100,6 @@ REGISTER_OPERATOR(merge_selected_rows, ops::MergeSelectedRowsOpMaker, ops::MergeSelectedRowsOpInferVarType); -REGISTER_OP_CPU_KERNEL( - merge_selected_rows, - ops::MergeSelectedRowsKernel, - ops::MergeSelectedRowsKernel); +REGISTER_OP_CPU_KERNEL(merge_selected_rows, + ops::MergeSelectedRowsKernel, + ops::MergeSelectedRowsKernel); diff --git a/paddle/fluid/operators/minus_op.cc b/paddle/fluid/operators/minus_op.cc index 5edc39f8fc7b88fc23415f179773e8bd0677883b..1e369c81538ed2cb74059c214fc3e5b975452bdb 100644 --- a/paddle/fluid/operators/minus_op.cc +++ b/paddle/fluid/operators/minus_op.cc @@ -153,8 +153,7 @@ REGISTER_OPERATOR(minus, ops::MinusOpMaker, ops::MinusGradDescMaker, ops::MinusGradMaker); -REGISTER_OP_CPU_KERNEL( - minus, ops::MinusKernel); +REGISTER_OP_CPU_KERNEL(minus, ops::MinusKernel); REGISTER_OP_CUDA_KERNEL( minus, ops::MinusKernel); diff --git a/paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc b/paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc index 058be90cd82acff3307d856e935d06235153eee8..ea56b84c908894045b2478507a442b48ae80e868 100644 --- a/paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc +++ b/paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc @@ -198,8 +198,7 @@ class ReshapeMKLDNNKernel : public framework::OpKernel { x_dims = x->dims(); auto axes = ctx.Attr("axis"); out_dims = phi::make_ddim( - FlattenKernel::GetOutputShape( - axes, x_dims)); + FlattenKernel::GetOutputShape(axes, x_dims)); } protected: diff --git a/paddle/fluid/operators/mkldnn/sum_mkldnn_op.cc b/paddle/fluid/operators/mkldnn/sum_mkldnn_op.cc index bd6d55fb7b3facf0eab16cc693290858883023f9..2202349bd66c1605a4c1d34750639e7ee3a46947 100644 --- a/paddle/fluid/operators/mkldnn/sum_mkldnn_op.cc +++ b/paddle/fluid/operators/mkldnn/sum_mkldnn_op.cc @@ -41,8 +41,8 @@ class MKLDNNDeviceContext; namespace paddle { namespace operators { -using paddle::platform::CPUDeviceContext; using paddle::platform::MKLDNNDeviceContext; +using phi::CPUContext; using platform::to_void_cast; template diff --git a/paddle/fluid/operators/modified_huber_loss_op.cc b/paddle/fluid/operators/modified_huber_loss_op.cc index f3fcab3ca5490d688ab2d80f6c0171ab0fd77f8d..17f323d0bcba8f8888aff4fbc3b7ac7e7632f430 100644 --- a/paddle/fluid/operators/modified_huber_loss_op.cc +++ b/paddle/fluid/operators/modified_huber_loss_op.cc @@ -176,8 +176,7 @@ REGISTER_OPERATOR( ops::ModifiedHuberLossGradOpMaker); REGISTER_OPERATOR(modified_huber_loss_grad, ops::ModifiedHuberLossGradOp); -REGISTER_OP_CPU_KERNEL( - modified_huber_loss, - ops::ModifiedHuberLossKernel); +REGISTER_OP_CPU_KERNEL(modified_huber_loss, + ops::ModifiedHuberLossKernel); REGISTER_OP_CPU_KERNEL(modified_huber_loss_grad, ops::ModifiedHuberLossGradCPUKernel); diff --git a/paddle/fluid/operators/norm_op.cc b/paddle/fluid/operators/norm_op.cc index e43112f423692127dc3b048470db5e11ba684861..76737f2bc35a7a9e13681816d48cc8d9e52e8758 100644 --- a/paddle/fluid/operators/norm_op.cc +++ b/paddle/fluid/operators/norm_op.cc @@ -100,7 +100,7 @@ class NormOpGradOpMaker : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; DECLARE_INFER_SHAPE_FUNCTOR(norm, NormInferShapeFunctor, diff --git a/paddle/fluid/operators/one_hot_op.cc b/paddle/fluid/operators/one_hot_op.cc index e749a267c970be3269bc89d4a8798eb32be24ab1..59842249adcdd0bffe1f1ccfaa6689e8403fe442 100644 --- a/paddle/fluid/operators/one_hot_op.cc +++ b/paddle/fluid/operators/one_hot_op.cc @@ -133,7 +133,6 @@ REGISTER_OPERATOR( ops::OneHotOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - one_hot, - ops::OneHotKernel, - ops::OneHotKernel); +REGISTER_OP_CPU_KERNEL(one_hot, + ops::OneHotKernel, + ops::OneHotKernel); diff --git a/paddle/fluid/operators/optimizers/decayed_adagrad_op.cc b/paddle/fluid/operators/optimizers/decayed_adagrad_op.cc index 8b9569db1a63c66e3168f207c4298f07bacdc8c9..90ce98c4dc316a9c7301b682f1c68cb45dd0f626 100644 --- a/paddle/fluid/operators/optimizers/decayed_adagrad_op.cc +++ b/paddle/fluid/operators/optimizers/decayed_adagrad_op.cc @@ -131,6 +131,5 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(decayed_adagrad, ops::DecayedAdagradOp, ops::DecayedAdagradOpMaker); -REGISTER_OP_CPU_KERNEL( - decayed_adagrad, - ops::DecayedAdagradOpKernel); +REGISTER_OP_CPU_KERNEL(decayed_adagrad, + ops::DecayedAdagradOpKernel); diff --git a/paddle/fluid/operators/optimizers/dgc_momentum_op.cc b/paddle/fluid/operators/optimizers/dgc_momentum_op.cc index f283cbd21ef9e7463e62d9cadf8336acb5962df9..09847ff216f5ab008dbca6dc0ae89cfc3ac70088 100644 --- a/paddle/fluid/operators/optimizers/dgc_momentum_op.cc +++ b/paddle/fluid/operators/optimizers/dgc_momentum_op.cc @@ -74,6 +74,5 @@ REGISTER_OP_WITHOUT_GRADIENT(dgc_momentum, ops::DGCMomentumOp, ops::DGCMomentumOpMaker); -REGISTER_OP_CPU_KERNEL( - dgc_momentum, - ops::DGCMomentumKernel); +REGISTER_OP_CPU_KERNEL(dgc_momentum, + ops::DGCMomentumKernel); diff --git a/paddle/fluid/operators/optimizers/distributed_fused_lamb_init_op.cc b/paddle/fluid/operators/optimizers/distributed_fused_lamb_init_op.cc index 95b45934ea6d2e7d5472f7552a86e27773509105..e32cf3625174265b0fd89c8b224428d5d299b46c 100644 --- a/paddle/fluid/operators/optimizers/distributed_fused_lamb_init_op.cc +++ b/paddle/fluid/operators/optimizers/distributed_fused_lamb_init_op.cc @@ -120,4 +120,4 @@ REGISTER_OP_WITHOUT_GRADIENT(distributed_fused_lamb_init, REGISTER_OP_CPU_KERNEL( distributed_fused_lamb_init, - ops::DistributedFusedLambInitOpKernel); + ops::DistributedFusedLambInitOpKernel); diff --git a/paddle/fluid/operators/optimizers/distributed_fused_lamb_op.cc b/paddle/fluid/operators/optimizers/distributed_fused_lamb_op.cc index 224e2a4de3f74b56532ae57d40d1fbd320748f5f..b85eb16a39cf282ce3881e03b3d49d81dfbbcf85 100644 --- a/paddle/fluid/operators/optimizers/distributed_fused_lamb_op.cc +++ b/paddle/fluid/operators/optimizers/distributed_fused_lamb_op.cc @@ -167,4 +167,4 @@ REGISTER_OP_WITHOUT_GRADIENT(distributed_fused_lamb, REGISTER_OP_CPU_KERNEL( distributed_fused_lamb, - ops::DistributedFusedLambOpKernel); + ops::DistributedFusedLambOpKernel); diff --git a/paddle/fluid/operators/optimizers/dpsgd_op.cc b/paddle/fluid/operators/optimizers/dpsgd_op.cc index 023c3f27cf29ef3079395443ecfccc4a2398f896..ad1262a7d2d5528cf005af25c2843cd5466ba218 100644 --- a/paddle/fluid/operators/optimizers/dpsgd_op.cc +++ b/paddle/fluid/operators/optimizers/dpsgd_op.cc @@ -132,7 +132,6 @@ CCS16 - Deep Learning with Differential Privacy. namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(dpsgd, ops::DpsgdOp, ops::DpsgdOpMaker); -REGISTER_OP_CPU_KERNEL( - dpsgd, - ops::DpsgdOpKernel, - ops::DpsgdOpKernel); +REGISTER_OP_CPU_KERNEL(dpsgd, + ops::DpsgdOpKernel, + ops::DpsgdOpKernel); diff --git a/paddle/fluid/operators/optimizers/ftrl_op.cc b/paddle/fluid/operators/optimizers/ftrl_op.cc index edafacf508dcbe711405430f8e1106c77e3b21d2..50060b1636943a66b6e3a3d5be8b262d201e6521 100644 --- a/paddle/fluid/operators/optimizers/ftrl_op.cc +++ b/paddle/fluid/operators/optimizers/ftrl_op.cc @@ -157,5 +157,4 @@ The paper that proposed Follow The Regularized Leader (FTRL): namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(ftrl, ops::FTRLOp, ops::FTRLOpMaker); -REGISTER_OP_CPU_KERNEL( - ftrl, ops::FTRLOpKernel); +REGISTER_OP_CPU_KERNEL(ftrl, ops::FTRLOpKernel); diff --git a/paddle/fluid/operators/optimizers/lamb_op.cc b/paddle/fluid/operators/optimizers/lamb_op.cc index e2df17fd720add571bf99416a31f65c88e3577a8..8434da2bb0e76a389991d141d2fffab90956d962 100644 --- a/paddle/fluid/operators/optimizers/lamb_op.cc +++ b/paddle/fluid/operators/optimizers/lamb_op.cc @@ -247,10 +247,9 @@ learning rate, $\lambda$ the weight decay rate. namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(lamb, ops::LambOp, ops::LambOpMaker); -REGISTER_OP_CPU_KERNEL( - lamb, - ops::LambOpKernel, - ops::LambOpKernel); +REGISTER_OP_CPU_KERNEL(lamb, + ops::LambOpKernel, + ops::LambOpKernel); /* ========================== register checkpoint ===========================*/ REGISTER_OP_VERSION(lamb).AddCheckpoint( diff --git a/paddle/fluid/operators/optimizers/merged_adam_op.cc b/paddle/fluid/operators/optimizers/merged_adam_op.cc index 042905ddfe489d7d3f409214cb4fcc277845900d..69ca8ec3c6670a00a3c3a8083a317d952787020b 100644 --- a/paddle/fluid/operators/optimizers/merged_adam_op.cc +++ b/paddle/fluid/operators/optimizers/merged_adam_op.cc @@ -135,7 +135,6 @@ REGISTER_OP_WITHOUT_GRADIENT(merged_adamw, ops::MergedAdamOp, ops::MergedAdamOpMaker); -REGISTER_OP_CPU_KERNEL( - merged_adam, - ops::MergedAdamOpKernel, - ops::MergedAdamOpKernel); +REGISTER_OP_CPU_KERNEL(merged_adam, + ops::MergedAdamOpKernel, + ops::MergedAdamOpKernel); diff --git a/paddle/fluid/operators/optimizers/merged_momentum_op.cc b/paddle/fluid/operators/optimizers/merged_momentum_op.cc index b640e47e6e638070b3d3286dd93b34619f54c595..e6aec5cec9e6645e2408eb0030ccb0be697d2bfa 100644 --- a/paddle/fluid/operators/optimizers/merged_momentum_op.cc +++ b/paddle/fluid/operators/optimizers/merged_momentum_op.cc @@ -104,7 +104,6 @@ REGISTER_OP_WITHOUT_GRADIENT(merged_momentum, ops::MergedMomentumOp, ops::MergedMomentumOpMaker); -REGISTER_OP_CPU_KERNEL( - merged_momentum, - ops::MergedMomentumOpKernel, - ops::MergedMomentumOpKernel); +REGISTER_OP_CPU_KERNEL(merged_momentum, + ops::MergedMomentumOpKernel, + ops::MergedMomentumOpKernel); diff --git a/paddle/fluid/operators/optimizers/mkldnn/sgd_mkldnn_op.cc b/paddle/fluid/operators/optimizers/mkldnn/sgd_mkldnn_op.cc index 7486c0c2b8cbeb40e47b0f5aa91aa0fc3af6071b..e332972f7576abd70de442a4a0a68eec86a572ec 100644 --- a/paddle/fluid/operators/optimizers/mkldnn/sgd_mkldnn_op.cc +++ b/paddle/fluid/operators/optimizers/mkldnn/sgd_mkldnn_op.cc @@ -23,7 +23,7 @@ namespace paddle { namespace operators { template -class SGDOneDNNKernel : public SGDOpKernel { +class SGDOneDNNKernel : public SGDOpKernel { protected: void dense_param_and_grad_kernel( const framework::ExecutionContext &ctx) const override { diff --git a/paddle/fluid/operators/optimizers/pow2_decay_with_linear_warmup_op.cc b/paddle/fluid/operators/optimizers/pow2_decay_with_linear_warmup_op.cc index 5eeeb7353072e9b4542b62d163d2272b6bf13f49..f576827f9cadfcf891433fb4079f0beef20cefbc 100644 --- a/paddle/fluid/operators/optimizers/pow2_decay_with_linear_warmup_op.cc +++ b/paddle/fluid/operators/optimizers/pow2_decay_with_linear_warmup_op.cc @@ -85,5 +85,5 @@ REGISTER_OP_WITHOUT_GRADIENT(pow2_decay_with_linear_warmup, ops::Pow2DecayWithLinearWarmupOpMaker); REGISTER_OP_CPU_KERNEL( pow2_decay_with_linear_warmup, - ops::Pow2DecayWithLinearWarmupOpKernel, - ops::Pow2DecayWithLinearWarmupOpKernel); + ops::Pow2DecayWithLinearWarmupOpKernel, + ops::Pow2DecayWithLinearWarmupOpKernel); diff --git a/paddle/fluid/operators/optimizers/proximal_adagrad_op.cc b/paddle/fluid/operators/optimizers/proximal_adagrad_op.cc index a5424f5cda5f01a3e8804d04bf4d8da1f0b8b7fd..072e39dd91cc0e9acb1d05ff0ba80f1e0b3743df 100644 --- a/paddle/fluid/operators/optimizers/proximal_adagrad_op.cc +++ b/paddle/fluid/operators/optimizers/proximal_adagrad_op.cc @@ -134,6 +134,5 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(proximal_adagrad, ops::ProximalAdagradOp, ops::ProximalAdagradOpMaker); -REGISTER_OP_CPU_KERNEL( - proximal_adagrad, - ops::ProximalAdagradOpKernel); +REGISTER_OP_CPU_KERNEL(proximal_adagrad, + ops::ProximalAdagradOpKernel); diff --git a/paddle/fluid/operators/optimizers/proximal_gd_op.cc b/paddle/fluid/operators/optimizers/proximal_gd_op.cc index dc7e9c90af59fea6b3653897118fb2b9ea2bc9aa..50676863678c1c46a3323d9c01b2d4df706df43d 100644 --- a/paddle/fluid/operators/optimizers/proximal_gd_op.cc +++ b/paddle/fluid/operators/optimizers/proximal_gd_op.cc @@ -107,6 +107,5 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(proximal_gd, ops::ProximalGDOp, ops::ProximalGDOpMaker); -REGISTER_OP_CPU_KERNEL( - proximal_gd, - ops::ProximalGDOpKernel); +REGISTER_OP_CPU_KERNEL(proximal_gd, + ops::ProximalGDOpKernel); diff --git a/paddle/fluid/operators/optimizers/sgd_op.h b/paddle/fluid/operators/optimizers/sgd_op.h index cb87850f43c5e3adf670b7a80e3eedcac15b0676..02d8bcbd279dcade437916e27ec28186d4c090c2 100644 --- a/paddle/fluid/operators/optimizers/sgd_op.h +++ b/paddle/fluid/operators/optimizers/sgd_op.h @@ -159,8 +159,7 @@ class SGDOpKernel : public framework::OpKernel { }; template -class SGDOpKernel - : public framework::OpKernel { +class SGDOpKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &ctx) const override { const auto *param_var = ctx.InputVar("Param"); diff --git a/paddle/fluid/operators/optimizers/sparse_momentum_op.cc b/paddle/fluid/operators/optimizers/sparse_momentum_op.cc index 48f211f9c5ace0ad782086f85c75274ce8bbc8c1..a92bbbc838a8a23185fbae72a75e096cd049fefa 100644 --- a/paddle/fluid/operators/optimizers/sparse_momentum_op.cc +++ b/paddle/fluid/operators/optimizers/sparse_momentum_op.cc @@ -119,7 +119,6 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker, ops::SparseMomentumOpInferVarType); -REGISTER_OP_CPU_KERNEL( - sparse_momentum, - ops::SparseMomentumOpKernel, - ops::SparseMomentumOpKernel); +REGISTER_OP_CPU_KERNEL(sparse_momentum, + ops::SparseMomentumOpKernel, + ops::SparseMomentumOpKernel); diff --git a/paddle/fluid/operators/overlap_add_op.cc b/paddle/fluid/operators/overlap_add_op.cc index 18d88f1069185491313b64e66b95c2303bbe870c..108c2df4cd2e1cf954499f60049e893cb7ce1cc5 100644 --- a/paddle/fluid/operators/overlap_add_op.cc +++ b/paddle/fluid/operators/overlap_add_op.cc @@ -186,22 +186,20 @@ REGISTER_OPERATOR(overlap_add_grad, ops::OverlapAddOpGrad); REGISTER_OP_CPU_KERNEL( overlap_add, - ops::OverlapAddKernel, - ops::OverlapAddKernel, - ops::OverlapAddKernel, - ops::OverlapAddKernel, - ops::OverlapAddKernel>, - ops::OverlapAddKernel>); + ops::OverlapAddKernel, + ops::OverlapAddKernel, + ops::OverlapAddKernel, + ops::OverlapAddKernel, + ops::OverlapAddKernel>, + ops::OverlapAddKernel>); REGISTER_OP_CPU_KERNEL( overlap_add_grad, - ops::OverlapAddGradKernel, - ops::OverlapAddGradKernel, - ops::OverlapAddGradKernel, - ops::OverlapAddGradKernel, - ops::OverlapAddGradKernel, + ops::OverlapAddGradKernel, + ops::OverlapAddGradKernel, + ops::OverlapAddGradKernel, + ops::OverlapAddGradKernel>, - ops::OverlapAddGradKernel>); diff --git a/paddle/fluid/operators/p_norm_op.cc b/paddle/fluid/operators/p_norm_op.cc index c5128707920731b39684489adf9bb7612316db2e..766ecaee0d6c936e174c90777a4ec5d708bd6b64 100644 --- a/paddle/fluid/operators/p_norm_op.cc +++ b/paddle/fluid/operators/p_norm_op.cc @@ -112,7 +112,7 @@ class PnormOpGradOpMaker : public framework::SingleGradOpMaker { } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; DECLARE_INFER_SHAPE_FUNCTOR(p_norm, PNormInferShapeFunctor, diff --git a/paddle/fluid/operators/pad2d_op.cc b/paddle/fluid/operators/pad2d_op.cc index 72073ed3067c3ea848eae9a47a7c5e7bfb9da81e..c2dfb8e61e5eb99032c15d9d6dcb81b336297ba7 100644 --- a/paddle/fluid/operators/pad2d_op.cc +++ b/paddle/fluid/operators/pad2d_op.cc @@ -536,8 +536,8 @@ class Pad2dGradCPUKernel : public framework::OpKernel { auto d_out_dims = d_out->dims(); const T* d_out_data = d_out->data(); T* d_in_data = d_in->mutable_data(context.GetPlace()); - phi::funcs::SetConstant set_zero; - set_zero(context.template device_context(), + phi::funcs::SetConstant set_zero; + set_zero(context.template device_context(), d_in, static_cast(0)); const int pad_top = pads[0]; diff --git a/paddle/fluid/operators/pad_constant_like_op.cc b/paddle/fluid/operators/pad_constant_like_op.cc index 571ead1710a923ecdc3e2548196d76ff8dc84196..e523c93f5d10bcfaf38ea1b7a3e84eca61a9a647 100644 --- a/paddle/fluid/operators/pad_constant_like_op.cc +++ b/paddle/fluid/operators/pad_constant_like_op.cc @@ -247,19 +247,17 @@ REGISTER_OPERATOR(pad_constant_like, ops::PadConstantLikeOpGradMaker); REGISTER_OPERATOR(pad_constant_like_grad, ops::PadConstantLikeOpGrad); -REGISTER_OP_CPU_KERNEL( - pad_constant_like, - ops::PadConstantLikeKernel, - ops::PadConstantLikeKernel, - ops::PadConstantLikeKernel, - ops::PadConstantLikeKernel); +REGISTER_OP_CPU_KERNEL(pad_constant_like, + ops::PadConstantLikeKernel, + ops::PadConstantLikeKernel, + ops::PadConstantLikeKernel, + ops::PadConstantLikeKernel); REGISTER_OP_CPU_KERNEL( pad_constant_like_grad, - ops::PadConstantLikeGradKernel, - ops::PadConstantLikeGradKernel, - ops::PadConstantLikeGradKernel, - ops::PadConstantLikeGradKernel); + ops::PadConstantLikeGradKernel, + ops::PadConstantLikeGradKernel, + ops::PadConstantLikeGradKernel, + ops::PadConstantLikeGradKernel); REGISTER_OP_CUDA_KERNEL( pad_constant_like, diff --git a/paddle/fluid/operators/partial_concat_op.cc b/paddle/fluid/operators/partial_concat_op.cc index 98bbede0323a9e47a14dc0b6968e3ae4fbf35497..e9b54632ddc010af66e559c0b59caebf699bc177 100644 --- a/paddle/fluid/operators/partial_concat_op.cc +++ b/paddle/fluid/operators/partial_concat_op.cc @@ -211,12 +211,11 @@ REGISTER_OPERATOR(partial_concat, REGISTER_OPERATOR(partial_concat_grad, ops::PartialConcatGradOp); -REGISTER_OP_CPU_KERNEL( - partial_concat, - ops::PartialConcatKernel, - ops::PartialConcatKernel, - ops::PartialConcatKernel, - ops::PartialConcatKernel); +REGISTER_OP_CPU_KERNEL(partial_concat, + ops::PartialConcatKernel, + ops::PartialConcatKernel, + ops::PartialConcatKernel, + ops::PartialConcatKernel); REGISTER_OP_CPU_KERNEL(partial_concat_grad, ops::PartialConcatGradientOpKernel, diff --git a/paddle/fluid/operators/partial_concat_op.h b/paddle/fluid/operators/partial_concat_op.h index f99617fdc634f8364d00b164e140631526dd3c11..affe06f20956adad0676fa7bf4292da4026f1a74 100644 --- a/paddle/fluid/operators/partial_concat_op.h +++ b/paddle/fluid/operators/partial_concat_op.h @@ -111,8 +111,8 @@ class PartialConcatGradientOpKernel : public framework::OpKernel { auto all_length = grad_batch_len * batch_size; // initialize - auto& place = *ctx.template device_context() - .eigen_device(); + auto& place = + *ctx.template device_context().eigen_device(); for (size_t i = 0; i < outs.size(); ++i) { outs[i]->mutable_data(ctx.GetPlace()); auto dxt = framework::EigenVector::Flatten(*outs[i]); diff --git a/paddle/fluid/operators/partial_sum_op.cc b/paddle/fluid/operators/partial_sum_op.cc index 3b69efb8e7489827a7c361ff5aa9e90d17e50255..4d4c1e54cff27634fc76d1698cd67c80bd418eb6 100644 --- a/paddle/fluid/operators/partial_sum_op.cc +++ b/paddle/fluid/operators/partial_sum_op.cc @@ -210,12 +210,11 @@ REGISTER_OPERATOR(partial_sum, REGISTER_OPERATOR(partial_sum_grad, ops::PartialSumGradOp); -REGISTER_OP_CPU_KERNEL( - partial_sum, - ops::PartialSumKernel, - ops::PartialSumKernel, - ops::PartialSumKernel, - ops::PartialSumKernel); +REGISTER_OP_CPU_KERNEL(partial_sum, + ops::PartialSumKernel, + ops::PartialSumKernel, + ops::PartialSumKernel, + ops::PartialSumKernel); REGISTER_OP_CPU_KERNEL(partial_sum_grad, ops::PartialSumGradientOpKernel, diff --git a/paddle/fluid/operators/partial_sum_op.h b/paddle/fluid/operators/partial_sum_op.h index b45c4cb9b65c74284cafdf9a1277ff2f77f2a585..58ac0671dde10c2bc71011313b478c0f8bec67b3 100644 --- a/paddle/fluid/operators/partial_sum_op.h +++ b/paddle/fluid/operators/partial_sum_op.h @@ -79,8 +79,8 @@ class PartialSumGradientOpKernel : public framework::OpKernel { } // initialize - auto& place = *ctx.template device_context() - .eigen_device(); + auto& place = + *ctx.template device_context().eigen_device(); for (size_t i = 0; i < outs.size(); ++i) { outs[i]->mutable_data(ctx.GetPlace()); auto dxt = framework::EigenVector::Flatten(*outs[i]); diff --git a/paddle/fluid/operators/pool_op_mlu.cc b/paddle/fluid/operators/pool_op_mlu.cc index e40fe2025e28118c13d6b5c7779440f073516403..4f9d1343c8395ab0d37f9802551f72bdc644f1f7 100644 --- a/paddle/fluid/operators/pool_op_mlu.cc +++ b/paddle/fluid/operators/pool_op_mlu.cc @@ -122,9 +122,9 @@ class MLUPoolOpKernel : public framework::OpKernel { handle, pool_mode, out_w, out_h, &extra_input_size); if (extra_input_size > 0) { - paddle::platform::CPUDeviceContext cpu_ctx; + phi::CPUContext cpu_ctx; framework::Tensor extra_host_tensor = - ctx.AllocateTmpTensor( + ctx.AllocateTmpTensor( {static_cast(extra_input_size)}, cpu_ctx); cnnlInitPoolingExtraInput(handle, pool_desc.get(), diff --git a/paddle/fluid/operators/prroi_pool_op.cc b/paddle/fluid/operators/prroi_pool_op.cc index c9e45fe51cf14f4f2f439e7ff83baa54cd20bfac..cf8f17d5f747c4e2945f2edc8c5b9351c9da3189 100644 --- a/paddle/fluid/operators/prroi_pool_op.cc +++ b/paddle/fluid/operators/prroi_pool_op.cc @@ -200,15 +200,13 @@ REGISTER_OPERATOR(prroi_pool, ops::PRROIPoolGradMaker, ops::PRROIPoolGradMaker); REGISTER_OPERATOR(prroi_pool_grad, ops::PRROIPoolGradOp); -REGISTER_OP_CPU_KERNEL( - prroi_pool, - ops::CPUPRROIPoolOpKernel, - ops::CPUPRROIPoolOpKernel, - ops::CPUPRROIPoolOpKernel, - ops::CPUPRROIPoolOpKernel); -REGISTER_OP_CPU_KERNEL( - prroi_pool_grad, - ops::CPUPRROIPoolGradOpKernel, - ops::CPUPRROIPoolGradOpKernel, - ops::CPUPRROIPoolGradOpKernel, - ops::CPUPRROIPoolGradOpKernel); +REGISTER_OP_CPU_KERNEL(prroi_pool, + ops::CPUPRROIPoolOpKernel, + ops::CPUPRROIPoolOpKernel, + ops::CPUPRROIPoolOpKernel, + ops::CPUPRROIPoolOpKernel); +REGISTER_OP_CPU_KERNEL(prroi_pool_grad, + ops::CPUPRROIPoolGradOpKernel, + ops::CPUPRROIPoolGradOpKernel, + ops::CPUPRROIPoolGradOpKernel, + ops::CPUPRROIPoolGradOpKernel); diff --git a/paddle/fluid/operators/prune_gate_by_capacity_op.cc b/paddle/fluid/operators/prune_gate_by_capacity_op.cc index 91223ff0d4813ebfe5bc77e8386e08f809cba0f0..14494f426d2d072b2d4f1f8ad95df14b11d5ff7f 100644 --- a/paddle/fluid/operators/prune_gate_by_capacity_op.cc +++ b/paddle/fluid/operators/prune_gate_by_capacity_op.cc @@ -128,6 +128,5 @@ REGISTER_OP_WITHOUT_GRADIENT(prune_gate_by_capacity, REGISTER_OP_CPU_KERNEL( prune_gate_by_capacity, - ops::PruneGateByCapacityCPUKernel, - ops::PruneGateByCapacityCPUKernel); + ops::PruneGateByCapacityCPUKernel, + ops::PruneGateByCapacityCPUKernel); diff --git a/paddle/fluid/operators/pscore/distributed_lookup_table_op.cc b/paddle/fluid/operators/pscore/distributed_lookup_table_op.cc index 6f0bb0a39d4736e003665a17e191b20b1f6c81a2..dbdf58637580db178cf99a2bee3c0be0faa14ba3 100644 --- a/paddle/fluid/operators/pscore/distributed_lookup_table_op.cc +++ b/paddle/fluid/operators/pscore/distributed_lookup_table_op.cc @@ -152,5 +152,4 @@ REGISTER_OPERATOR(distributed_lookup_table, REGISTER_OP_CPU_KERNEL( distributed_lookup_table, - ops::DistributedLookupTableKernel); + ops::DistributedLookupTableKernel); diff --git a/paddle/fluid/operators/pscore/distributed_push_sparse_op.cc b/paddle/fluid/operators/pscore/distributed_push_sparse_op.cc index 32326531dd779c0edff35033a94f1be4091e96ee..a2bf63da10bd2ff85ab2347b6999c13e956789d1 100644 --- a/paddle/fluid/operators/pscore/distributed_push_sparse_op.cc +++ b/paddle/fluid/operators/pscore/distributed_push_sparse_op.cc @@ -135,6 +135,5 @@ REGISTER_OPERATOR(distributed_push_sparse, REGISTER_OP_CPU_KERNEL( distributed_push_sparse, - ops::DistributedPushSparseKernel, - ops::DistributedPushSparseKernel); + ops::DistributedPushSparseKernel, + ops::DistributedPushSparseKernel); diff --git a/paddle/fluid/operators/pscore/heter_cloud_comm_cpu_test.cc b/paddle/fluid/operators/pscore/heter_cloud_comm_cpu_test.cc index 9f28bd27f10af5825ca594d4b372e4f173477750..0d0897b0af011e42f981a4a88dd85450d20343fe 100644 --- a/paddle/fluid/operators/pscore/heter_cloud_comm_cpu_test.cc +++ b/paddle/fluid/operators/pscore/heter_cloud_comm_cpu_test.cc @@ -134,7 +134,7 @@ void PressTestSendRecv( int64_t data_size = vars_len; VLOG(0) << "float num: " << data_size; float* data_ptr = new float[data_size]; - file.read((char*)data_ptr, 9437184); + file.read(static_cast(data_ptr), 9437184); VLOG(0) << "send data is: " << data_ptr[0] << ", " << data_ptr[1]; std::vector var_names{"34"}; int loopCnt = 10000; @@ -169,7 +169,7 @@ void PressTestSendRecv( delete[] values; std::ofstream recv("/recv_20_34", std::ios::out | std::ios::binary); - recv.write((char*)values, data_size); + recv.write(static_cast(values, data_size)); recv.close(); t.join(); } @@ -177,7 +177,7 @@ void PressTestSendRecv( void TestScopeSendRecv( std::shared_ptr heter_client_ptr_) { platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); framework::Executor exe(place); std::shared_ptr send_scope_ptr = std::make_shared(); diff --git a/paddle/fluid/operators/pscore/heter_listen_and_server_test.cc b/paddle/fluid/operators/pscore/heter_listen_and_server_test.cc index 1bf0cd598d43812bd42238da8a4b1cebe7d1930b..b7267d0c6bc55698979107de4f9ffee08eea8dc1 100644 --- a/paddle/fluid/operators/pscore/heter_listen_and_server_test.cc +++ b/paddle/fluid/operators/pscore/heter_listen_and_server_test.cc @@ -150,7 +150,7 @@ void RunHeterServerOp(std::string endpoint) { framework::Scope scope; platform::CPUPlace place; framework::Executor exe(place); - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); LOG(INFO) << "before GetHeterListenAndServProgram"; GetHeterListenAndServProgram(&program, endpoint); @@ -211,7 +211,7 @@ TEST(HETER_LISTEN_AND_SERV, CPU) { framework::Scope* scope = (*micro_scope)[0]; platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); // create var on local scope int64_t rows_numel = 10; diff --git a/paddle/fluid/operators/pscore/heter_server_test.cc b/paddle/fluid/operators/pscore/heter_server_test.cc index c9cd445c98a148b054f8b8716cf44696a535c6a1..a0332e857cc4a43b90e578b722ccbe2a6004304e 100644 --- a/paddle/fluid/operators/pscore/heter_server_test.cc +++ b/paddle/fluid/operators/pscore/heter_server_test.cc @@ -162,7 +162,7 @@ void StartSendAndRecvServer(std::string endpoint) { framework::Scope scope; platform::CPUPlace place; framework::Executor exe(place); - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); LOG(INFO) << "before AppendSendAndRecvBlock"; auto block = AppendSendAndRecvBlock(&program); std::string in_var_name("x"); @@ -254,7 +254,7 @@ TEST(SENDANDRECV, CPU) { framework::Scope* scope = (*micro_scope)[0]; platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); // create var on local scope int64_t rows_numel = 10; diff --git a/paddle/fluid/operators/pscore/send_and_recv_op.cc b/paddle/fluid/operators/pscore/send_and_recv_op.cc index 71f7cf6a91be55a2c93fdf75fc4dfdaac4885772..73eb3f1509223bc8b1de01a8c128faae736f669f 100644 --- a/paddle/fluid/operators/pscore/send_and_recv_op.cc +++ b/paddle/fluid/operators/pscore/send_and_recv_op.cc @@ -104,12 +104,11 @@ REGISTER_OP_CUDA_KERNEL( ops::SendAndRecvKernel, ops::SendAndRecvKernel, ops::SendAndRecvKernel); -REGISTER_OP_CPU_KERNEL( - send_and_recv, - ops::SendAndRecvKernel, - ops::SendAndRecvKernel, - ops::SendAndRecvKernel, - ops::SendAndRecvKernel); +REGISTER_OP_CPU_KERNEL(send_and_recv, + ops::SendAndRecvKernel, + ops::SendAndRecvKernel, + ops::SendAndRecvKernel, + ops::SendAndRecvKernel); REGISTER_OP_VERSION(send_and_recv) .AddCheckpoint( diff --git a/paddle/fluid/operators/pscore/send_and_recv_op_cpu_test.cc b/paddle/fluid/operators/pscore/send_and_recv_op_cpu_test.cc index 11ef5cc99e842353410405b16232e10f31d1347a..61ef001930a04e1ae70c253dbc509f396d559aee 100644 --- a/paddle/fluid/operators/pscore/send_and_recv_op_cpu_test.cc +++ b/paddle/fluid/operators/pscore/send_and_recv_op_cpu_test.cc @@ -138,7 +138,7 @@ void StartSendAndRecvServer(std::string endpoint) { framework::Scope scope; platform::CPUPlace place; framework::Executor exe(place); - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); LOG(INFO) << "before AppendSendAndRecvBlock"; auto block = AppendSendAndRecvBlock(&program); std::string in_var_name("x"); @@ -227,7 +227,7 @@ TEST(SENDANDRECV, CPU) { framework::Scope* scope = (*micro_scope)[0]; platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); framework::Executor exe(place); // create var on local scope diff --git a/paddle/fluid/operators/pscore/send_and_recv_op_gpu_test.cc b/paddle/fluid/operators/pscore/send_and_recv_op_gpu_test.cc index e443439dafe83fc4670ae5003922a4220a2c1af8..8d0d2d3090c1746b2fd0f1753902f67504190cc9 100644 --- a/paddle/fluid/operators/pscore/send_and_recv_op_gpu_test.cc +++ b/paddle/fluid/operators/pscore/send_and_recv_op_gpu_test.cc @@ -163,7 +163,7 @@ void StartSendAndRecvServer(std::string endpoint) { framework::Scope scope; platform::CPUPlace place; framework::Executor exe(place); - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); LOG(INFO) << "before AppendSendAndRecvBlock"; auto block = AppendSendAndRecvBlock(&program); std::string in_var_name("x"); diff --git a/paddle/fluid/operators/pscore/switch_server_test.cc b/paddle/fluid/operators/pscore/switch_server_test.cc index 4af4d4b89275d5a9140cdf642ccab9e066fedd0d..a5e6fff4804af491f357156e218f107ebc1d41e1 100644 --- a/paddle/fluid/operators/pscore/switch_server_test.cc +++ b/paddle/fluid/operators/pscore/switch_server_test.cc @@ -55,7 +55,7 @@ void StartSwitchInterServer( int main(int argc, char* argv[]) { platform::CPUPlace place; - platform::CPUDeviceContext ctx(place); + phi::CPUContext ctx(place); framework::Executor exe(place); framework::ProgramDesc program; diff --git a/paddle/fluid/operators/py_layer_op.cc b/paddle/fluid/operators/py_layer_op.cc index 512179ba56526efcd4bf11c2879fa07848a846d8..9255a5f164bc4b5b47aa2a895103db19cdeca45b 100644 --- a/paddle/fluid/operators/py_layer_op.cc +++ b/paddle/fluid/operators/py_layer_op.cc @@ -207,23 +207,19 @@ REGISTER_OPERATOR(py_layer, REGISTER_OP_CPU_KERNEL( py_layer, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel, - ops::PyLayerOpKernel>, - ops::PyLayerOpKernel>); + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel, + ops::PyLayerOpKernel>, + ops::PyLayerOpKernel>); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) REGISTER_OP_CUDA_KERNEL( py_layer, diff --git a/paddle/fluid/operators/pyramid_hash_op.cc b/paddle/fluid/operators/pyramid_hash_op.cc index fbda6a13d659240cc63808eed6948f56268f0acb..0dd74f9324fa31be7267167e6e3f6d7fa040f401 100644 --- a/paddle/fluid/operators/pyramid_hash_op.cc +++ b/paddle/fluid/operators/pyramid_hash_op.cc @@ -586,10 +586,8 @@ REGISTER_OPERATOR(pyramid_hash, ops::PyramidHashGradOpMaker); REGISTER_OPERATOR(pyramid_hash_grad, ops::PyramidHashOpGrad); -REGISTER_OP_CPU_KERNEL( - pyramid_hash, - ops::CPUPyramidHashOPKernel, - ops::CPUPyramidHashOPKernel); -REGISTER_OP_CPU_KERNEL( - pyramid_hash_grad, - ops::CPUPyramidHashOPGradKernel); +REGISTER_OP_CPU_KERNEL(pyramid_hash, + ops::CPUPyramidHashOPKernel, + ops::CPUPyramidHashOPKernel); +REGISTER_OP_CPU_KERNEL(pyramid_hash_grad, + ops::CPUPyramidHashOPGradKernel); diff --git a/paddle/fluid/operators/qr_op.cc b/paddle/fluid/operators/qr_op.cc index 4074d0dfc63af12d123a37e398adc8e50ae32ac7..90ace1ba773d1dd8f0d625913762bc4adff86e79 100644 --- a/paddle/fluid/operators/qr_op.cc +++ b/paddle/fluid/operators/qr_op.cc @@ -124,7 +124,6 @@ REGISTER_OPERATOR(qr, REGISTER_OPERATOR(qr_grad, ops::QrGradOp); -REGISTER_OP_CPU_KERNEL( - qr_grad, - ops::QrGradKernel, - ops::QrGradKernel); +REGISTER_OP_CPU_KERNEL(qr_grad, + ops::QrGradKernel, + ops::QrGradKernel); diff --git a/paddle/fluid/operators/quantize_linear_op.cc b/paddle/fluid/operators/quantize_linear_op.cc index 4580acbe3fc833093aff9cf2e266e725407e1f2c..65be8acaa552512a33d0b6b4a5f4f0bcf5a302cd 100644 --- a/paddle/fluid/operators/quantize_linear_op.cc +++ b/paddle/fluid/operators/quantize_linear_op.cc @@ -25,8 +25,8 @@ namespace paddle { namespace operators { template -struct ChannelDequantizeFunctorV2 { - void operator()(const platform::CPUDeviceContext &dev_ctx, +struct ChannelDequantizeFunctorV2 { + void operator()(const phi::CPUContext &dev_ctx, const framework::Tensor *in, const framework::Tensor *scale, T max_range, @@ -72,8 +72,8 @@ struct ChannelDequantizeFunctorV2 { } }; -template struct ChannelDequantizeFunctorV2; -template struct ChannelDequantizeFunctorV2; +template struct ChannelDequantizeFunctorV2; +template struct ChannelDequantizeFunctorV2; class QuantizeLinearOp : public framework::OperatorWithKernel { public: @@ -176,7 +176,7 @@ $$0 \leq c \lt \ the\ channel\ number\ of\ X$$ } // namespace paddle namespace ops = paddle::operators; -using CPU = paddle::platform::CPUDeviceContext; +using CPU = phi::CPUContext; REGISTER_OPERATOR( quantize_linear, diff --git a/paddle/fluid/operators/random_crop_op.cc b/paddle/fluid/operators/random_crop_op.cc index d7c30142ee7782bd5a2d24c1f75443c17acc2e80..b86cd9538aceaabe049786d13140b94ac6d373d8 100644 --- a/paddle/fluid/operators/random_crop_op.cc +++ b/paddle/fluid/operators/random_crop_op.cc @@ -98,7 +98,7 @@ REGISTER_OPERATOR( paddle::framework::EmptyGradOpMaker); template -using Kernel = ops::RandomCropKernel; +using Kernel = ops::RandomCropKernel; REGISTER_OP_CPU_KERNEL(random_crop, Kernel, Kernel, diff --git a/paddle/fluid/operators/random_crop_op.h b/paddle/fluid/operators/random_crop_op.h index 78841dae77fb6303863bb13eb9ac6e992a568531..aee430b50579d230394485d81450f8e60a99b137 100644 --- a/paddle/fluid/operators/random_crop_op.h +++ b/paddle/fluid/operators/random_crop_op.h @@ -30,7 +30,7 @@ template struct Random; template <> -struct Random { +struct Random { using Engine = std::minstd_rand; template @@ -218,7 +218,7 @@ class RandomCropKernel : public framework::OpKernel { for_range(functor); - Random::Engine engine(seed); + Random::Engine engine(seed); engine.discard(functor.prod_batchsize_dims_ * (functor.rank_ - functor.num_batchsize_dims_)); *ctx.Output("SeedOut")->mutable_data( diff --git a/paddle/fluid/operators/rank_attention_op.cc b/paddle/fluid/operators/rank_attention_op.cc index 4c97b9bf5bd1cd4b4293cc44f809d225d8b80bab..716fc58d4187bd2636b95b87bef3acda0154e164 100644 --- a/paddle/fluid/operators/rank_attention_op.cc +++ b/paddle/fluid/operators/rank_attention_op.cc @@ -194,10 +194,9 @@ REGISTER_OPERATOR(rank_attention_grad, ops::RankAttentionGradOp, ops::RankAttentionGradOpNoNeedBufferVarsInference); -REGISTER_OP_CPU_KERNEL( - rank_attention, - ops::RankAttentionKernel, - ops::RankAttentionKernel); +REGISTER_OP_CPU_KERNEL(rank_attention, + ops::RankAttentionKernel, + ops::RankAttentionKernel); REGISTER_OP_VERSION(rank_attention) .AddCheckpoint( diff --git a/paddle/fluid/operators/rank_loss_op.cc b/paddle/fluid/operators/rank_loss_op.cc index 49d6424394ab72eaa583380b253f165ba5a169a8..edf82d00950ae298ee106a599b9dc18217b55b6e 100644 --- a/paddle/fluid/operators/rank_loss_op.cc +++ b/paddle/fluid/operators/rank_loss_op.cc @@ -240,11 +240,9 @@ REGISTER_OPERATOR(rank_loss, ops::RankLossGradMaker, ops::RankLossGradMaker); REGISTER_OPERATOR(rank_loss_grad, ops::RankLossGradOp); -REGISTER_OP_CPU_KERNEL( - rank_loss, ops::RankLossKernel); -REGISTER_OP_CPU_KERNEL( - rank_loss_grad, - ops::RankLossGradKernel); +REGISTER_OP_CPU_KERNEL(rank_loss, ops::RankLossKernel); +REGISTER_OP_CPU_KERNEL(rank_loss_grad, + ops::RankLossGradKernel); REGISTER_OP_CUDA_KERNEL( rank_loss, diff --git a/paddle/fluid/operators/reduce_ops/reduce_amax_op.cc b/paddle/fluid/operators/reduce_ops/reduce_amax_op.cc index fce8c51f003d37fcb219dba2ba850201ab585783..36776cebfcd46dc0998e8e5e75793656b6631482 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_amax_op.cc +++ b/paddle/fluid/operators/reduce_ops/reduce_amax_op.cc @@ -17,26 +17,14 @@ REGISTER_REDUCE_OP(reduce_amax); REGISTER_OP_CPU_KERNEL( reduce_amax, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel); -REGISTER_OP_CPU_KERNEL(reduce_amax_grad, - ops::ReduceGradKernel, - ops::ReduceGradKernel, - ops::ReduceGradKernel, - ops::ReduceGradKernel); + ops::ReduceKernel, + ops::ReduceKernel, + ops::ReduceKernel, + ops::ReduceKernel); +REGISTER_OP_CPU_KERNEL( + reduce_amax_grad, + ops::ReduceGradKernel, + ops::ReduceGradKernel, + ops::ReduceGradKernel, + ops:: + ReduceGradKernel); diff --git a/paddle/fluid/operators/reduce_ops/reduce_amin_op.cc b/paddle/fluid/operators/reduce_ops/reduce_amin_op.cc index a6c4cb55105296964c92fd401592aa1f9514657e..bb99ca9b17e7ea80f8d7b386a14b86b467a78df1 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_amin_op.cc +++ b/paddle/fluid/operators/reduce_ops/reduce_amin_op.cc @@ -17,26 +17,14 @@ REGISTER_REDUCE_OP(reduce_amin); REGISTER_OP_CPU_KERNEL( reduce_amin, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel, - ops::ReduceKernel); -REGISTER_OP_CPU_KERNEL(reduce_amin_grad, - ops::ReduceGradKernel, - ops::ReduceGradKernel, - ops::ReduceGradKernel, - ops::ReduceGradKernel); + ops::ReduceKernel, + ops::ReduceKernel, + ops::ReduceKernel, + ops::ReduceKernel); +REGISTER_OP_CPU_KERNEL( + reduce_amin_grad, + ops::ReduceGradKernel, + ops::ReduceGradKernel, + ops::ReduceGradKernel, + ops:: + ReduceGradKernel); diff --git a/paddle/fluid/operators/repeat_interleave_op.cc b/paddle/fluid/operators/repeat_interleave_op.cc index 2ed43cf8f0ea4963d4a7e6656d2154ee7778bd66..f3bec9489fdb0526b4f82d064be1a817c2220fa6 100644 --- a/paddle/fluid/operators/repeat_interleave_op.cc +++ b/paddle/fluid/operators/repeat_interleave_op.cc @@ -172,16 +172,14 @@ REGISTER_OPERATOR(repeat_interleave, REGISTER_OPERATOR(repeat_interleave_grad, ops::RepeatInterleaveGradOp, ops::RepeatInterleaveGradNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - repeat_interleave, - ops::RepeatInterleaveKernel, - ops::RepeatInterleaveKernel, - ops::RepeatInterleaveKernel, - ops::RepeatInterleaveKernel); +REGISTER_OP_CPU_KERNEL(repeat_interleave, + ops::RepeatInterleaveKernel, + ops::RepeatInterleaveKernel, + ops::RepeatInterleaveKernel, + ops::RepeatInterleaveKernel); REGISTER_OP_CPU_KERNEL( repeat_interleave_grad, - ops::RepeatInterleaveGradKernel, - ops::RepeatInterleaveGradKernel, - ops::RepeatInterleaveGradKernel, - ops::RepeatInterleaveGradKernel); + ops::RepeatInterleaveGradKernel, + ops::RepeatInterleaveGradKernel, + ops::RepeatInterleaveGradKernel, + ops::RepeatInterleaveGradKernel); diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index ec9c1198996c1d2fabbfce7357007a177c317f79..b665cce096207daf540af0bcfb3ef4019463cadd 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -420,7 +420,7 @@ class ReshapeKernel { pt_scalar_shape = phi::IntArray(shape_attr); } if (platform::is_cpu_place(ctx.GetPlace())) { - auto &dev_ctx = ctx.device_context(); + auto &dev_ctx = ctx.device_context(); phi::ReshapeKernel(static_cast(dev_ctx), *in, pt_scalar_shape, @@ -455,7 +455,7 @@ class ReshapeGradKernel { d_x->mutable_data(ctx.GetPlace(), d_out->type()); if (platform::is_cpu_place(ctx.GetPlace())) { - auto &dev_ctx = ctx.device_context(); + auto &dev_ctx = ctx.device_context(); phi::ReshapeGradKernel( static_cast(dev_ctx), *d_out, d_x); } @@ -485,7 +485,7 @@ class ReshapeDoubleGradKernel { dd_out->mutable_data(ctx.GetPlace(), dd_x->type()); if (platform::is_cpu_place(ctx.GetPlace())) { - auto &dev_ctx = ctx.device_context(); + auto &dev_ctx = ctx.device_context(); phi::ReshapeDoubleGradKernel( static_cast(dev_ctx), *d_out, *dd_x, dd_out); } diff --git a/paddle/fluid/operators/row_conv_op.cc b/paddle/fluid/operators/row_conv_op.cc index 1cf72e320ffad559c16e4829ce0ea7a78ade4cc1..fc39d174c90ae9e9dd61f9d212a77cc1dcfb2adc 100644 --- a/paddle/fluid/operators/row_conv_op.cc +++ b/paddle/fluid/operators/row_conv_op.cc @@ -140,8 +140,7 @@ https://github.com/PaddlePaddle/Paddle/issues/2228#issuecomment-303903645 . }; template -class RowConvKernel - : public framework::OpKernel { +class RowConvKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &context) const override { auto *x = context.Input("X"); @@ -216,8 +215,7 @@ class RowConvKernel }; template -class RowConvGradKernel - : public framework::OpKernel { +class RowConvGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext &context) const override { auto *x = context.Input("X"); @@ -353,8 +351,6 @@ REGISTER_OPERATOR(row_conv, ops::RowConvGradOpMaker, ops::RowConvGradOpMaker); REGISTER_OPERATOR(row_conv_grad, ops::RowConvGradOp); -REGISTER_OP_CPU_KERNEL( - row_conv, ops::RowConvKernel); -REGISTER_OP_CPU_KERNEL( - row_conv_grad, - ops::RowConvGradKernel); +REGISTER_OP_CPU_KERNEL(row_conv, ops::RowConvKernel); +REGISTER_OP_CPU_KERNEL(row_conv_grad, + ops::RowConvGradKernel); diff --git a/paddle/fluid/operators/run_program_op.cc b/paddle/fluid/operators/run_program_op.cc index 99ad2328b77cd29e9d4e79ce492f73dbdf5a23cf..fd400d291367018cf516336c901defe1e1b05d59 100644 --- a/paddle/fluid/operators/run_program_op.cc +++ b/paddle/fluid/operators/run_program_op.cc @@ -232,9 +232,7 @@ REGISTER_OPERATOR(run_program, REGISTER_OPERATOR(run_program_grad, ops::RunProgramGradOp); /* see [Why use single type kernel] */ -REGISTER_OP_CPU_KERNEL( - run_program, - ops::RunProgramOpKernel) -REGISTER_OP_CPU_KERNEL( - run_program_grad, - ops::RunProgramGradOpKernel) +REGISTER_OP_CPU_KERNEL(run_program, + ops::RunProgramOpKernel) +REGISTER_OP_CPU_KERNEL(run_program_grad, + ops::RunProgramGradOpKernel) diff --git a/paddle/fluid/operators/sample_logits_op.h b/paddle/fluid/operators/sample_logits_op.h index d4e862f26cd6d36dc0af2c9dad06126012138bbf..d6affde0ce022bd94d4a4185b1f03913bb258a70 100644 --- a/paddle/fluid/operators/sample_logits_op.h +++ b/paddle/fluid/operators/sample_logits_op.h @@ -244,8 +244,7 @@ class SampleLogitsKernel : public framework::OpKernel { context.Attr("remove_accidental_hits"); // device contexts - auto& dev_ctx = - context.template device_context(); + auto& dev_ctx = context.template device_context(); // UNDERSTAND: allocate memories for temporaries sampled_logits->mutable_data(samples_dim, context.GetPlace()); @@ -278,8 +277,7 @@ class SampleLogitsKernel : public framework::OpKernel { probabilities->mutable_data(samples_dim, context.GetPlace()); // UNDERSTAND: sampling const auto seed = context.Attr("seed"); - auto sampler_with_prob = - math::SampleWithProb(); + auto sampler_with_prob = math::SampleWithProb(); sampler_with_prob(dev_ctx, math::LogUniformSampler(num_classes, seed), num_samples, @@ -315,9 +313,8 @@ class SampleLogitsGradKernel : public framework::OpKernel { context.Input(framework::GradVarName("SampledLogits")); logits_grad->mutable_data(context.GetPlace()); - auto& dev_ctx = - context.template device_context(); - phi::funcs::SetConstant set_zero; + auto& dev_ctx = context.template device_context(); + phi::funcs::SetConstant set_zero; set_zero(dev_ctx, logits_grad, static_cast(0)); // UNDERSTAND: scatter it back to logit_grad diff --git a/paddle/fluid/operators/save_combine_op.cc b/paddle/fluid/operators/save_combine_op.cc index 385b092c4bcc0a45d6e2b9eda9a7323be62a8210..6b5c2367bb9ad644bf6b21c36e53fd9b7f1bd079 100644 --- a/paddle/fluid/operators/save_combine_op.cc +++ b/paddle/fluid/operators/save_combine_op.cc @@ -104,9 +104,8 @@ REGISTER_OPERATOR(save_combine, REGISTER_OP_CPU_KERNEL( save_combine, - ops::SaveCombineOpKernel, - ops::SaveCombineOpKernel, - ops::SaveCombineOpKernel, - ops::SaveCombineOpKernel, - ops::SaveCombineOpKernel); + ops::SaveCombineOpKernel, + ops::SaveCombineOpKernel, + ops::SaveCombineOpKernel, + ops::SaveCombineOpKernel, + ops::SaveCombineOpKernel); diff --git a/paddle/fluid/operators/save_op.cc b/paddle/fluid/operators/save_op.cc index 0ff381bdbab3f5565672fcaaf39670a0fb05bbcb..f269c4aa32dea71c22ad5dba861a42c01e1b8160 100644 --- a/paddle/fluid/operators/save_op.cc +++ b/paddle/fluid/operators/save_op.cc @@ -90,14 +90,12 @@ REGISTER_OPERATOR(save, REGISTER_OP_CPU_KERNEL( save, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel, - ops::SaveOpKernel); + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel, + ops::SaveOpKernel); diff --git a/paddle/fluid/operators/scatter_test.cc b/paddle/fluid/operators/scatter_test.cc index 93f2d60e5f232767f8e604ca98e3c39fc00caf8b..1249e3e807ec7c5b1ed1dfba020f6f9abee3ed30 100644 --- a/paddle/fluid/operators/scatter_test.cc +++ b/paddle/fluid/operators/scatter_test.cc @@ -42,7 +42,7 @@ TEST(scatter, ScatterUpdate) { } auto* cpu_place = new paddle::platform::CPUPlace(); - paddle::platform::CPUDeviceContext ctx(*cpu_place); + phi::CPUContext ctx(*cpu_place); phi::funcs::ScatterAssign(ctx, src, index, &output); for (size_t i = 0; i < 4; ++i) EXPECT_EQ(p_output[i], 0.0f); diff --git a/paddle/fluid/operators/search_compute.h b/paddle/fluid/operators/search_compute.h index 32aa7442f519985cbe841b8a9453bff70b52fe32..07cd48604b8aa8ab60a3943111901802a96f4de1 100644 --- a/paddle/fluid/operators/search_compute.h +++ b/paddle/fluid/operators/search_compute.h @@ -63,7 +63,7 @@ void call_gemm(const framework::ExecutionContext& ctx, T* C) { int lda = (TransA == CblasNoTrans) ? K : M; int ldb = (TransB == CblasNoTrans) ? N : K; - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); blas.GEMM(TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, N); } diff --git a/paddle/fluid/operators/seed_op.cc b/paddle/fluid/operators/seed_op.cc index 1364d4c1d2ae91fbf8027565b7578c979572c984..527884ec9c9b6b013598c631aa9ae79e4fc3f852 100644 --- a/paddle/fluid/operators/seed_op.cc +++ b/paddle/fluid/operators/seed_op.cc @@ -72,8 +72,7 @@ REGISTER_OPERATOR( ops::SeedOpMaker, paddle::framework::EmptyGradOpMaker, paddle::framework::EmptyGradOpMaker); -REGISTER_OP_CPU_KERNEL( - seed, ops::CPUSeedKernel); +REGISTER_OP_CPU_KERNEL(seed, ops::CPUSeedKernel); /* ========================== register checkpoint ===========================*/ REGISTER_OP_VERSION(seed).AddCheckpoint( diff --git a/paddle/fluid/operators/seed_op.cu b/paddle/fluid/operators/seed_op.cu index 449bd694ceb4637db08b0386c4e2727a5b92eeec..9b1d7a27e58e42af50524c231cdf5a008584a3f1 100644 --- a/paddle/fluid/operators/seed_op.cu +++ b/paddle/fluid/operators/seed_op.cu @@ -32,8 +32,8 @@ class GPUSeedKernel : public framework::OpKernel { platform::DeviceContextPool::Instance(); auto &dev_ctx = *pool.Get(platform::CPUPlace()); out->mutable_data(platform::CPUPlace()); - phi::funcs::SetConstant functor; - functor(reinterpret_cast(dev_ctx), + phi::funcs::SetConstant functor; + functor(reinterpret_cast(dev_ctx), out, static_cast(seed)); } else { diff --git a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc index 9b7bd3fd6c6ab987efce6042e95c2aee4ab78319..117fc4ebe0c36030cd1836fbb739a2eb6cf1e708 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_concat_op.cc @@ -141,19 +141,17 @@ REGISTER_OPERATOR(sequence_concat, op::SeqConcatOpMaker, op::SeqConcatGradOpMaker, op::SeqConcatGradOpMaker); -REGISTER_OP_CPU_KERNEL( - sequence_concat, - op::SeqConcatKernel, - op::SeqConcatKernel, - op::SeqConcatKernel, - op::SeqConcatKernel); +REGISTER_OP_CPU_KERNEL(sequence_concat, + op::SeqConcatKernel, + op::SeqConcatKernel, + op::SeqConcatKernel, + op::SeqConcatKernel); REGISTER_OPERATOR(sequence_concat_grad, op::SeqConcatGradOp, op::SeqConcatGradNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_concat_grad, - op::SeqConcatGradKernel, - op::SeqConcatGradKernel, - op::SeqConcatGradKernel, - op::SeqConcatGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_concat_grad, + op::SeqConcatGradKernel, + op::SeqConcatGradKernel, + op::SeqConcatGradKernel, + op::SeqConcatGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc b/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc index dced2038eb6808a4ea614cdb8d14417110224014..f1350ce334b418a01a179a4d3a026088d2b976d0 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc @@ -268,11 +268,9 @@ REGISTER_OPERATOR(sequence_conv_grad, ops::SequenceConvGradOp, ops::SequenceConvGradNoNeedBufferVarsInference); -REGISTER_OP_CPU_KERNEL( - sequence_conv, - ops::SequenceConvKernel, - ops::SequenceConvKernel); -REGISTER_OP_CPU_KERNEL( - sequence_conv_grad, - ops::SequenceConvGradKernel, - ops::SequenceConvGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_conv, + ops::SequenceConvKernel, + ops::SequenceConvKernel); +REGISTER_OP_CPU_KERNEL(sequence_conv_grad, + ops::SequenceConvGradKernel, + ops::SequenceConvGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc index a06ed8b02d11005f6a212f7d4fd837fb759daae9..de55f1ab52a351b03062b940e5406f798e16ece6 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc @@ -88,7 +88,6 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(sequence_enumerate, ops::SequenceEnumerateOp, ops::SequenceEnumerateOpMaker); -REGISTER_OP_CPU_KERNEL( - sequence_enumerate, - ops::SequenceEnumerateKernel, - ops::SequenceEnumerateKernel); +REGISTER_OP_CPU_KERNEL(sequence_enumerate, + ops::SequenceEnumerateKernel, + ops::SequenceEnumerateKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc b/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc index e763635b7f419db2fbd669b2f2e0564180f6a6c8..c64b568e533d09c347bd35094af0ce9a802047ff 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_erase_op.cc @@ -97,7 +97,6 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(sequence_erase, ops::SequenceEraseOp, ops::SequenceEraseOpMaker); -REGISTER_OP_CPU_KERNEL( - sequence_erase, - ops::SequenceEraseKernel, - ops::SequenceEraseKernel); +REGISTER_OP_CPU_KERNEL(sequence_erase, + ops::SequenceEraseKernel, + ops::SequenceEraseKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.cc b/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.cc index 4135f046c21e2d1573fd55cce6c356695d686fe1..5c3731fc90253fbaf0ff474b6f57babbf82ee8a5 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.cc @@ -208,16 +208,14 @@ REGISTER_OPERATOR( REGISTER_OPERATOR(sequence_expand_as_grad, ops::SequenceExpandAsOpGrad, ops::SequenceExpandAsGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_expand_as, - ops::SequenceExpandAsKernel, - ops::SequenceExpandAsKernel, - ops::SequenceExpandAsKernel, - ops::SequenceExpandAsKernel); +REGISTER_OP_CPU_KERNEL(sequence_expand_as, + ops::SequenceExpandAsKernel, + ops::SequenceExpandAsKernel, + ops::SequenceExpandAsKernel, + ops::SequenceExpandAsKernel); REGISTER_OP_CPU_KERNEL( sequence_expand_as_grad, - ops::SequenceExpandAsGradKernel, - ops::SequenceExpandAsGradKernel, - ops::SequenceExpandAsGradKernel, - ops::SequenceExpandAsGradKernel); + ops::SequenceExpandAsGradKernel, + ops::SequenceExpandAsGradKernel, + ops::SequenceExpandAsGradKernel, + ops::SequenceExpandAsGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.h b/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.h index da9ad3574db2f704f010b0cef21720528ae99b0c..02d2b87874d05d67435e525c64bd64d938ed9b88 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_expand_as_op.h @@ -43,9 +43,9 @@ struct SequenceExpandAsGradFunctor { }; template -struct SequenceExpandAsFunctor { +struct SequenceExpandAsFunctor { void operator()( - const platform::CPUDeviceContext &context, + const phi::CPUContext &context, const framework::LoDTensor &x, const framework::Vector &ref_lod, /*expand referenced lod*/ framework::LoDTensor *out) { @@ -121,9 +121,9 @@ class SequenceExpandAsKernel : public framework::OpKernel { * * */ template -struct SequenceExpandAsGradFunctor { +struct SequenceExpandAsGradFunctor { void operator()( - const platform::CPUDeviceContext &context, + const phi::CPUContext &context, const framework::LoDTensor &dout, const framework::Vector &ref_lod, /*expand referenced lod*/ framework::LoDTensor *dx) { diff --git a/paddle/fluid/operators/sequence_ops/sequence_expand_op.cc b/paddle/fluid/operators/sequence_ops/sequence_expand_op.cc index e9e7912fe50361762e9310fcfe02b0189d09cb10..a2fb088975e39e6051762bef838f6801788d5049 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_expand_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_expand_op.cc @@ -281,15 +281,13 @@ REGISTER_OPERATOR(sequence_expand, REGISTER_OPERATOR(sequence_expand_grad, ops::SequenceExpandOpGrad, ops::SequenceExpandGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_expand, - ops::SequenceExpandKernel, - ops::SequenceExpandKernel, - ops::SequenceExpandKernel, - ops::SequenceExpandKernel); -REGISTER_OP_CPU_KERNEL( - sequence_expand_grad, - ops::SequenceExpandGradKernel, - ops::SequenceExpandGradKernel, - ops::SequenceExpandGradKernel, - ops::SequenceExpandGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_expand, + ops::SequenceExpandKernel, + ops::SequenceExpandKernel, + ops::SequenceExpandKernel, + ops::SequenceExpandKernel); +REGISTER_OP_CPU_KERNEL(sequence_expand_grad, + ops::SequenceExpandGradKernel, + ops::SequenceExpandGradKernel, + ops::SequenceExpandGradKernel, + ops::SequenceExpandGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_expand_op.h b/paddle/fluid/operators/sequence_ops/sequence_expand_op.h index b6cd8c3b9079ac5b925ecf0a2df814a1dea75455..158aa0e4fe19002ec99d1a63ea2583ee6f0826ba 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_expand_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_expand_op.h @@ -49,9 +49,9 @@ struct SequenceExpandGradFunctor { }; template -struct SequenceExpandFunctor { +struct SequenceExpandFunctor { void operator()( - const platform::CPUDeviceContext& context, + const phi::CPUContext& context, const LoDTensor& x, const framework::Vector& x_lod, /*expand source lod*/ const framework::Vector& ref_lod, /*expand referenced lod*/ @@ -161,9 +161,9 @@ class SequenceExpandKernel : public framework::OpKernel { * * */ template -struct SequenceExpandGradFunctor { +struct SequenceExpandGradFunctor { void operator()( - const platform::CPUDeviceContext& context, + const phi::CPUContext& context, const LoDTensor& dout, const framework::Vector& x_lod, /*expand source lod*/ const framework::Vector& ref_lod, /*expand referenced lod*/ @@ -181,7 +181,7 @@ struct SequenceExpandGradFunctor { int dout_end = dout_offset + repeat_num * x_seq_len; auto dout_sub = dout.Slice(dout_offset, dout_end); dout_sub.Resize({repeat_num, dx_sub.dims()[0]}); - phi::funcs::ColwiseSum col_sum; + phi::funcs::ColwiseSum col_sum; col_sum(context, dout_sub, &dx_sub); dout_offset += repeat_num * x_seq_len; } diff --git a/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc b/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc index 6b20338f95eb71021f643e39e842bb646411e456..2ed9c44f5928ce9f799924b28f8ef689f8ba8d8a 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc @@ -103,11 +103,7 @@ REGISTER_OPERATOR( REGISTER_OP_CPU_KERNEL( sequence_mask, - paddle::operators::SequenceMaskKernel, - paddle::operators::SequenceMaskKernel, - paddle::operators::SequenceMaskKernel, - paddle::operators::SequenceMaskKernel); + paddle::operators::SequenceMaskKernel, + paddle::operators::SequenceMaskKernel, + paddle::operators::SequenceMaskKernel, + paddle::operators::SequenceMaskKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_pad_op.cc b/paddle/fluid/operators/sequence_ops/sequence_pad_op.cc index dc04a6cce7abdbaf1d824c4edf016f56fc6e80da..ad4876970c532aca83edc3144a5f206b57b4f9d9 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_pad_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_pad_op.cc @@ -282,15 +282,13 @@ REGISTER_OPERATOR(sequence_pad, REGISTER_OPERATOR(sequence_pad_grad, ops::SequencePadGradOp, ops::SequencePadGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_pad, - ops::SequencePadOpKernel, - ops::SequencePadOpKernel, - ops::SequencePadOpKernel, - ops::SequencePadOpKernel); -REGISTER_OP_CPU_KERNEL( - sequence_pad_grad, - ops::SequencePadGradOpKernel, - ops::SequencePadGradOpKernel, - ops::SequencePadGradOpKernel, - ops::SequencePadGradOpKernel); +REGISTER_OP_CPU_KERNEL(sequence_pad, + ops::SequencePadOpKernel, + ops::SequencePadOpKernel, + ops::SequencePadOpKernel, + ops::SequencePadOpKernel); +REGISTER_OP_CPU_KERNEL(sequence_pad_grad, + ops::SequencePadGradOpKernel, + ops::SequencePadGradOpKernel, + ops::SequencePadGradOpKernel, + ops::SequencePadGradOpKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_pool_op.cc b/paddle/fluid/operators/sequence_ops/sequence_pool_op.cc index 327fdfda5e28f5fdf0faaceed86e7ec23130c152..6c146a699af8b8b141a1b8a1677acc6e3abc43e4 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_pool_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_pool_op.cc @@ -193,12 +193,10 @@ REGISTER_OPERATOR(sequence_pool, REGISTER_OPERATOR(sequence_pool_grad, ops::SequencePoolGradOp, ops::SequencePoolGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_pool, - ops::SequencePoolKernel, - ops::SequencePoolKernel); - -REGISTER_OP_CPU_KERNEL( - sequence_pool_grad, - ops::SequencePoolGradKernel, - ops::SequencePoolGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_pool, + ops::SequencePoolKernel, + ops::SequencePoolKernel); + +REGISTER_OP_CPU_KERNEL(sequence_pool_grad, + ops::SequencePoolGradKernel, + ops::SequencePoolGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc b/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc index 5266650f2279d936c80a071e45c0acbf58f3b5c3..6925267f1a981ae3c1bd4b4a1c3103d3769dc12b 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_reshape_op.cc @@ -144,15 +144,13 @@ REGISTER_OPERATOR(sequence_reshape, ops::SequenceReshapeGradOpMaker, ops::SequenceReshapeGradOpMaker); REGISTER_OPERATOR(sequence_reshape_grad, ops::SequenceReshapeGradOp); -REGISTER_OP_CPU_KERNEL( - sequence_reshape, - ops::SequenceReshapeKernel, - ops::SequenceReshapeKernel, - ops::SequenceReshapeKernel, - ops::SequenceReshapeKernel); -REGISTER_OP_CPU_KERNEL( - sequence_reshape_grad, - ops::SequenceReshapeGradKernel, - ops::SequenceReshapeGradKernel, - ops::SequenceReshapeGradKernel, - ops::SequenceReshapeGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_reshape, + ops::SequenceReshapeKernel, + ops::SequenceReshapeKernel, + ops::SequenceReshapeKernel, + ops::SequenceReshapeKernel); +REGISTER_OP_CPU_KERNEL(sequence_reshape_grad, + ops::SequenceReshapeGradKernel, + ops::SequenceReshapeGradKernel, + ops::SequenceReshapeGradKernel, + ops::SequenceReshapeGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_reverse_op.cc b/paddle/fluid/operators/sequence_ops/sequence_reverse_op.cc index f17c2baca9896868b3370037934776c209d3bf39..d1e8409653a5e75ac1758f3c32d82ffb24209e64 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_reverse_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_reverse_op.cc @@ -22,10 +22,9 @@ REGISTER_OPERATOR(sequence_reverse, ops::SequenceReverseGradOpMaker, ops::SequenceReverseGradOpMaker); -REGISTER_OP_CPU_KERNEL( - sequence_reverse, - ops::SequenceReverseOpKernel, - ops::SequenceReverseOpKernel, - ops::SequenceReverseOpKernel, - ops::SequenceReverseOpKernel, - ops::SequenceReverseOpKernel); +REGISTER_OP_CPU_KERNEL(sequence_reverse, + ops::SequenceReverseOpKernel, + ops::SequenceReverseOpKernel, + ops::SequenceReverseOpKernel, + ops::SequenceReverseOpKernel, + ops::SequenceReverseOpKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_slice_op.cc b/paddle/fluid/operators/sequence_ops/sequence_slice_op.cc index a7578e25f93f4bfbec34d217f851bbbc05dd1131..9375cea85c78f5a58bb32ad1600ee003a01479d4 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_slice_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_slice_op.cc @@ -159,16 +159,14 @@ REGISTER_OPERATOR(sequence_slice, REGISTER_OPERATOR(sequence_slice_grad, ops::SequenceSliceGradOp, ops::SequenceSliceGradNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_slice, - ops::SequenceSliceOpKernel, - ops::SequenceSliceOpKernel, - ops::SequenceSliceOpKernel, - ops::SequenceSliceOpKernel); +REGISTER_OP_CPU_KERNEL(sequence_slice, + ops::SequenceSliceOpKernel, + ops::SequenceSliceOpKernel, + ops::SequenceSliceOpKernel, + ops::SequenceSliceOpKernel); REGISTER_OP_CPU_KERNEL( sequence_slice_grad, - ops::SequenceSliceGradOpKernel, - ops::SequenceSliceGradOpKernel, - ops::SequenceSliceGradOpKernel, - ops::SequenceSliceGradOpKernel); + ops::SequenceSliceGradOpKernel, + ops::SequenceSliceGradOpKernel, + ops::SequenceSliceGradOpKernel, + ops::SequenceSliceGradOpKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_softmax_op.cc b/paddle/fluid/operators/sequence_ops/sequence_softmax_op.cc index 863d2e01d73e5a7cc8e2f35c9e6f901994a5422f..bb0ad26b51bb4c3079459161b1a560bcf0512b86 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_softmax_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_softmax_op.cc @@ -185,11 +185,9 @@ REGISTER_OPERATOR( REGISTER_OPERATOR(sequence_softmax_grad, ops::SequenceSoftmaxGradOp, ops::SequenceSoftmaxGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_softmax, - ops::SequenceSoftmaxKernel, - ops::SequenceSoftmaxKernel); -REGISTER_OP_CPU_KERNEL( - sequence_softmax_grad, - ops::SequenceSoftmaxGradKernel, - ops::SequenceSoftmaxGradKernel); +REGISTER_OP_CPU_KERNEL(sequence_softmax, + ops::SequenceSoftmaxKernel, + ops::SequenceSoftmaxKernel); +REGISTER_OP_CPU_KERNEL(sequence_softmax_grad, + ops::SequenceSoftmaxGradKernel, + ops::SequenceSoftmaxGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_softmax_op.h b/paddle/fluid/operators/sequence_ops/sequence_softmax_op.h index 3ebf955fe259a6a8f471ad02c1c98699309a08ab..0d3d3b695af4bfa9975b2c35f9136bde2f4b48d0 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_softmax_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_softmax_op.h @@ -41,8 +41,8 @@ struct SequenceSoftmaxGradFunctor { }; template -struct SequenceSoftmaxFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct SequenceSoftmaxFunctor { + void operator()(const phi::CPUContext &ctx, const LoDTensor &x, const framework::Vector &ref_lod, /*referenced lod*/ LoDTensor *out) { @@ -63,8 +63,8 @@ struct SequenceSoftmaxFunctor { }; template -struct SequenceSoftmaxGradFunctor { - void operator()(const platform::CPUDeviceContext &ctx, +struct SequenceSoftmaxGradFunctor { + void operator()(const phi::CPUContext &ctx, const LoDTensor &dout, const LoDTensor &out, const framework::Vector &ref_lod, /*referenced lod*/ diff --git a/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.cc b/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.cc index 0c312cfb1cf8368977d8f7b345d9e2f41a0619d5..b19dfe40ed95e1dff22c33f5fb20cec240d63535 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.cc @@ -139,9 +139,7 @@ REGISTER_OPERATOR(sequence_topk_avg_pooling_grad, ops::SequenceTopkAvgPoolingGradOp); REGISTER_OP_CPU_KERNEL( sequence_topk_avg_pooling, - ops::SequenceTopkAvgPoolingKernel); + ops::SequenceTopkAvgPoolingKernel); REGISTER_OP_CPU_KERNEL( sequence_topk_avg_pooling_grad, - ops::SequenceTopkAvgPoolingGradKernel); + ops::SequenceTopkAvgPoolingGradKernel); diff --git a/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.h b/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.h index 04115c69a9a7d6aea55c736a1376274d7a460560..1c1168e449eb7dfd46a519da547c37ea25343811 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_topk_avg_pooling_op.h @@ -202,9 +202,8 @@ class SequenceTopkAvgPoolingGradKernel : public framework::OpKernel { auto pos_data = pos_input->data(); auto dout_data = d_out->data(); - auto& dev_ctx = - context.template device_context(); - phi::funcs::SetConstant zero; + auto& dev_ctx = context.template device_context(); + phi::funcs::SetConstant zero; zero(dev_ctx, d_in, static_cast(0.0)); auto din_data = d_in->data(); diff --git a/paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc b/paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc index 4b90d64d26fe353070d54f9873c6ca3cd0a9c40b..613dc8bfbc9b10da53c6105e3ab6d2d8e155ada6 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc @@ -194,16 +194,14 @@ REGISTER_OPERATOR(sequence_unpad, REGISTER_OPERATOR(sequence_unpad_grad, ops::SequenceUnpadGradOp, ops::SequenceUnpadGradOpNoNeedBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - sequence_unpad, - ops::SequenceUnpadOpKernel, - ops::SequenceUnpadOpKernel, - ops::SequenceUnpadOpKernel, - ops::SequenceUnpadOpKernel); +REGISTER_OP_CPU_KERNEL(sequence_unpad, + ops::SequenceUnpadOpKernel, + ops::SequenceUnpadOpKernel, + ops::SequenceUnpadOpKernel, + ops::SequenceUnpadOpKernel); REGISTER_OP_CPU_KERNEL( sequence_unpad_grad, - ops::SequenceUnpadGradOpKernel, - ops::SequenceUnpadGradOpKernel, - ops::SequenceUnpadGradOpKernel, - ops::SequenceUnpadGradOpKernel); + ops::SequenceUnpadGradOpKernel, + ops::SequenceUnpadGradOpKernel, + ops::SequenceUnpadGradOpKernel, + ops::SequenceUnpadGradOpKernel); diff --git a/paddle/fluid/operators/shuffle_channel_op.cc b/paddle/fluid/operators/shuffle_channel_op.cc index 74896d84996721d8defdfb6b6e6cd66bd6fc5477..4a3668b11405921ac9062acb5bbe75727472940a 100644 --- a/paddle/fluid/operators/shuffle_channel_op.cc +++ b/paddle/fluid/operators/shuffle_channel_op.cc @@ -137,13 +137,11 @@ REGISTER_OPERATOR(shuffle_channel, REGISTER_OPERATOR(shuffle_channel_grad, ops::ShuffleChannelGradOp); -REGISTER_OP_CPU_KERNEL( - shuffle_channel, - ops::ShuffleChannelOpKernel, - ops::ShuffleChannelOpKernel); +REGISTER_OP_CPU_KERNEL(shuffle_channel, + ops::ShuffleChannelOpKernel, + ops::ShuffleChannelOpKernel); REGISTER_OP_CPU_KERNEL( shuffle_channel_grad, - ops::ShuffleChannelGradOpKernel, - ops::ShuffleChannelGradOpKernel); + ops::ShuffleChannelGradOpKernel, + ops::ShuffleChannelGradOpKernel); diff --git a/paddle/fluid/operators/slice_op.cc b/paddle/fluid/operators/slice_op.cc index 4b6bcae7635b89185acfdd23a16aeab61156d840..4e81226188304d1aa63c545d92a24acd46e19d00 100644 --- a/paddle/fluid/operators/slice_op.cc +++ b/paddle/fluid/operators/slice_op.cc @@ -466,31 +466,25 @@ REGISTER_OPERATOR(slice_grad, REGISTER_OP_CPU_KERNEL( slice, - ops::SliceKernel, - ops::SliceKernel, - ops::SliceKernel, - ops::SliceKernel, - ops::SliceKernel, - ops::SliceKernel>, - ops::SliceKernel>, - ops::SliceKernel); + ops::SliceKernel, + ops::SliceKernel, + ops::SliceKernel, + ops::SliceKernel, + ops::SliceKernel, + ops::SliceKernel>, + ops::SliceKernel>, + ops::SliceKernel); REGISTER_OP_CPU_KERNEL( slice_grad, - ops::SliceGradKernel, - ops::SliceGradKernel, - ops::SliceGradKernel, - ops::SliceGradKernel, - ops::SliceGradKernel, - ops::SliceGradKernel>, - ops::SliceGradKernel>, - ops::SliceGradKernel); + ops::SliceGradKernel, + ops::SliceGradKernel, + ops::SliceGradKernel, + ops::SliceGradKernel, + ops::SliceGradKernel, + ops::SliceGradKernel>, + ops::SliceGradKernel>, + ops::SliceGradKernel); REGISTER_OP_CUDA_KERNEL( slice, diff --git a/paddle/fluid/operators/smooth_l1_loss_op.cc b/paddle/fluid/operators/smooth_l1_loss_op.cc index eb391fd3fb73cb8108a79a7b61e6302caf2fd5da..f8bebe331d8beb84411f72e791a1ffcf6218760c 100644 --- a/paddle/fluid/operators/smooth_l1_loss_op.cc +++ b/paddle/fluid/operators/smooth_l1_loss_op.cc @@ -225,9 +225,7 @@ REGISTER_OPERATOR(smooth_l1_loss, ops::SmoothL1LossGradMaker, ops::SmoothL1LossGradMaker); REGISTER_OPERATOR(smooth_l1_loss_grad, ops::SmoothL1LossGradOp); -REGISTER_OP_CPU_KERNEL( - smooth_l1_loss, - ops::SmoothL1LossKernel); -REGISTER_OP_CPU_KERNEL( - smooth_l1_loss_grad, - ops::SmoothL1LossGradKernel); +REGISTER_OP_CPU_KERNEL(smooth_l1_loss, + ops::SmoothL1LossKernel); +REGISTER_OP_CPU_KERNEL(smooth_l1_loss_grad, + ops::SmoothL1LossGradKernel); diff --git a/paddle/fluid/operators/solve_op.cc b/paddle/fluid/operators/solve_op.cc index 77a45684aca0eb686db5c9c88127599f344863e2..a7bf413e10519ab6dd11e3b81005c0aee4cb37b8 100644 --- a/paddle/fluid/operators/solve_op.cc +++ b/paddle/fluid/operators/solve_op.cc @@ -221,11 +221,9 @@ REGISTER_OPERATOR(solve, REGISTER_OPERATOR(solve_grad, ops::SolveGradOp); -REGISTER_OP_CPU_KERNEL( - solve, - ops::SolveKernel, - ops::SolveKernel); -REGISTER_OP_CPU_KERNEL( - solve_grad, - ops::SolveGradKernel, - ops::SolveGradKernel); +REGISTER_OP_CPU_KERNEL(solve, + ops::SolveKernel, + ops::SolveKernel); +REGISTER_OP_CPU_KERNEL(solve_grad, + ops::SolveGradKernel, + ops::SolveGradKernel); diff --git a/paddle/fluid/operators/space_to_depth_op.cc b/paddle/fluid/operators/space_to_depth_op.cc index fb428594226a989f26947369ca30d0e02dc8661a..dce7539fe72b81520d2a1adb0038aca88a5538ac 100644 --- a/paddle/fluid/operators/space_to_depth_op.cc +++ b/paddle/fluid/operators/space_to_depth_op.cc @@ -226,15 +226,13 @@ REGISTER_OPERATOR(space_to_depth, REGISTER_OPERATOR(space_to_depth_grad, ops::SpaceToDepthGradOp, ops::SpaceToDepthGradOpNoBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - space_to_depth, - ops::SpaceToDepthKernel, - ops::SpaceToDepthKernel, - ops::SpaceToDepthKernel, - ops::SpaceToDepthKernel); -REGISTER_OP_CPU_KERNEL( - space_to_depth_grad, - ops::SpaceToDepthGradKernel, - ops::SpaceToDepthGradKernel, - ops::SpaceToDepthGradKernel, - ops::SpaceToDepthGradKernel); +REGISTER_OP_CPU_KERNEL(space_to_depth, + ops::SpaceToDepthKernel, + ops::SpaceToDepthKernel, + ops::SpaceToDepthKernel, + ops::SpaceToDepthKernel); +REGISTER_OP_CPU_KERNEL(space_to_depth_grad, + ops::SpaceToDepthGradKernel, + ops::SpaceToDepthGradKernel, + ops::SpaceToDepthGradKernel, + ops::SpaceToDepthGradKernel); diff --git a/paddle/fluid/operators/spectral_helper.h b/paddle/fluid/operators/spectral_helper.h index d66cc503307e6bb061b86c9d2ea9f7dc5075b2df..f69573e18927e1623e3e80e0167e104b3be176b4 100644 --- a/paddle/fluid/operators/spectral_helper.h +++ b/paddle/fluid/operators/spectral_helper.h @@ -210,7 +210,7 @@ void exec_fft(const DeviceContext& ctx, transposed_input.Resize(transposed_input_shape); const auto place = ctx.GetPlace(); transposed_input.mutable_data(place); - TransCompute( + TransCompute( ndim, ctx, *x, &transposed_input, dim_permute); // make an collapsed input: collapse batch axes for input @@ -310,39 +310,39 @@ void exec_fft(const DeviceContext& ctx, for (int i = 0; i < ndim; i++) { reverse_dim_permute[dim_permute[i]] = i; } - TransCompute( + TransCompute( ndim, ctx, transposed_output, out, reverse_dim_permute); } template -struct FFTC2CFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTC2CFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, FFTNormMode normalization, bool forward) { - exec_fft( + exec_fft( ctx, x, out, axes, normalization, forward); } }; template -struct FFTR2CFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTR2CFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, FFTNormMode normalization, bool forward) { - exec_fft( + exec_fft( ctx, x, out, axes, normalization, forward); } }; template -struct FFTC2RFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTC2RFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, @@ -353,14 +353,14 @@ struct FFTC2RFunctor { Tensor temp; temp.mutable_data(x->dims(), ctx.GetPlace()); - FFTC2CFunctor c2c_functor; + FFTC2CFunctor c2c_functor; c2c_functor(ctx, x, &temp, c2c_dims, normalization, forward); const std::vector new_axes{axes.back()}; - exec_fft( + exec_fft( ctx, &temp, out, new_axes, normalization, forward); } else { - exec_fft( + exec_fft( ctx, x, out, axes, normalization, forward); } } @@ -383,8 +383,8 @@ T compute_factor(int64_t size, FFTNormMode normalization) { } template -struct FFTC2CFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTC2CFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, @@ -426,8 +426,8 @@ struct FFTC2CFunctor { }; template -struct FFTR2CFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTR2CFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, @@ -483,8 +483,8 @@ struct FFTR2CFunctor { }; template -struct FFTC2RFunctor { - void operator()(const platform::CPUDeviceContext& ctx, +struct FFTC2RFunctor { + void operator()(const phi::CPUContext& ctx, const Tensor* x, Tensor* out, const std::vector& axes, diff --git a/paddle/fluid/operators/spectral_norm_op.cc b/paddle/fluid/operators/spectral_norm_op.cc index 1af812c336b5a9964c27894802b80bec803654c9..a6addb2e6f46d87f7becb3b00f2087b83a558692 100644 --- a/paddle/fluid/operators/spectral_norm_op.cc +++ b/paddle/fluid/operators/spectral_norm_op.cc @@ -256,11 +256,9 @@ REGISTER_OPERATOR(spectral_norm, ops::SpectralNormGradOpMaker, ops::SpectralNormGradOpMaker); REGISTER_OPERATOR(spectral_norm_grad, ops::SpectralNormOpGrad); -REGISTER_OP_CPU_KERNEL( - spectral_norm, - ops::SpectralNormKernel, - ops::SpectralNormKernel); -REGISTER_OP_CPU_KERNEL( - spectral_norm_grad, - ops::SpectralNormGradKernel, - ops::SpectralNormGradKernel); +REGISTER_OP_CPU_KERNEL(spectral_norm, + ops::SpectralNormKernel, + ops::SpectralNormKernel); +REGISTER_OP_CPU_KERNEL(spectral_norm_grad, + ops::SpectralNormGradKernel, + ops::SpectralNormGradKernel); diff --git a/paddle/fluid/operators/spectral_op.cc b/paddle/fluid/operators/spectral_op.cc index 3f00333b980897033ae2cfd0ca4672e963f94238..91e3880dff0049b324bed7188a90962224a4e25b 100644 --- a/paddle/fluid/operators/spectral_op.cc +++ b/paddle/fluid/operators/spectral_op.cc @@ -351,45 +351,39 @@ REGISTER_OPERATOR(fft_c2c, ops::FFTC2COpMaker, ops::FFTC2CGradOpMaker, ops::FFTC2CGradOpMaker); -REGISTER_OP_CPU_KERNEL( - fft_c2c, - ops::FFTC2CKernel, - ops::FFTC2CKernel); +REGISTER_OP_CPU_KERNEL(fft_c2c, + ops::FFTC2CKernel, + ops::FFTC2CKernel); REGISTER_OPERATOR(fft_c2c_grad, ops::FFTC2CGradOp); -REGISTER_OP_CPU_KERNEL( - fft_c2c_grad, - ops::FFTC2CGradKernel, - ops::FFTC2CGradKernel); +REGISTER_OP_CPU_KERNEL(fft_c2c_grad, + ops::FFTC2CGradKernel, + ops::FFTC2CGradKernel); REGISTER_OPERATOR(fft_r2c, ops::FFTR2COp, ops::FFTR2COpMaker, ops::FFTR2CGradOpMaker, ops::FFTR2CGradOpMaker); -REGISTER_OP_CPU_KERNEL( - fft_r2c, - ops::FFTR2CKernel, - ops::FFTR2CKernel); +REGISTER_OP_CPU_KERNEL(fft_r2c, + ops::FFTR2CKernel, + ops::FFTR2CKernel); REGISTER_OPERATOR(fft_r2c_grad, ops::FFTR2CGradOp); -REGISTER_OP_CPU_KERNEL( - fft_r2c_grad, - ops::FFTR2CGradKernel, - ops::FFTR2CGradKernel); +REGISTER_OP_CPU_KERNEL(fft_r2c_grad, + ops::FFTR2CGradKernel, + ops::FFTR2CGradKernel); REGISTER_OPERATOR(fft_c2r, ops::FFTC2ROp, ops::FFTC2ROpMaker, ops::FFTC2RGradOpMaker, ops::FFTC2RGradOpMaker); -REGISTER_OP_CPU_KERNEL( - fft_c2r, - ops::FFTC2RKernel, - ops::FFTC2RKernel); +REGISTER_OP_CPU_KERNEL(fft_c2r, + ops::FFTC2RKernel, + ops::FFTC2RKernel); REGISTER_OPERATOR(fft_c2r_grad, ops::FFTC2RGradOp); -REGISTER_OP_CPU_KERNEL( - fft_c2r_grad, - ops::FFTC2RGradKernel, - ops::FFTC2RGradKernel); +REGISTER_OP_CPU_KERNEL(fft_c2r_grad, + ops::FFTC2RGradKernel, + ops::FFTC2RGradKernel); diff --git a/paddle/fluid/operators/spp_op.cc b/paddle/fluid/operators/spp_op.cc index 583b0b69a63cfc988310badbcca7b9889901fba2..b1ca67f5218160a0c31341fa826b05e3eb55bde4 100644 --- a/paddle/fluid/operators/spp_op.cc +++ b/paddle/fluid/operators/spp_op.cc @@ -109,11 +109,9 @@ REGISTER_OPERATOR( paddle::framework::DefaultGradOpMaker, paddle::framework::DefaultGradOpMaker); REGISTER_OPERATOR(spp_grad, ops::SppOpGrad); -REGISTER_OP_CPU_KERNEL( - spp, - ops::SppKernel, - ops::SppKernel); -REGISTER_OP_CPU_KERNEL( - spp_grad, - ops::SppGradKernel, - ops::SppGradKernel); +REGISTER_OP_CPU_KERNEL(spp, + ops::SppKernel, + ops::SppKernel); +REGISTER_OP_CPU_KERNEL(spp_grad, + ops::SppGradKernel, + ops::SppGradKernel); diff --git a/paddle/fluid/operators/squared_l2_distance_op.cc b/paddle/fluid/operators/squared_l2_distance_op.cc index 2b76a427065359b1d6b5109f8635dfce40f3c9cf..55d307cf087ece60ca191acda1a28a9b32e8b781 100644 --- a/paddle/fluid/operators/squared_l2_distance_op.cc +++ b/paddle/fluid/operators/squared_l2_distance_op.cc @@ -221,10 +221,8 @@ REGISTER_OPERATOR( REGISTER_OPERATOR(squared_l2_distance_grad, ops::SquaredL2DistanceGradOp, ops::SquaredL2DistanceGradOpNoBufferVarsInferer); -REGISTER_OP_CPU_KERNEL( - squared_l2_distance, - ops::SquaredL2DistanceKernel); +REGISTER_OP_CPU_KERNEL(squared_l2_distance, + ops::SquaredL2DistanceKernel); REGISTER_OP_CPU_KERNEL( squared_l2_distance_grad, - ops::SquaredL2DistanceGradKernel); + ops::SquaredL2DistanceGradKernel); diff --git a/paddle/fluid/operators/squared_l2_norm_op.cc b/paddle/fluid/operators/squared_l2_norm_op.cc index 529c4262b0a08983916281c44ecfe3d83be2f293..f6792baa1f59121e97ae355ac4ff5663b95ef576 100644 --- a/paddle/fluid/operators/squared_l2_norm_op.cc +++ b/paddle/fluid/operators/squared_l2_norm_op.cc @@ -96,11 +96,9 @@ REGISTER_OPERATOR(squared_l2_norm, ops::SquaredL2NormGradOpMaker, ops::SquaredL2NormGradOpMaker); REGISTER_OPERATOR(squared_l2_norm_grad, ops::SquaredL2NormGradOp); -REGISTER_OP_CPU_KERNEL( - squared_l2_norm, - ops::SquaredL2NormKernel, - ops::SquaredL2NormKernel); -REGISTER_OP_CPU_KERNEL( - squared_l2_norm_grad, - ops::SquaredL2NormGradKernel, - ops::SquaredL2NormGradKernel); +REGISTER_OP_CPU_KERNEL(squared_l2_norm, + ops::SquaredL2NormKernel, + ops::SquaredL2NormKernel); +REGISTER_OP_CPU_KERNEL(squared_l2_norm_grad, + ops::SquaredL2NormGradKernel, + ops::SquaredL2NormGradKernel); diff --git a/paddle/fluid/operators/squeeze_op.cc b/paddle/fluid/operators/squeeze_op.cc index 29c54d2699affb2b36f46a2a5ca950df72afa749..f532a429b49e2fa03e99212aaf50a20b954c7770 100644 --- a/paddle/fluid/operators/squeeze_op.cc +++ b/paddle/fluid/operators/squeeze_op.cc @@ -375,31 +375,25 @@ REGISTER_OPERATOR(squeeze2_grad, REGISTER_OP_CPU_KERNEL( squeeze, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel, - ops::SqueezeKernel>, - ops::SqueezeKernel>, - ops::SqueezeKernel); + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel, + ops::SqueezeKernel>, + ops::SqueezeKernel>, + ops::SqueezeKernel); REGISTER_OP_CPU_KERNEL( squeeze_grad, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel, - ops::SqueezeGradKernel>, - ops::SqueezeGradKernel>, - ops::SqueezeGradKernel); + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel, + ops::SqueezeGradKernel>, + ops::SqueezeGradKernel>, + ops::SqueezeGradKernel); diff --git a/paddle/fluid/operators/stft_op.cc b/paddle/fluid/operators/stft_op.cc index fd064c255f560eaf86a9fd49fbb5634437a899cc..d708abe3d0f8c16414572933e0f3b3b052e159c2 100644 --- a/paddle/fluid/operators/stft_op.cc +++ b/paddle/fluid/operators/stft_op.cc @@ -164,12 +164,10 @@ REGISTER_OPERATOR(stft, REGISTER_OPERATOR(stft_grad, ops::StftGradOp); -REGISTER_OP_CPU_KERNEL( - stft, - ops::StftKernel, - ops::StftKernel); - -REGISTER_OP_CPU_KERNEL( - stft_grad, - ops::StftGradKernel, - ops::StftGradKernel); +REGISTER_OP_CPU_KERNEL(stft, + ops::StftKernel, + ops::StftKernel); + +REGISTER_OP_CPU_KERNEL(stft_grad, + ops::StftGradKernel, + ops::StftGradKernel); diff --git a/paddle/fluid/operators/strided_memcpy_test.cc b/paddle/fluid/operators/strided_memcpy_test.cc index 362be0d5da33d6780be461cab04c5f75a6bd619f..e16df345427958349f59b431b7f0e8b21924dd4c 100644 --- a/paddle/fluid/operators/strided_memcpy_test.cc +++ b/paddle/fluid/operators/strided_memcpy_test.cc @@ -35,7 +35,7 @@ TEST(StridedMemcpy, CPUCrop) { framework::DDim dst_dim({2, 2}); framework::DDim dst_stride({2, 1}); - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; StridedMemcpy(ctx, src + 1, src_stride, dst_dim, dst_stride, dst); ASSERT_EQ(1, dst[0]); @@ -57,7 +57,7 @@ TEST(StridedMemcpy, CPUConcat) { framework::DDim src_stride({2, 1}); framework::DDim dst_dim({2, 2}); framework::DDim dst_stride({4, 1}); - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; StridedMemcpy(ctx, src, src_stride, dst_dim, dst_stride, dst); StridedMemcpy(ctx, src, src_stride, dst_dim, dst_stride, dst + 2); diff --git a/paddle/fluid/operators/sum_op.cc b/paddle/fluid/operators/sum_op.cc index fca510143d0decf58c0d780a1c16d6b2f517020b..ca851b8ee75b1ebd80dcde5c7cf73df81526db6e 100644 --- a/paddle/fluid/operators/sum_op.cc +++ b/paddle/fluid/operators/sum_op.cc @@ -359,9 +359,8 @@ REGISTER_OPERATOR(sum, REGISTER_OP_CPU_KERNEL( sum, - ops::SumKernel, - ops::SumKernel, - ops::SumKernel, - ops::SumKernel, - ops::SumKernel); + ops::SumKernel, + ops::SumKernel, + ops::SumKernel, + ops::SumKernel, + ops::SumKernel); diff --git a/paddle/fluid/operators/svd_op.cc b/paddle/fluid/operators/svd_op.cc index 4186068cd6e409fcff91d181c927ed02036bb7ed..7ae85343e04723fb86223694041eca951bf87e3d 100644 --- a/paddle/fluid/operators/svd_op.cc +++ b/paddle/fluid/operators/svd_op.cc @@ -172,7 +172,6 @@ REGISTER_OP_CPU_KERNEL(svd, ops::SvdCPUKernel, ops::SvdCPUKernel); -REGISTER_OP_CPU_KERNEL( - svd_grad, - ops::SvdGradKernel, - ops::SvdGradKernel); +REGISTER_OP_CPU_KERNEL(svd_grad, + ops::SvdGradKernel, + ops::SvdGradKernel); diff --git a/paddle/fluid/operators/svd_op.h b/paddle/fluid/operators/svd_op.h index 7b98dc21d07bb3d19657a2dbd90abcf68bbc5600..b7d3b7d3e5ae0f39b13852f90535fe55da6514f3 100644 --- a/paddle/fluid/operators/svd_op.h +++ b/paddle/fluid/operators/svd_op.h @@ -40,10 +40,10 @@ class SvdCPUKernel : public framework::OpKernel { /*Create Tensors and output, set the dim ...*/ auto numel = x->numel(); - auto& orig_dev_ctx = - context.template device_context(); - auto& dev_ctx = static_cast::TYPE&>(orig_dev_ctx); + auto& orig_dev_ctx = context.template device_context(); + auto& dev_ctx = static_cast< + const typename framework::ConvertToPhiContext::TYPE&>( + orig_dev_ctx); Tensor trans_x = ::phi::TransposeLast2Dim(dev_ctx, *x); auto* x_data = trans_x.data(); auto x_dims = x->dims(); diff --git a/paddle/fluid/operators/test_leaky_relu_grad_grad_functor.h b/paddle/fluid/operators/test_leaky_relu_grad_grad_functor.h index cd0842e4a47bf1e9cba1099b672181075b1445e6..6df883e83337fd2cd0a0595453617ff7bb395b92 100644 --- a/paddle/fluid/operators/test_leaky_relu_grad_grad_functor.h +++ b/paddle/fluid/operators/test_leaky_relu_grad_grad_functor.h @@ -103,10 +103,9 @@ static bool TestLeakyReluGradGradMain(const framework::DDim &dim, for_range(actual_functor); } else { #endif - auto &cpu_dev_ctx = dynamic_cast(dev_ctx); + auto &cpu_dev_ctx = dynamic_cast(dev_ctx); functor(cpu_dev_ctx, &x, out, &ddx, &ddout, dout, dx); - platform::ForRange for_range(cpu_dev_ctx, - limit); + platform::ForRange for_range(cpu_dev_ctx, limit); for_range(actual_functor); #if defined(__NVCC__) || defined(__HIPCC__) } diff --git a/paddle/fluid/operators/tree_conv_op.cc b/paddle/fluid/operators/tree_conv_op.cc index f62e1d3072fa3e6079ab070f12f34b5de06c4ee8..525dd17c39bb9b8bec05416af824d55e642417c1 100644 --- a/paddle/fluid/operators/tree_conv_op.cc +++ b/paddle/fluid/operators/tree_conv_op.cc @@ -234,12 +234,10 @@ REGISTER_OPERATOR(tree_conv, REGISTER_OPERATOR(tree_conv_grad, ops::TreeConvGradOp); -REGISTER_OP_CPU_KERNEL( - tree_conv, - ops::TreeConvKernel, - ops::TreeConvKernel); - -REGISTER_OP_CPU_KERNEL( - tree_conv_grad, - ops::TreeConvGradKernel, - ops::TreeConvGradKernel); +REGISTER_OP_CPU_KERNEL(tree_conv, + ops::TreeConvKernel, + ops::TreeConvKernel); + +REGISTER_OP_CPU_KERNEL(tree_conv_grad, + ops::TreeConvGradKernel, + ops::TreeConvGradKernel); diff --git a/paddle/fluid/operators/unique_consecutive_op.cc b/paddle/fluid/operators/unique_consecutive_op.cc index e9c6a4edb66c5220b7a7287a3dbf9bfb9fb3dc2b..73f6918d52598fd4c0d082919a6115cb0d948731 100644 --- a/paddle/fluid/operators/unique_consecutive_op.cc +++ b/paddle/fluid/operators/unique_consecutive_op.cc @@ -118,12 +118,11 @@ namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(unique_consecutive, ops::UniqueConsecutiveOp, ops::UniqueConsecutiveOpMaker); -REGISTER_OP_CPU_KERNEL( - unique_consecutive, - ops::UniqueConsecutiveKernel, - ops::UniqueConsecutiveKernel, - ops::UniqueConsecutiveKernel, - ops::UniqueConsecutiveKernel); +REGISTER_OP_CPU_KERNEL(unique_consecutive, + ops::UniqueConsecutiveKernel, + ops::UniqueConsecutiveKernel, + ops::UniqueConsecutiveKernel, + ops::UniqueConsecutiveKernel); REGISTER_OP_VERSION(unique_consecutive) .AddCheckpoint( R"ROC( diff --git a/paddle/fluid/operators/unpool_op.cc b/paddle/fluid/operators/unpool_op.cc index 82e6b734aa009b5c7581bfad09e5042a22401203..47679ca57f5bfdf4c4fa0c33b7f16bc426a16d9c 100644 --- a/paddle/fluid/operators/unpool_op.cc +++ b/paddle/fluid/operators/unpool_op.cc @@ -328,14 +328,12 @@ REGISTER_OPERATOR(unpool, ops::UnpoolOpGradMaker); REGISTER_OPERATOR(unpool_grad, ops::UnpoolOpGrad); -REGISTER_OP_CPU_KERNEL( - unpool, - ops::UnpoolKernel, - ops::UnpoolKernel); -REGISTER_OP_CPU_KERNEL( - unpool_grad, - ops::UnpoolGradKernel, - ops::UnpoolGradKernel); +REGISTER_OP_CPU_KERNEL(unpool, + ops::UnpoolKernel, + ops::UnpoolKernel); +REGISTER_OP_CPU_KERNEL(unpool_grad, + ops::UnpoolGradKernel, + ops::UnpoolGradKernel); REGISTER_OPERATOR(unpool3d, ops::Unpool3dOp, @@ -344,11 +342,9 @@ REGISTER_OPERATOR(unpool3d, ops::Unpool3dOpGradMaker); REGISTER_OPERATOR(unpool3d_grad, ops::Unpool3dOpGrad); -REGISTER_OP_CPU_KERNEL( - unpool3d, - ops::Unpool3dKernel, - ops::Unpool3dKernel); -REGISTER_OP_CPU_KERNEL( - unpool3d_grad, - ops::Unpool3dGradKernel, - ops::Unpool3dGradKernel); +REGISTER_OP_CPU_KERNEL(unpool3d, + ops::Unpool3dKernel, + ops::Unpool3dKernel); +REGISTER_OP_CPU_KERNEL(unpool3d_grad, + ops::Unpool3dGradKernel, + ops::Unpool3dGradKernel); diff --git a/paddle/fluid/operators/unsqueeze_op.cc b/paddle/fluid/operators/unsqueeze_op.cc index 18a1d5435e014c978ec9edf6617054977072a878..53de6440f1f613dfcf7f7c0e325fe53009befba1 100644 --- a/paddle/fluid/operators/unsqueeze_op.cc +++ b/paddle/fluid/operators/unsqueeze_op.cc @@ -378,33 +378,28 @@ REGISTER_OPERATOR(unsqueeze2_grad, REGISTER_OP_CPU_KERNEL( unsqueeze, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel, - ops::UnsqueezeKernel>, - ops::UnsqueezeKernel>, - ops::UnsqueezeKernel); + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel, + ops::UnsqueezeKernel>, + ops::UnsqueezeKernel>, + ops::UnsqueezeKernel); REGISTER_OP_CPU_KERNEL( unsqueeze_grad, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel, - ops::UnsqueezeGradKernel>, - ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel, + ops::UnsqueezeGradKernel>, + ops::UnsqueezeGradKernel>, - ops::UnsqueezeGradKernel); + ops::UnsqueezeGradKernel); diff --git a/paddle/fluid/operators/var_conv_2d_op.cc b/paddle/fluid/operators/var_conv_2d_op.cc index d46d2bd8473414fffab953ea643154c56ab95ca4..53feefef3e1cc640da8bdaa4cad536cf0c4a2eb9 100644 --- a/paddle/fluid/operators/var_conv_2d_op.cc +++ b/paddle/fluid/operators/var_conv_2d_op.cc @@ -321,7 +321,7 @@ class CPUVarConv2dOPKernel : public framework::OpKernel { auto* w_data = w->data(); auto* col_data = col->data(); - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); for (int b = 0; b < batch; ++b) { int top_im_size = (top_offset[b + 1] - top_offset[b]) / output_channel; if (top_im_size == 0) { @@ -479,7 +479,7 @@ class CPUVarConv2dOPGradKernel : public framework::OpKernel { int batch = x->lod()[0].size() - 1; const auto& top_offset = out->lod()[0]; const auto& col_offset = col->lod()[0]; - auto blas = phi::funcs::GetBlas(ctx); + auto blas = phi::funcs::GetBlas(ctx); for (int b = 0; b < batch; ++b) { int top_im_size = (top_offset[b + 1] - top_offset[b]) / output_channel; if (top_im_size == 0) { @@ -526,11 +526,10 @@ REGISTER_OPERATOR(var_conv_2d, REGISTER_OPERATOR(var_conv_2d_grad, ops::VarConv2dOpGrad); REGISTER_OP_CPU_KERNEL(var_conv_2d, - ops::CPUVarConv2dOPKernel); -// ops::CPUVarConv2dOPKernel); +// ops::CPUVarConv2dOPKernel -REGISTER_OP_CPU_KERNEL( - var_conv_2d_grad, - ops::CPUVarConv2dOPGradKernel); -// ops::CPUVarConv2dOPGradKernel); +// ops::CPUVarConv2dOPGradKernel diff --git a/paddle/fluid/platform/device/npu/npu_op_runner.cc b/paddle/fluid/platform/device/npu/npu_op_runner.cc index e6a847758bdeec0d4e0fe8e2e60de801162262c4..99828a425517b01927d217e9ab125265c436e081 100644 --- a/paddle/fluid/platform/device/npu/npu_op_runner.cc +++ b/paddle/fluid/platform/device/npu/npu_op_runner.cc @@ -233,7 +233,7 @@ NpuOpRunner &NpuOpRunner::AddInput(const Tensor &tensor, aclMemType mem_type) { NpuOpRunner &NpuOpRunner::AddInput(std::vector &&dims) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); auto *dev_ctx = - static_cast(pool.Get(platform::CPUPlace())); + static_cast(pool.Get(platform::CPUPlace())); Tensor host_tensor; paddle::framework::TensorFromVector(dims, *dev_ctx, &host_tensor); host_tensors_.emplace_back(host_tensor); @@ -249,7 +249,7 @@ NpuOpRunner &NpuOpRunner::AddInput(std::vector &&dims) { NpuOpRunner &NpuOpRunner::AddInput(std::vector &&dims) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); auto *dev_ctx = - static_cast(pool.Get(platform::CPUPlace())); + static_cast(pool.Get(platform::CPUPlace())); Tensor host_tensor; paddle::framework::TensorFromVector(dims, *dev_ctx, &host_tensor); host_tensors_.emplace_back(host_tensor); @@ -265,7 +265,7 @@ NpuOpRunner &NpuOpRunner::AddInput(std::vector &&dims) { NpuOpRunner &NpuOpRunner::AddInput(std::vector &&values) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); auto *dev_ctx = - static_cast(pool.Get(platform::CPUPlace())); + static_cast(pool.Get(platform::CPUPlace())); Tensor host_tensor; paddle::framework::TensorFromVector(values, *dev_ctx, &host_tensor); host_tensors_.emplace_back(host_tensor); @@ -281,7 +281,7 @@ NpuOpRunner &NpuOpRunner::AddInput(std::vector &&values) { NpuOpRunner &NpuOpRunner::AddInput(std::vector &&values) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); auto *dev_ctx = - static_cast(pool.Get(platform::CPUPlace())); + static_cast(pool.Get(platform::CPUPlace())); Tensor host_tensor; paddle::framework::TensorFromVector(values, *dev_ctx, &host_tensor); host_tensors_.emplace_back(host_tensor); diff --git a/paddle/fluid/platform/device_context.cc b/paddle/fluid/platform/device_context.cc index ec7f46cd973d41a225157ec5a5db489cfe26a400..4dfeca3bd13254bf905a0510566ffceb2bfa7f66 100644 --- a/paddle/fluid/platform/device_context.cc +++ b/paddle/fluid/platform/device_context.cc @@ -261,7 +261,7 @@ void EmplaceDeviceContexts( p, disable_setting_default_stream_for_allocator); #else - EmplaceDeviceContext( + EmplaceDeviceContext( place_to_device_context, p, disable_setting_default_stream_for_allocator); @@ -751,7 +751,7 @@ const Place& CUDAPinnedDeviceContext::GetPlace() const { return place_; } #ifdef PADDLE_WITH_MKLDNN MKLDNNDeviceContext::MKLDNNDeviceContext(CPUPlace place) - : CPUDeviceContext(place), p_blobmap_() { + : phi::CPUContext(place), p_blobmap_() { p_blobmap_.reset(new BlobMap()); p_exec_items_.reset(new ExecShape()); p_mutex_.reset(new std::mutex()); diff --git a/paddle/fluid/platform/device_context.h b/paddle/fluid/platform/device_context.h index 2c3bc017635dd2872e9e46cc929a1524a2d9448e..1b7aafdac6f29947ab41c140bb4f4521aa54266f 100644 --- a/paddle/fluid/platform/device_context.h +++ b/paddle/fluid/platform/device_context.h @@ -133,7 +133,6 @@ constexpr DeviceType kIPU = DeviceType::IPU; constexpr DeviceType kMLU = DeviceType::MLU; using DeviceContext = phi::DeviceContext; - using CPUDeviceContext = phi::CPUContext; template @@ -141,7 +140,7 @@ struct DefaultDeviceContextType; template <> struct DefaultDeviceContextType { - using TYPE = CPUDeviceContext; + using TYPE = phi::CPUContext; }; // Graphcore IPU @@ -776,7 +775,7 @@ class MKLDNNDeviceContextThreadLocals { } }; -class MKLDNNDeviceContext : public CPUDeviceContext { +class MKLDNNDeviceContext : public phi::CPUContext { public: template using BlobPtr_t = std::shared_ptr; diff --git a/paddle/fluid/platform/transform_test.cu b/paddle/fluid/platform/transform_test.cu index 1caa2e87707722ad1396371e482c68872c974b39..5e0717ba635cedb6878beec347668599846afe5d 100644 --- a/paddle/fluid/platform/transform_test.cu +++ b/paddle/fluid/platform/transform_test.cu @@ -39,17 +39,17 @@ class Multiply { using paddle::memory::Alloc; using paddle::memory::Copy; -using paddle::platform::CPUDeviceContext; using paddle::platform::CPUPlace; using paddle::platform::CUDADeviceContext; using paddle::platform::CUDAPlace; +using phi::CPUContext; using paddle::platform::Transform; TEST(Transform, CPUUnary) { - CPUDeviceContext ctx; + CPUContext ctx; float buf[4] = {0.1, 0.2, 0.3, 0.4}; - Transform trans; + Transform trans; trans(ctx, buf, buf + 4, buf, Scale(10)); for (int i = 0; i < 4; ++i) { ASSERT_NEAR(buf[i], static_cast(i + 1), 1e-5); @@ -78,8 +78,8 @@ TEST(Transform, GPUUnary) { TEST(Transform, CPUBinary) { int buf[4] = {1, 2, 3, 4}; - Transform trans; - CPUDeviceContext ctx; + Transform trans; + phi::CPUContext ctx; trans(ctx, buf, buf + 4, buf, buf, Multiply()); for (int i = 0; i < 4; ++i) { ASSERT_EQ((i + 1) * (i + 1), buf[i]); diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 7b7e9d1a6c9edefc02a3e006c762f35429c1710b..3723e58e52902c7bfd655fec3ebfe388b4e3d5b2 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -2089,7 +2089,7 @@ All parameter, weight, gradient are variables in Paddle. .def_static("create", [](paddle::platform::CPUPlace& place) -> paddle::platform::DeviceContext* { - auto* context = new paddle::platform::CPUDeviceContext(); + auto* context = new phi::CPUContext(); context->SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() .GetAllocator(place) diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index bba8526abd7f97672c17924099e3ca0f55e6eda1..ccec0c060a3a47330fa78e22afd8ec35459931e2 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -676,7 +676,7 @@ void SetUVATensorFromPyArray( template void _sliceCompute(const framework::Tensor *in, framework::Tensor *out, - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, const std::vector &axes, const std::vector &starts) { auto &eigen_place = *ctx.eigen_device(); @@ -711,7 +711,7 @@ void _sliceCompute(const framework::Tensor *in, template void _concatCompute(const std::vector &ins, paddle::framework::Tensor *out, - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, int64_t axis) { if (axis == 0 && ins.size() < 10) { size_t output_offset = 0; @@ -729,8 +729,7 @@ void _concatCompute(const std::vector &ins, output_offset += in_stride[axis]; } } else { - paddle::operators::math::ConcatFunctor - concat_functor; + paddle::operators::math::ConcatFunctor concat_functor; concat_functor(ctx, ins, static_cast(axis), out); } } @@ -817,7 +816,7 @@ inline framework::Tensor *_getTensor(const framework::Tensor &self, template void _sliceDapper(const framework::Tensor *in, framework::Tensor *out, - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, const std::vector &axes, const std::vector &starts, int size) { @@ -858,7 +857,7 @@ void _sliceDapper(const framework::Tensor *in, template inline framework::Tensor *_sliceWrapper(const framework::Tensor &self, - const platform::CPUDeviceContext &ctx, + const phi::CPUContext &ctx, py::object obj, int dim, int64_t start, @@ -876,7 +875,7 @@ template inline framework::Tensor *_sliceAndConcat(const framework::Tensor &self, py::object obj, int dim) { - platform::CPUDeviceContext ctx; + phi::CPUContext ctx; int64_t start, stop, step, slicelength; _getSliceinfo(self, obj, dim, &start, &stop, &step, &slicelength); if (step == 1 || slicelength == 1) { diff --git a/paddle/phi/kernels/funcs/gru_compute.cc b/paddle/phi/kernels/funcs/gru_compute.cc index c081a9ed97d1ffc1148fe7f3d4474fac5e0ab231..f0c946134906b0e04596f04affc21b41c59c00bd 100644 --- a/paddle/phi/kernels/funcs/gru_compute.cc +++ b/paddle/phi/kernels/funcs/gru_compute.cc @@ -19,8 +19,8 @@ namespace phi { namespace funcs { template -struct GRUUnitFunctor { - static void compute(const paddle::platform::CPUDeviceContext &context, +struct GRUUnitFunctor { + static void compute(const phi::CPUContext &context, GRUMetaValue value, int frame_size, int batch_size, @@ -28,8 +28,7 @@ struct GRUUnitFunctor { const phi::funcs::detail::ActivationType active_gate, bool origin_mode) { #if !defined(__NVCC__) && !defined(__HIPCC___) - auto blas = - phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (value.prev_out_value) { blas.GEMM(false, false, @@ -46,7 +45,7 @@ struct GRUUnitFunctor { frame_size * 3); } - detail::forward_reset_output( + detail::forward_reset_output( phi::funcs::detail::forward::gru_resetOutput(), value, frame_size, @@ -71,7 +70,7 @@ struct GRUUnitFunctor { frame_size * 3); } - detail::forward_final_output( + detail::forward_final_output( phi::funcs::detail::forward::gru_finalOutput(), value, frame_size, @@ -85,8 +84,8 @@ struct GRUUnitFunctor { }; template -struct GRUUnitGradFunctor { - static void compute(const paddle::platform::CPUDeviceContext &context, +struct GRUUnitGradFunctor { + static void compute(const phi::CPUContext &context, GRUMetaValue value, GRUMetaGrad grad, int frame_size, @@ -103,8 +102,7 @@ struct GRUUnitGradFunctor { batch_size, active_node, origin_mode); - auto blas = - phi::funcs::GetBlas(context); + auto blas = phi::funcs::GetBlas(context); if (value.prev_out_value && grad.prev_out_grad) { blas.GEMM(false, true, @@ -356,10 +354,10 @@ struct GRUUnitGradFunctorV2 { } }; -template struct GRUUnitFunctor; -template struct GRUUnitFunctor; -template struct GRUUnitGradFunctor; -template struct GRUUnitGradFunctor; +template struct GRUUnitFunctor; +template struct GRUUnitFunctor; +template struct GRUUnitGradFunctor; +template struct GRUUnitGradFunctor; template struct GRUUnitFunctorV2; template struct GRUUnitFunctorV2; diff --git a/paddle/phi/kernels/funcs/math_function.cc b/paddle/phi/kernels/funcs/math_function.cc index 042b333ad451ac17a28189ec07c429fd98176097..61cedb57faf2721b7332065272251ba6e1e18ffd 100644 --- a/paddle/phi/kernels/funcs/math_function.cc +++ b/paddle/phi/kernels/funcs/math_function.cc @@ -257,8 +257,8 @@ template struct RowwiseMean; template struct RowwiseMean; template -struct ElementwiseAddTo { - void operator()(paddle::platform::CPUDeviceContext* ctx, +struct ElementwiseAddTo { + void operator()(phi::CPUContext* ctx, const paddle::framework::Tensor& src, paddle::framework::Tensor* dst) { auto in = paddle::framework::EigenVector::Flatten(src); @@ -268,14 +268,12 @@ struct ElementwiseAddTo { } }; -template struct ElementwiseAddTo; -template struct ElementwiseAddTo; +template struct ElementwiseAddTo; +template struct ElementwiseAddTo; template -struct RowwiseAdd { - void operator()(const paddle::platform::CPUDeviceContext& context, +struct RowwiseAdd { + void operator()(const phi::CPUContext& context, const paddle::framework::Tensor& input, const paddle::framework::Tensor& vector, paddle::framework::Tensor* output) { @@ -312,8 +310,8 @@ struct RowwiseAdd { } }; -template struct RowwiseAdd; -template struct RowwiseAdd; +template struct RowwiseAdd; +template struct RowwiseAdd; } // namespace funcs } // namespace phi diff --git a/paddle/phi/kernels/funcs/math_function_impl.h b/paddle/phi/kernels/funcs/math_function_impl.h index 7c337e6c0dba93d7bcd94b1d97abd861b706f9a6..f9055fb56c913bbff413bcff8ad8c80afb155d45 100644 --- a/paddle/phi/kernels/funcs/math_function_impl.h +++ b/paddle/phi/kernels/funcs/math_function_impl.h @@ -92,9 +92,9 @@ void ColwiseSum::operator()( // colwise-sum can be easily implemented. General reduce has a huge overhead in // CPU template -class ColwiseSum { +class ColwiseSum { public: - void operator()(const paddle::platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const paddle::framework::Tensor& input, paddle::framework::Tensor* out) { auto& in_dims = input.dims(); @@ -155,9 +155,9 @@ void RowwiseMean::operator()( // rowwise-sum can be easily implemented. General reduce has a huge overhead in // CPU template -class RowwiseMean { +class RowwiseMean { public: - void operator()(const paddle::platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const paddle::framework::Tensor& input, paddle::framework::Tensor* out) { auto& in_dims = input.dims(); @@ -222,9 +222,9 @@ void RowwiseSum::operator()( // rowwise-sum can be easily implemented. General reduce has a huge overhead in // CPU template -class RowwiseSum { +class RowwiseSum { public: - void operator()(const paddle::platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const paddle::framework::Tensor& input, paddle::framework::Tensor* out) { auto& in_dims = input.dims(); diff --git a/paddle/phi/kernels/funcs/sequence2batch.cc b/paddle/phi/kernels/funcs/sequence2batch.cc index 0d75ba877db5e361b75d336bdd0885555fc2eacf..7cad5b6c0b929ca33a8829b50d938593498d243d 100644 --- a/paddle/phi/kernels/funcs/sequence2batch.cc +++ b/paddle/phi/kernels/funcs/sequence2batch.cc @@ -18,9 +18,9 @@ namespace phi { namespace funcs { template -class CopyMatrixRowsFunctor { +class CopyMatrixRowsFunctor { public: - void operator()(const paddle::platform::CPUDeviceContext& context, + void operator()(const phi::CPUContext& context, const paddle::framework::Tensor& src, paddle::framework::Vector index_lod, paddle::framework::Tensor* dst, @@ -68,18 +68,13 @@ class CopyMatrixRowsFunctor { } }; -template class CopyMatrixRowsFunctor; -template class CopyMatrixRowsFunctor; +template class CopyMatrixRowsFunctor; +template class CopyMatrixRowsFunctor; -template class LoDTensor2BatchFunctor; -template class LoDTensor2BatchFunctor; -template class Batch2LoDTensorFunctor; -template class Batch2LoDTensorFunctor; +template class LoDTensor2BatchFunctor; +template class LoDTensor2BatchFunctor; +template class Batch2LoDTensorFunctor; +template class Batch2LoDTensorFunctor; } // namespace funcs } // namespace phi diff --git a/paddle/phi/tests/common/test_scalar.cu b/paddle/phi/tests/common/test_scalar.cu index 95334ac36a608a7d146b7c524441c0e519ed8592..e985f1c417de3d7d792e08c3a55e63b948a6bd4b 100644 --- a/paddle/phi/tests/common/test_scalar.cu +++ b/paddle/phi/tests/common/test_scalar.cu @@ -164,6 +164,7 @@ TEST(Scalar, ConstructFromDenseTensor7) { .GetAllocator(phi::GPUPlace()) .get()); dev_ctx.Init(); + auto* dense_x_data = dev_ctx.Alloc(&dense_x); FillTensor<<<1, 1, 0, dev_ctx.stream()>>>(dense_x_data); dev_ctx.Wait(); diff --git a/paddle/phi/tests/kernels/test_math_function.cc b/paddle/phi/tests/kernels/test_math_function.cc index a13a8cb564f94ed7cb1dde051ed09ddb1aa3bd50..b21cf0203febe3edc99e13e82c809a25def285a2 100644 --- a/paddle/phi/tests/kernels/test_math_function.cc +++ b/paddle/phi/tests/kernels/test_math_function.cc @@ -20,9 +20,9 @@ namespace phi { namespace tests { template -inline phi::funcs::BlasT GetBlas( - const paddle::platform::CPUDeviceContext& context) { - return phi::funcs::GetBlas(context); +inline phi::funcs::BlasT GetBlas( + const phi::CPUContext& context) { + return phi::funcs::GetBlas(context); } TEST(math_function, gemm_notrans_cblas) { @@ -44,7 +44,7 @@ TEST(math_function, gemm_notrans_cblas) { float arr3[8] = {0, 1, 2, 3, 4, 5, 6, 7}; memcpy(input3_ptr, arr3, 8 * sizeof(float)); - paddle::platform::CPUDeviceContext context(*cpu_place); + phi::CPUContext context(*cpu_place); GetBlas(context).GEMM(false, false, m, @@ -165,7 +165,7 @@ TEST(math_function, gemm_trans_cblas) { float arr3[8] = {0, 1, 2, 3, 4, 5, 6, 7}; memcpy(input3_ptr, arr3, 8 * sizeof(float)); - paddle::platform::CPUDeviceContext context(*cpu_place); + phi::CPUContext context(*cpu_place); GetBlas(context).GEMM(false, true, m, @@ -196,8 +196,8 @@ TEST(math_function, zero) { paddle::framework::Tensor tensor; auto* cpu_place = new paddle::platform::CPUPlace(); float* t = tensor.mutable_data({2, 2}, *cpu_place); - paddle::platform::CPUDeviceContext context(*cpu_place); - phi::funcs::SetConstant functor; + phi::CPUContext context(*cpu_place); + phi::funcs::SetConstant functor; functor(context, &tensor, 0); EXPECT_EQ(t[0], 0); EXPECT_EQ(t[1], 0); @@ -231,7 +231,7 @@ void GemvTest(int m, int n, bool trans) { data_b[i] = static_cast(i); } - paddle::platform::CPUDeviceContext context(*cpu_place); + phi::CPUContext context(*cpu_place); GetBlas(context).GEMV(trans, static_cast(m), static_cast(n), @@ -272,7 +272,7 @@ TEST(math_funciton, set_constant) { paddle::framework::Tensor t; t.Resize({10, 10}); t.mutable_data(paddle::platform::CPUPlace()); - auto* ctx = new paddle::platform::CPUDeviceContext(); + auto* ctx = new phi::CPUContext(); phi::funcs::set_constant(*ctx, &t, 10); for (int64_t i = 0; i < t.numel(); ++i) { PADDLE_ENFORCE_EQ(10, @@ -311,7 +311,7 @@ void GemmWarpTest(int m, int n, int k, T alpha, T beta) { } // this would call gemm_warp - paddle::platform::CPUDeviceContext context(*cpu_place); + phi::CPUContext context(*cpu_place); GetBlas(context).GEMM( CblasNoTrans, CblasNoTrans, m, n, k, alpha, A, B, beta, CREF); diff --git a/python/paddle/fluid/tests/custom_op/custom_raw_op_kernel_op.h b/python/paddle/fluid/tests/custom_op/custom_raw_op_kernel_op.h index 9cec48f9c99b5cb400d3316eb465f95e4a402828..ffe89fde0470e95ad3b376cf4619e4598ee6d183 100644 --- a/python/paddle/fluid/tests/custom_op/custom_raw_op_kernel_op.h +++ b/python/paddle/fluid/tests/custom_op/custom_raw_op_kernel_op.h @@ -66,7 +66,7 @@ struct ReluFunctor { return; } #endif - LAUNCH_RELU_KERNEL(paddle::platform::CPUDeviceContext); + LAUNCH_RELU_KERNEL(phi::CPUContext); #undef LAUNCH_RELU_KERNEL }