未验证 提交 942ff89f 编写于 作者: W Weilong Wu 提交者: GitHub

[Phi] polish and rename, pt* -> phi* (#44697)

* polish and rename, pt* -> phi*

* fix code format
上级 d985b4b1
......@@ -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<platform::DeviceContext*>(&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());
......
......@@ -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(
......
......@@ -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_; }
......
......@@ -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_;
};
......
此差异已折叠。
......@@ -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<phi::KernelSignature> kernel_signature_;
mutable std::unique_ptr<phi::Kernel> pt_kernel_;
mutable std::unique_ptr<phi::Kernel> phi_kernel_;
mutable std::unique_ptr<phi::ArgumentMappingFn> arg_map_fn_;
struct CacheImpl;
......
......@@ -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<std::shared_ptr<std::function<void()>>> void_function_post_hooks_;
};
......
......@@ -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<VarType>(phi_kernel, kernel_signature, ins);
phi::KernelContext pt_kernel_context;
phi::KernelContext phi_kernel_context;
BuildDygraphPhiKernelContext<VarType>(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) {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册