From 942ff89f62b0eb94ba4f85648a9fd79e06249a9a Mon Sep 17 00:00:00 2001 From: Weilong Wu Date: Tue, 2 Aug 2022 15:27:18 +0800 Subject: [PATCH] [Phi] polish and rename, pt* -> phi* (#44697) * polish and rename, pt* -> phi* * fix code format --- .../framework/new_executor/interpretercore.cc | 6 +- .../new_executor/interpretercore_util.cc | 24 +- .../new_executor/new_executor_defs.cc | 4 +- .../new_executor/new_executor_defs.h | 2 +- paddle/fluid/framework/operator.cc | 201 ++-- paddle/fluid/framework/operator.h | 8 +- paddle/fluid/imperative/op_base.h | 2 +- paddle/fluid/imperative/prepared_operator.cc | 53 +- paddle/phi/capi/include/kernel_utils.h | 498 +++++----- paddle/phi/core/kernel_registry.h | 886 +++++++++--------- 10 files changed, 844 insertions(+), 840 deletions(-) diff --git a/paddle/fluid/framework/new_executor/interpretercore.cc b/paddle/fluid/framework/new_executor/interpretercore.cc index 1e54df3c73c..1a98b44729f 100644 --- a/paddle/fluid/framework/new_executor/interpretercore.cc +++ b/paddle/fluid/framework/new_executor/interpretercore.cc @@ -621,13 +621,13 @@ void InterpreterCore::RunInstruction(const Instruction& instr_node) { VLOG(4) << "Run phi kernel: " << op->Type(); VLOG(4) << instr_node.InnerRuntimeContext().get() << " " << &instr_node.DeviceContext(); - phi::KernelContext pt_kernel_context; + phi::KernelContext phi_kernel_context; op_with_kernel->BuildPhiKernelContext( *instr_node.InnerRuntimeContext().get(), const_cast(&instr_node.DeviceContext()), - &pt_kernel_context); + &phi_kernel_context); - (*instr_node.PhiKernel())(&pt_kernel_context); + (*instr_node.PhiKernel())(&phi_kernel_context); } else { instr_node.KernelFunc()(*instr_node.InnerExecutionContext().get()); diff --git a/paddle/fluid/framework/new_executor/interpretercore_util.cc b/paddle/fluid/framework/new_executor/interpretercore_util.cc index f1ef875e4db..055a765af11 100644 --- a/paddle/fluid/framework/new_executor/interpretercore_util.cc +++ b/paddle/fluid/framework/new_executor/interpretercore_util.cc @@ -513,25 +513,25 @@ void build_op_func_list(const platform::Place& place, auto run_phi_kernel = false; if (phi::KernelFactory::Instance().HasCompatiblePhiKernel( op_with_kernel->Type())) { - auto pt_kernel_key = op_with_kernel->ChoosePhiKernel(exec_ctx); - auto pt_kernel_name = op_with_kernel->PhiKernelSignature()->name; + auto phi_kernel_key = op_with_kernel->ChoosePhiKernel(exec_ctx); + auto phi_kernel_name = op_with_kernel->PhiKernelSignature()->name; if (op_with_kernel->PhiKernel()->IsValid()) { run_phi_kernel = true; } else { if (!op_with_kernel->SupportsKernelType(expected_kernel_key)) { - auto pt_cpu_kernel_key = FallBackToCpu( - expected_kernel_key, pt_kernel_key, *op_with_kernel); + auto phi_cpu_kernel_key = FallBackToCpu( + expected_kernel_key, phi_kernel_key, *op_with_kernel); op_with_kernel->ResetPhiKernel( new phi::Kernel(phi::KernelFactory::Instance().SelectKernel( - pt_kernel_name, pt_cpu_kernel_key))); + phi_kernel_name, phi_cpu_kernel_key))); if (op_with_kernel->PhiKernel()->IsValid()) { VLOG(6) << "Static mode PrepareImpl - kernel name: " - << pt_kernel_name - << " | kernel key: " << pt_cpu_kernel_key + << phi_kernel_name + << " | kernel key: " << phi_cpu_kernel_key << " | kernel: " << *(op_with_kernel->PhiKernel()); op_with_kernel->ResetKernelType(new OpKernelType( - TransPhiKernelKeyToOpKernelType(pt_cpu_kernel_key))); + TransPhiKernelKeyToOpKernelType(phi_cpu_kernel_key))); run_phi_kernel = true; } } @@ -541,7 +541,7 @@ void build_op_func_list(const platform::Place& place, op_with_kernel->ChooseKernel(exec_ctx); op_func_node.kernel_func_ = *op_with_kernel->kernel_func(); } else { - op_func_node.pt_kernel_ = op_with_kernel->PhiKernel(); + op_func_node.phi_kernel_ = op_with_kernel->PhiKernel(); } auto kernel_type = *(op_with_kernel->kernel_type()); if (kernel_type.place_ != dev_ctx->GetPlace()) { @@ -583,10 +583,10 @@ void build_op_func_list(const platform::Place& place, // step 5. run kernel if (run_phi_kernel) { - phi::KernelContext pt_kernel_context; + phi::KernelContext phi_kernel_context; op_with_kernel->BuildPhiKernelContext( - runtime_context, dev_ctx, &pt_kernel_context); - (*op_func_node.pt_kernel_)(&pt_kernel_context); + runtime_context, dev_ctx, &phi_kernel_context); + (*op_func_node.phi_kernel_)(&phi_kernel_context); } else { // the place of exec_ctx maybe has changed. op_func_node.kernel_func_(ExecutionContext( diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.cc b/paddle/fluid/framework/new_executor/new_executor_defs.cc index 128656b275f..f2e39def069 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.cc +++ b/paddle/fluid/framework/new_executor/new_executor_defs.cc @@ -705,7 +705,9 @@ OpKernelComputeFunc Instruction::KernelFunc() const { return op_func_node_.kernel_func_; } -phi::Kernel* Instruction::PhiKernel() const { return op_func_node_.pt_kernel_; } +phi::Kernel* Instruction::PhiKernel() const { + return op_func_node_.phi_kernel_; +} OpFuncType Instruction::KernelType() const { return op_func_node_.type_; } diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.h b/paddle/fluid/framework/new_executor/new_executor_defs.h index 31e27a07c66..711bef3743d 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.h +++ b/paddle/fluid/framework/new_executor/new_executor_defs.h @@ -283,7 +283,7 @@ struct OpFuncNode { platform::DeviceContext* dev_ctx_; // not owned // fit for phi kernel - phi::Kernel* pt_kernel_{nullptr}; // not owned + phi::Kernel* phi_kernel_{nullptr}; // not owned OpFuncType type_; }; diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index fb8dbe603c3..6c85cee0b04 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -1421,7 +1421,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, !need_prepare_phi_data_) { if (!all_kernels_must_compute_runtime_shape_) this->Info().infer_shape_(impl_->getRuntimeInferShapeContext()); - (*pt_kernel_)(impl_->getKernelContext()); + (*phi_kernel_)(impl_->getKernelContext()); } else { if (runtime_ctx_.get() == nullptr || pre_scope_ != cur_scope) { std::lock_guard lock(cache_update_mutex_); @@ -1467,10 +1467,10 @@ void OperatorWithKernel::RunImpl(const Scope& scope, // TODO(chenweihang): in the first phase of project, we only support CPU, CUDA // and RCOM backend, the XPU, NPU and MKLDNN will be supported in the second // phase - phi::KernelKey pt_kernel_key; - std::string pt_kernel_name; + phi::KernelKey phi_kernel_key; + std::string phi_kernel_name; if (phi::KernelFactory::Instance().HasCompatiblePhiKernel(type_)) { - if (kernel_signature_ == nullptr || pt_kernel_ == nullptr) { + if (kernel_signature_ == nullptr || phi_kernel_ == nullptr) { kernel_signature_.reset(new phi::KernelSignature( std::move(GetExpectedPhiKernelArgs(exe_ctx)))); VLOG(6) << *kernel_signature_.get(); @@ -1479,7 +1479,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, new OpKernelType(std::move(InnerGetExpectedKernelType(exe_ctx)))); dev_ctx = pool.Get(kernel_type_->place_); - pt_kernel_name = kernel_signature_->name; + phi_kernel_name = kernel_signature_->name; // NOTE(Liu-xiandong): The register kernel used KP have library_type[KP], // But the default library_type is Plain, so we need to modify the // library_type here, otherwise it can't work. @@ -1502,38 +1502,38 @@ void OperatorWithKernel::RunImpl(const Scope& scope, auto expected_kernel_key_library_type = kernel_type_->library_type_; kernel_type_->library_type_ = LibraryType::kKP; VLOG(3) << "modifing XPU KP kernel in static graph: " - << pt_kernel_name + << phi_kernel_name << ", using_kernel_key:" << *kernel_type_.get(); - auto try_pt_kernel_key = + auto try_phi_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); - if (!phi::KernelFactory::Instance().HasKernel(pt_kernel_name, - try_pt_kernel_key)) { + if (!phi::KernelFactory::Instance().HasKernel(phi_kernel_name, + try_phi_kernel_key)) { kernel_type_->library_type_ = expected_kernel_key_library_type; VLOG(3) << "modify XPU KP kernel in static graph: " - << pt_kernel_name << " is failed " << *kernel_type_.get(); + << phi_kernel_name << " is failed " << *kernel_type_.get(); } else { use_phi_xpu_kp = true; VLOG(3) << "modify XPU KP kernel in static graph: " - << pt_kernel_name << " is succeed " << *kernel_type_.get(); + << phi_kernel_name << " is succeed " << *kernel_type_.get(); } } } #endif - pt_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); - pt_kernel_.reset( + phi_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); + phi_kernel_.reset( new phi::Kernel(phi::KernelFactory::Instance().SelectKernel( - pt_kernel_name, pt_kernel_key))); + phi_kernel_name, phi_kernel_key))); - if (pt_kernel_->IsValid()) { + if (phi_kernel_->IsValid()) { VLOG(6) << "Static mode ChoosePhiKernel - kernel name: " - << pt_kernel_name << " | kernel key: " << pt_kernel_key - << " | kernel: " << *pt_kernel_; + << phi_kernel_name << " | kernel key: " << phi_kernel_key + << " | kernel: " << *phi_kernel_; } else { - VLOG(6) << "Static mode ChoosePhiKernel - kernel `" << pt_kernel_name + VLOG(6) << "Static mode ChoosePhiKernel - kernel `" << phi_kernel_name << "` not found."; } } else { - pt_kernel_name = kernel_signature_->name; + phi_kernel_name = kernel_signature_->name; // NOTE(Liu-xiandong):In my ctest, this branch do not be executed, // I can't understand it, it's really confusing. // But we still need to keep this to avoid errors. @@ -1556,24 +1556,24 @@ void OperatorWithKernel::RunImpl(const Scope& scope, auto expected_kernel_key_library_type = kernel_type_->library_type_; kernel_type_->library_type_ = LibraryType::kKP; VLOG(3) << "modifing XPU KP kernel in static graph: " - << pt_kernel_name + << phi_kernel_name << ", using_kernel_key:" << *kernel_type_.get(); - auto try_pt_kernel_key = + auto try_phi_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); - if (!phi::KernelFactory::Instance().HasKernel(pt_kernel_name, - try_pt_kernel_key)) { + if (!phi::KernelFactory::Instance().HasKernel(phi_kernel_name, + try_phi_kernel_key)) { kernel_type_->library_type_ = expected_kernel_key_library_type; VLOG(3) << "modify XPU KP kernel in static graph: " - << pt_kernel_name << " is failed " << *kernel_type_.get(); + << phi_kernel_name << " is failed " << *kernel_type_.get(); } else { use_phi_xpu_kp = true; VLOG(3) << "modify XPU KP kernel in static graph: " - << pt_kernel_name << " is succeed " << *kernel_type_.get(); + << phi_kernel_name << " is succeed " << *kernel_type_.get(); } } } #endif - pt_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); + phi_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); } // NOTE(Liu-xiandong): Determine whether the selected kernel is valid @@ -1596,7 +1596,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, bool is_xpu_kp_support = (use_xpu_kp_kernel_rt || use_xpu_kp_kernel_debug); #endif - if (pt_kernel_->IsValid() + if (phi_kernel_->IsValid() #if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP) && !is_xpu_unsupport #endif @@ -1628,17 +1628,17 @@ void OperatorWithKernel::RunImpl(const Scope& scope, || (is_xpu_unsupport && !is_xpu_kp_support) #endif ) { - auto pt_cpu_kernel_key = - FallBackToCpu(*kernel_type_.get(), pt_kernel_key, *this); - pt_kernel_.reset( + auto phi_cpu_kernel_key = + FallBackToCpu(*kernel_type_.get(), phi_kernel_key, *this); + phi_kernel_.reset( new phi::Kernel(phi::KernelFactory::Instance().SelectKernel( - pt_kernel_name, pt_cpu_kernel_key))); + phi_kernel_name, phi_cpu_kernel_key))); dev_ctx = pool.Get(platform::CPUPlace()); - if (pt_kernel_->IsValid()) { - VLOG(6) << "Static mode PrepareImpl - kernel name: " << pt_kernel_name - << " | kernel key: " << pt_cpu_kernel_key - << " | kernel: " << *pt_kernel_; + if (phi_kernel_->IsValid()) { + VLOG(6) << "Static mode PrepareImpl - kernel name: " + << phi_kernel_name << " | kernel key: " << phi_cpu_kernel_key + << " | kernel: " << *phi_kernel_; run_phi_kernel_ = true; } } @@ -1692,20 +1692,20 @@ void OperatorWithKernel::RunImpl(const Scope& scope, 1, platform::EventRole::kInnerOp); if (run_phi_kernel_) { - phi::KernelContext pt_kernel_context; + phi::KernelContext phi_kernel_context; if (enable_cache_runtime_context_ && !need_prepare_phi_data_ && !need_prepare_data_) { impl_ = new CacheImpl(new phi::KernelContext(), new RuntimeInferShapeContext(*this, *runtime_ctx)); BuildPhiKernelContext(*runtime_ctx, dev_ctx, impl_->getKernelContext()); - (*pt_kernel_)(impl_->getKernelContext()); + (*phi_kernel_)(impl_->getKernelContext()); } else { - phi::KernelContext pt_kernel_context; + phi::KernelContext phi_kernel_context; // Do data transform before building KernelContext // TODO(zhiqiu): support TransferInplaceVarsBack - BuildPhiKernelContext(*runtime_ctx, dev_ctx, &pt_kernel_context); - (*pt_kernel_)(&pt_kernel_context); + BuildPhiKernelContext(*runtime_ctx, dev_ctx, &phi_kernel_context); + (*phi_kernel_)(&phi_kernel_context); } } else { (*kernel_func_)( @@ -1851,20 +1851,20 @@ phi::KernelKey OperatorWithKernel::ChoosePhiKernel( kernel_type_.reset( new OpKernelType(std::move(InnerGetExpectedKernelType(ctx)))); - auto pt_kernel_name = kernel_signature_->name; - auto pt_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); - pt_kernel_.reset(new phi::Kernel(phi::KernelFactory::Instance().SelectKernel( - pt_kernel_name, pt_kernel_key))); + auto phi_kernel_name = kernel_signature_->name; + auto phi_kernel_key = TransOpKernelTypeToPhiKernelKey(*kernel_type_.get()); + phi_kernel_.reset(new phi::Kernel(phi::KernelFactory::Instance().SelectKernel( + phi_kernel_name, phi_kernel_key))); - if (pt_kernel_->IsValid()) { - VLOG(6) << "Static mode ChoosePhiKernel - kernel name: " << pt_kernel_name - << " | kernel key: " << pt_kernel_key - << " | kernel: " << *pt_kernel_; + if (phi_kernel_->IsValid()) { + VLOG(6) << "Static mode ChoosePhiKernel - kernel name: " << phi_kernel_name + << " | kernel key: " << phi_kernel_key + << " | kernel: " << *phi_kernel_; } else { - VLOG(6) << "Static mode ChoosePhiKernel - kernel `" << pt_kernel_name + VLOG(6) << "Static mode ChoosePhiKernel - kernel `" << phi_kernel_name << "` not found."; } - return pt_kernel_key; + return phi_kernel_key; } void OperatorWithKernel::ChooseKernel(const ExecutionContext& ctx) const { @@ -2302,7 +2302,7 @@ Scope* OperatorWithKernel::PrepareData( if (run_phi_kernel_) { const auto& input_names = kernel_signature_->input_names; - const auto& input_defs = pt_kernel_->args_def().input_defs(); + const auto& input_defs = phi_kernel_->args_def().input_defs(); PADDLE_ENFORCE_EQ(input_names.size(), input_defs.size(), platform::errors::InvalidArgument( @@ -2311,7 +2311,7 @@ Scope* OperatorWithKernel::PrepareData( input_names.size(), input_defs.size())); for (size_t i = 0; i < input_defs.size(); ++i) { - const auto& input_defs = pt_kernel_->args_def().input_defs(); + const auto& input_defs = phi_kernel_->args_def().input_defs(); auto& in_def = input_defs.at(i); std::string input_name = input_names[i]; auto iter = ctx->inputs.find(input_name); @@ -2577,16 +2577,16 @@ phi::KernelSignature OperatorWithKernel::GetExpectedPhiKernelArgs( void OperatorWithKernel::BuildPhiKernelContext( const RuntimeContext& ctx, platform::DeviceContext* dev_ctx, - phi::KernelContext* pt_kernel_context) const { - pt_kernel_context->SetDeviceContext(dev_ctx); + phi::KernelContext* phi_kernel_context) const { + phi_kernel_context->SetDeviceContext(dev_ctx); auto& input_names = kernel_signature_->input_names; auto& attr_names = kernel_signature_->attr_names; auto& output_names = kernel_signature_->output_names; - auto input_defs = pt_kernel_->args_def().input_defs(); - auto attr_defs = pt_kernel_->args_def().attribute_defs(); - auto output_defs = pt_kernel_->args_def().output_defs(); + auto input_defs = phi_kernel_->args_def().input_defs(); + auto attr_defs = phi_kernel_->args_def().attribute_defs(); + auto output_defs = phi_kernel_->args_def().output_defs(); PADDLE_ENFORCE_EQ(input_names.size(), input_defs.size(), @@ -2617,7 +2617,7 @@ void OperatorWithKernel::BuildPhiKernelContext( // calcute the start and end index of the input tensors size_t start_idx = - (i == 0 ? 0 : pt_kernel_context->InputRangeAt(i - 1).second); + (i == 0 ? 0 : phi_kernel_context->InputRangeAt(i - 1).second); // deal with optional here if ((it == ctx.inputs.end() || it->second.size() == 0) && (input_defs[i].type_index == @@ -2627,10 +2627,10 @@ void OperatorWithKernel::BuildPhiKernelContext( input_defs[i].type_index == std::type_index(typeid( paddle::optional>)))) { - pt_kernel_context->EmplaceBackInputWithoutSetRange(nullptr); + phi_kernel_context->EmplaceBackInputWithoutSetRange(nullptr); auto end_idx = start_idx + 1; - pt_kernel_context->AssignInputRange(std::make_pair(start_idx, end_idx), - i); + phi_kernel_context->AssignInputRange(std::make_pair(start_idx, end_idx), + i); continue; } @@ -2641,10 +2641,10 @@ void OperatorWithKernel::BuildPhiKernelContext( auto* var = ins_vector[offset]; if (var->IsType()) { tensor_in = &(var->Get()); - pt_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in); + phi_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in); } else if (var->IsType()) { tensor_in = &(var->Get()); - pt_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in); + phi_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in); } else if (var->IsType()) { need_prepare_phi_data_ = true; paddle::small_vector tensor_vector; @@ -2652,7 +2652,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (auto& t : tensor_array) { tensor_vector.emplace_back(&t); } - pt_kernel_context->EmplaceBackInputsWithoutSetRange(tensor_vector); + phi_kernel_context->EmplaceBackInputsWithoutSetRange(tensor_vector); end_idx += tensor_array.size() - 1; } else { PADDLE_THROW(platform::errors::Unimplemented( @@ -2661,24 +2661,24 @@ void OperatorWithKernel::BuildPhiKernelContext( } } // Note: here cannot deal with vector input - pt_kernel_context->AssignInputRange(std::make_pair(start_idx, end_idx), i); + phi_kernel_context->AssignInputRange(std::make_pair(start_idx, end_idx), i); } VLOG(4) << "Done inputs"; for (size_t i = 0; i < output_names.size(); ++i) { auto it = ctx.outputs.find(output_names[i]); size_t start_idx = - (i == 0 ? 0 : pt_kernel_context->OutputRangeAt(i - 1).second); + (i == 0 ? 0 : phi_kernel_context->OutputRangeAt(i - 1).second); if (it == ctx.outputs.end() || it->second.empty()) { // Deal with the case that some outputs are not found or be NULL when run // the kernel. // For example : the outputs of matmul_grad are dx and dy, // sometimes dx or dy may be NULL. - pt_kernel_context->EmplaceBackOutputWithoutSetRange(nullptr); + phi_kernel_context->EmplaceBackOutputWithoutSetRange(nullptr); auto end_idx = start_idx + 1; - pt_kernel_context->AssignOutputRange(std::make_pair(start_idx, end_idx), - i); + phi_kernel_context->AssignOutputRange(std::make_pair(start_idx, end_idx), + i); continue; } auto& outs_vector = it->second; @@ -2691,10 +2691,10 @@ void OperatorWithKernel::BuildPhiKernelContext( if (var) { if (var->template IsType()) { tensor_out = var->template GetMutable(); - pt_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); + phi_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); } else if (var->template IsType()) { tensor_out = var->template GetMutable(); - pt_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); + phi_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); } else if (var->template IsType()) { paddle::small_vector tensor_vector; auto* tensor_array = @@ -2704,7 +2704,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (auto& t : *tensor_array) { tensor_vector.emplace_back(&t); } - pt_kernel_context->EmplaceBackOutputsWithoutSetRange(tensor_vector); + phi_kernel_context->EmplaceBackOutputsWithoutSetRange(tensor_vector); end_idx += tensor_array->size() - 1; } else { PADDLE_THROW(platform::errors::Unimplemented( @@ -2712,10 +2712,11 @@ void OperatorWithKernel::BuildPhiKernelContext( framework::ToTypeName(var->Type()))); } } else { - pt_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); + phi_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); } } - pt_kernel_context->AssignOutputRange(std::make_pair(start_idx, end_idx), i); + phi_kernel_context->AssignOutputRange(std::make_pair(start_idx, end_idx), + i); } VLOG(4) << "Done outputs"; @@ -2729,15 +2730,15 @@ void OperatorWithKernel::BuildPhiKernelContext( // scalar is in the attribute switch (AttrTypeID(attr_iter->second)) { case proto::AttrType::FLOAT: - pt_kernel_context->EmplaceBackAttr(std::move( + phi_kernel_context->EmplaceBackAttr(std::move( phi::Scalar(PADDLE_GET_CONST(float, attr_iter->second)))); break; case proto::AttrType::INT: - pt_kernel_context->EmplaceBackAttr(std::move( + phi_kernel_context->EmplaceBackAttr(std::move( phi::Scalar(PADDLE_GET_CONST(int, attr_iter->second)))); break; case proto::AttrType::STRING: - pt_kernel_context->EmplaceBackAttr(std::move(phi::Scalar( + phi_kernel_context->EmplaceBackAttr(std::move(phi::Scalar( PADDLE_GET_CONST(std::string, attr_iter->second)))); break; default: @@ -2749,7 +2750,7 @@ void OperatorWithKernel::BuildPhiKernelContext( } else { // scalar is in the input need_prepare_phi_data_ = true; auto& ins_vector = ctx.inputs.at(attr_names[i]); - pt_kernel_context->EmplaceBackAttr(std::move( + phi_kernel_context->EmplaceBackAttr(std::move( experimental::MakePhiScalarFromVar(*ins_vector.front()))); } break; @@ -2757,19 +2758,19 @@ void OperatorWithKernel::BuildPhiKernelContext( if (attr_iter != Attrs().end()) { switch (AttrTypeID(attr_iter->second)) { case proto::AttrType::INTS: - pt_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( + phi_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( PADDLE_GET_CONST(std::vector, attr_iter->second)))); break; case proto::AttrType::LONGS: - pt_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( + phi_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( PADDLE_GET_CONST(std::vector, attr_iter->second)))); break; case proto::AttrType::INT: - pt_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( + phi_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( &PADDLE_GET_CONST(int32_t, attr_iter->second), 1))); break; case proto::AttrType::LONG: - pt_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( + phi_kernel_context->EmplaceBackAttr(std::move(phi::IntArray( &PADDLE_GET_CONST(int64_t, attr_iter->second), 1))); break; default: @@ -2782,10 +2783,10 @@ void OperatorWithKernel::BuildPhiKernelContext( need_prepare_phi_data_ = true; auto& ins_vector = ctx.inputs.at(attr_names[i]); if (ins_vector.size() == 1) { // ShapeTensor - pt_kernel_context->EmplaceBackAttr(std::move( + phi_kernel_context->EmplaceBackAttr(std::move( experimental::MakePhiIntArrayFromVar(*ins_vector.front()))); } else { // ShapeTensorList - pt_kernel_context->EmplaceBackAttr(std::move( + phi_kernel_context->EmplaceBackAttr(std::move( experimental::MakePhiIntArrayFromVarList(ins_vector))); } } @@ -2806,7 +2807,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (const auto& val : vec) { scalar_list.emplace_back(val); } - pt_kernel_context->EmplaceBackAttr(std::move(scalar_list)); + phi_kernel_context->EmplaceBackAttr(std::move(scalar_list)); } break; case proto::AttrType::LONGS: { const auto& vec = @@ -2816,7 +2817,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (const auto& val : vec) { scalar_list.emplace_back(val); } - pt_kernel_context->EmplaceBackAttr(std::move(scalar_list)); + phi_kernel_context->EmplaceBackAttr(std::move(scalar_list)); } break; case proto::AttrType::FLOATS: { const auto& vec = @@ -2826,7 +2827,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (const auto& val : vec) { scalar_list.emplace_back(val); } - pt_kernel_context->EmplaceBackAttr(std::move(scalar_list)); + phi_kernel_context->EmplaceBackAttr(std::move(scalar_list)); } break; case proto::AttrType::FLOAT64S: { const auto& vec = @@ -2836,7 +2837,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (const auto& val : vec) { scalar_list.emplace_back(val); } - pt_kernel_context->EmplaceBackAttr(std::move(scalar_list)); + phi_kernel_context->EmplaceBackAttr(std::move(scalar_list)); } break; case proto::AttrType::BOOLEANS: { const auto& vec = @@ -2846,7 +2847,7 @@ void OperatorWithKernel::BuildPhiKernelContext( for (const auto& val : vec) { scalar_list.emplace_back(val); } - pt_kernel_context->EmplaceBackAttr(std::move(scalar_list)); + phi_kernel_context->EmplaceBackAttr(std::move(scalar_list)); } break; default: PADDLE_THROW(platform::errors::Unimplemented( @@ -2864,39 +2865,39 @@ void OperatorWithKernel::BuildPhiKernelContext( attr_names[i])); switch (attr_defs[i].type_index) { case phi::AttributeType::FLOAT32: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(float, attr_iter->second)); break; case phi::AttributeType::INT32: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(int, attr_iter->second)); break; case phi::AttributeType::BOOL: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(bool, attr_iter->second)); break; case phi::AttributeType::INT64: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(int64_t, attr_iter->second)); break; case phi::AttributeType::INT32S: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(std::vector, attr_iter->second)); break; case phi::AttributeType::DATA_TYPE: { auto data_type = framework::TransToPhiDataType( static_cast( PADDLE_GET_CONST(int, attr_iter->second))); - pt_kernel_context->EmplaceBackAttr(data_type); + phi_kernel_context->EmplaceBackAttr(data_type); } break; case phi::AttributeType::STRING: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( std::move(PADDLE_GET_CONST(std::string, attr_iter->second))); break; case phi::AttributeType::INT64S: switch (AttrTypeID(attr_iter->second)) { case proto::AttrType::LONGS: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(std::vector, attr_iter->second)); break; case proto::AttrType::INTS: { @@ -2904,7 +2905,7 @@ void OperatorWithKernel::BuildPhiKernelContext( PADDLE_GET_CONST(std::vector, attr_iter->second); const std::vector vector_int64_attr( vector_int_attr.begin(), vector_int_attr.end()); - pt_kernel_context->EmplaceBackAttr(vector_int64_attr); + phi_kernel_context->EmplaceBackAttr(vector_int64_attr); } break; default: PADDLE_THROW(platform::errors::Unimplemented( @@ -2915,11 +2916,11 @@ void OperatorWithKernel::BuildPhiKernelContext( } break; case phi::AttributeType::FLOAT32S: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(std::vector, attr_iter->second)); break; case phi::AttributeType::STRINGS: - pt_kernel_context->EmplaceBackAttr( + phi_kernel_context->EmplaceBackAttr( PADDLE_GET_CONST(std::vector, attr_iter->second)); break; default: diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index cb6b2d832bf..17ec9a1f93e 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -652,16 +652,16 @@ class OperatorWithKernel : public OperatorBase { void BuildPhiKernelContext(const RuntimeContext& ctx, platform::DeviceContext* dev_ctx, - phi::KernelContext* pt_kernel_context) const; + phi::KernelContext* phi_kernel_context) const; phi::KernelSignature* PhiKernelSignature() const { return kernel_signature_.get(); } - phi::Kernel* PhiKernel() const { return pt_kernel_.get(); } + phi::Kernel* PhiKernel() const { return phi_kernel_.get(); } void ResetPhiKernel(phi::Kernel* kernel) const { - return pt_kernel_.reset(kernel); + return phi_kernel_.reset(kernel); } const OpKernelType* kernel_type() const { return kernel_type_.get(); } @@ -730,7 +730,7 @@ class OperatorWithKernel : public OperatorBase { mutable bool run_phi_kernel_ = false; mutable bool run_kp_kernel = false; mutable std::unique_ptr kernel_signature_; - mutable std::unique_ptr pt_kernel_; + mutable std::unique_ptr phi_kernel_; mutable std::unique_ptr arg_map_fn_; struct CacheImpl; diff --git a/paddle/fluid/imperative/op_base.h b/paddle/fluid/imperative/op_base.h index 04d6b4bd760..3faa9a0cfb6 100644 --- a/paddle/fluid/imperative/op_base.h +++ b/paddle/fluid/imperative/op_base.h @@ -227,7 +227,7 @@ class OpBase { size_t id_{-1UL}; // In order to reduce the compatibility phase // performance overhead, temporarily cache KernelContext - static phi::KernelContext pt_kernel_context_; + static phi::KernelContext phi_kernel_context_; std::vector>> void_function_post_hooks_; }; diff --git a/paddle/fluid/imperative/prepared_operator.cc b/paddle/fluid/imperative/prepared_operator.cc index 029c01a245b..62bbf77a2df 100644 --- a/paddle/fluid/imperative/prepared_operator.cc +++ b/paddle/fluid/imperative/prepared_operator.cc @@ -183,8 +183,8 @@ PreparedOp PrepareImpl( const phi::KernelSignature* default_kernel_signature = nullptr; phi::KernelSignature kernel_signature; - phi::KernelKey pt_kernel_key; - std::string pt_kernel_name; + phi::KernelKey phi_kernel_key; + std::string phi_kernel_name; #if defined(PADDLE_WITH_XPU) bool is_xpu_unsupport = paddle::platform::is_xpu_place(expected_kernel_key.place_) && @@ -213,7 +213,7 @@ PreparedOp PrepareImpl( if (has_phi_kernel) { VLOG(6) << kernel_signature; - pt_kernel_name = kernel_signature.name; + phi_kernel_name = kernel_signature.name; // NOTE(Liu-xiandong): The register kernel used KP have library_type[KP], // But the default library_type is Plain, so we need to modify the // library_type here, otherwise it can't work. @@ -236,34 +236,35 @@ PreparedOp PrepareImpl( auto expected_kernel_key_library_type = expected_kernel_key.library_type_; expected_kernel_key.library_type_ = paddle::framework::LibraryType::kKP; - VLOG(3) << "modifing XPU KP kernel: " << pt_kernel_name + VLOG(3) << "modifing XPU KP kernel: " << phi_kernel_name << ", using_kernel_key:" << expected_kernel_key; - phi::KernelKey try_pt_kernel_key = + phi::KernelKey try_phi_kernel_key = TransOpKernelTypeToPhiKernelKey(expected_kernel_key); - if (!phi_kernel_factory.HasKernel(pt_kernel_name, try_pt_kernel_key)) { + if (!phi_kernel_factory.HasKernel(phi_kernel_name, + try_phi_kernel_key)) { expected_kernel_key.library_type_ = expected_kernel_key_library_type; - VLOG(3) << "modify XPU KP kernel: " << pt_kernel_name + VLOG(3) << "modify XPU KP kernel: " << phi_kernel_name << " in dynamic graph is failed " << expected_kernel_key; } else { - VLOG(3) << "modify XPU KP kernel: " << pt_kernel_name + VLOG(3) << "modify XPU KP kernel: " << phi_kernel_name << " in dynamic graph is succeed " << expected_kernel_key; } } } #endif - pt_kernel_key = TransOpKernelTypeToPhiKernelKey(expected_kernel_key); + phi_kernel_key = TransOpKernelTypeToPhiKernelKey(expected_kernel_key); auto& phi_kernel = - phi_kernel_factory.SelectKernel(pt_kernel_name, pt_kernel_key); + phi_kernel_factory.SelectKernel(phi_kernel_name, phi_kernel_key); if (phi_kernel.IsValid() #if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP) && !is_xpu_unsupport #endif ) { - VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << pt_kernel_name - << " | kernel key: " << pt_kernel_key + VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << phi_kernel_name + << " | kernel key: " << phi_kernel_key << " | kernel: " << phi_kernel; if (expected_kernel_key.place_ != place) { @@ -279,7 +280,7 @@ PreparedOp PrepareImpl( phi_kernel, dev_ctx); } else { - VLOG(6) << "Dynamic mode ChoosePhiKernel - kernel `" << pt_kernel_name + VLOG(6) << "Dynamic mode ChoosePhiKernel - kernel `" << phi_kernel_name << "` not found."; } } @@ -316,23 +317,23 @@ PreparedOp PrepareImpl( #endif ) { if (has_phi_kernel) { - auto pt_cpu_kernel_key = - FallBackToCpu(expected_kernel_key, pt_kernel_key, op); - auto& pt_cpu_kernel = - phi_kernel_factory.SelectKernel(pt_kernel_name, pt_cpu_kernel_key); - if (pt_cpu_kernel.IsValid()) { - VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << pt_kernel_name - << " | kernel key: " << pt_cpu_kernel_key - << " | kernel: " << pt_cpu_kernel; + auto phi_cpu_kernel_key = + FallBackToCpu(expected_kernel_key, phi_kernel_key, op); + auto& phi_cpu_kernel = + phi_kernel_factory.SelectKernel(phi_kernel_name, phi_cpu_kernel_key); + if (phi_cpu_kernel.IsValid()) { + VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << phi_kernel_name + << " | kernel key: " << phi_cpu_kernel_key + << " | kernel: " << phi_cpu_kernel; auto* cpu_ctx = pool.Get(paddle::platform::CPUPlace()); return PreparedOp( op, empty_ctx, - framework::TransPhiKernelKeyToOpKernelType(pt_cpu_kernel_key), + framework::TransPhiKernelKeyToOpKernelType(phi_cpu_kernel_key), arg_map_fn, default_kernel_signature, std::move(kernel_signature), - pt_cpu_kernel, + phi_cpu_kernel, cpu_ctx); } } @@ -610,7 +611,7 @@ static void PreparedOpRunPtImpl( PreparePhiData(phi_kernel, kernel_signature, ins); - phi::KernelContext pt_kernel_context; + phi::KernelContext phi_kernel_context; BuildDygraphPhiKernelContext(kernel_signature, phi_kernel, ins, @@ -618,9 +619,9 @@ static void PreparedOpRunPtImpl( attrs, default_attrs, dev_ctx, - &pt_kernel_context); + &phi_kernel_context); - phi_kernel(&pt_kernel_context); + phi_kernel(&phi_kernel_context); } if (FLAGS_check_nan_inf) { diff --git a/paddle/phi/capi/include/kernel_utils.h b/paddle/phi/capi/include/kernel_utils.h index 246bc9e3c59..6c1d3f3c0ee 100644 --- a/paddle/phi/capi/include/kernel_utils.h +++ b/paddle/phi/capi/include/kernel_utils.h @@ -130,283 +130,283 @@ namespace capi { PD_CUSTOM_PHI_KERNEL_EXPAND( \ _PD_BUILD_KERNEL_INSTANTIATION_14(meta_kernel_fn, backend, __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_1(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - int TouchCustomKernelSymbolFor_##kernel_name##_##backend##_##layout() { \ - return 0; \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_1(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + int TouchCustomKernelSymbolFor_##kernel_name##_##backend##_##layout() { \ + return 0; \ } -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_2(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_1(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_2(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_1(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_3(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_2(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_3(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_2(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_4(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_3(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_4(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_3(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_5(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_4(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_5(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_4(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_6(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_5(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_6(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_5(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_7(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_6(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_7(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_6(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_8(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_7(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_8(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_7(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_9(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_8(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_9(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_8(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_10(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_9(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_10(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_9(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_11(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_10(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_11(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_10(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_12(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_11(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_12(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_11(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_13(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_12(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_13(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_12(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_14(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_13(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_14(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_13(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_BUILD_KERNEL_REGISTRAR_INIT_15(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - registrar_id, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ - PD_CUSTOM_PHI_KERNEL_EXPAND( \ - _PD_BUILD_KERNEL_REGISTRAR_INIT_14(registrar_class, \ - kernel_name, \ - backend, \ - layout, \ - PD_CUSTOM_PHI_KERNEL_ID, \ - meta_kernel_fn, \ +#define _PD_BUILD_KERNEL_REGISTRAR_INIT_15(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + registrar_id, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const registrar_class PD_CUSTOM_PHI_KERNEL_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id); \ + PD_CUSTOM_PHI_KERNEL_EXPAND( \ + _PD_BUILD_KERNEL_REGISTRAR_INIT_14(registrar_class, \ + kernel_name, \ + backend, \ + layout, \ + PD_CUSTOM_PHI_KERNEL_ID, \ + meta_kernel_fn, \ __VA_ARGS__)) #define _PD_BUILD_KERNEL_REGISTRAR_INIT( \ diff --git a/paddle/phi/core/kernel_registry.h b/paddle/phi/core/kernel_registry.h index 010d5c2e0c3..92cc3f511f6 100644 --- a/paddle/phi/core/kernel_registry.h +++ b/paddle/phi/core/kernel_registry.h @@ -553,461 +553,461 @@ struct KernelRegistrar { // clang-format on -#define _PD_KERNEL_REGISTRAR_INIT_1(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ +#define _PD_KERNEL_REGISTRAR_INIT_1(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ int TouchKernelSymbolFor_##kernel_name##_##backend##_##layout() { return 0; } -#define _PD_KERNEL_REGISTRAR_INIT_2(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_1(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_2(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_1(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_3(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_2(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_3(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_2(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_4(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_3(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_4(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_3(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_5(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_4(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_5(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_4(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_6(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_5(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_6(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_5(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_7(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_6(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_7(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_6(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_8(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_7(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_8(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_7(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_9(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_8(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_9(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_8(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_10(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_9(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_10(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_9(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_11(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_10(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_11(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_10(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_12(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_11(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_12(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_11(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_13(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_12(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_13(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_12(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_14(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_13(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_14(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_13(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) -#define _PD_KERNEL_REGISTRAR_INIT_15(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - registrar_id, \ - args_def_fn, \ - meta_kernel_fn, \ - cpp_dtype, \ - ...) \ - static const ::phi::KernelRegistrar PD_CONCATENATE( \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ - reg_type, \ - #kernel_name, \ - #backend, \ - DATALAYOUT(layout), \ - ::paddle::experimental::CppTypeToDataType::Type(), \ - ::phi::KernelArgsParseFunctor< \ - decltype(&meta_kernel_fn)>::Parse, \ - args_def_fn, \ - PHI_KERNEL(meta_kernel_fn), \ - PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ - PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_14(reg_type, \ - kernel_name, \ - backend, \ - context, \ - layout, \ - PD_ID, \ - args_def_fn, \ - meta_kernel_fn, \ +#define _PD_KERNEL_REGISTRAR_INIT_15(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + registrar_id, \ + args_def_fn, \ + meta_kernel_fn, \ + cpp_dtype, \ + ...) \ + static const ::phi::KernelRegistrar PD_CONCATENATE( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout##_, registrar_id)( \ + reg_type, \ + #kernel_name, \ + #backend, \ + DATALAYOUT(layout), \ + ::paddle::experimental::CppTypeToDataType::Type(), \ + ::phi::KernelArgsParseFunctor< \ + decltype(&meta_kernel_fn)>::Parse, \ + args_def_fn, \ + PHI_KERNEL(meta_kernel_fn), \ + PHI_VARIADIC_KERNEL(meta_kernel_fn)); \ + PD_EXPAND(_PD_KERNEL_REGISTRAR_INIT_14(reg_type, \ + kernel_name, \ + backend, \ + context, \ + layout, \ + PD_ID, \ + args_def_fn, \ + meta_kernel_fn, \ __VA_ARGS__)) /** PD_REGISTER_GENERAL_KERNEL * @@ -1035,7 +1035,7 @@ struct KernelRegistrar { static void __PD_KERNEL_args_def_FN_##kernel_name##_##backend##_##layout( \ const ::phi::KernelKey& kernel_key, ::phi::Kernel* kernel); \ static const ::phi::KernelRegistrar \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout( \ reg_type, \ #kernel_name, \ #backend, \ @@ -1055,7 +1055,7 @@ struct KernelRegistrar { static void __PD_KERNEL_args_def_FN_##kernel_name##_##backend##_##layout( \ const ::phi::KernelKey& kernel_key, ::phi::Kernel* kernel); \ static const ::phi::KernelRegistrar \ - __reg_pt_kernel_##kernel_name##_##backend##_##layout( \ + __reg_phi_kernel_##kernel_name##_##backend##_##layout( \ reg_type, \ #kernel_name, \ #backend, \ -- GitLab