未验证 提交 7a7a7cad 编写于 作者: A Aurelius84 提交者: GitHub

[Phi] Fix XPU OP segmentation Fault problem (#39827)

* [Phi] Fix XPU OP segmentation Fault problem

* fix cast_op_xpu in kunlun1

* fix cast_op_xpu in kunlun1
上级 94b31f90
...@@ -1211,7 +1211,17 @@ void OperatorWithKernel::RunImpl(const Scope& scope, ...@@ -1211,7 +1211,17 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
<< "` not found."; << "` not found.";
} }
} }
if (pt_kernel_->IsValid()) { #ifdef PADDLE_WITH_XPU
bool is_xpu_unsupport =
paddle::platform::is_xpu_place(kernel_type_->place_) &&
!paddle::platform::is_xpu_support_op(type_, *kernel_type_.get()) ||
paddle::platform::is_in_xpu_black_list(type_);
#endif
if (pt_kernel_->IsValid()
#ifdef PADDLE_WITH_XPU
&& !is_xpu_unsupport
#endif
) {
run_pten_kernel_ = true; run_pten_kernel_ = true;
} else { } else {
auto& all_op_kernels = AllOpKernels(); auto& all_op_kernels = AllOpKernels();
...@@ -1220,13 +1230,9 @@ void OperatorWithKernel::RunImpl(const Scope& scope, ...@@ -1220,13 +1230,9 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
kernels_iter->second.find(*kernel_type_.get()) == kernels_iter->second.find(*kernel_type_.get()) ==
kernels_iter->second.end() kernels_iter->second.end()
#ifdef PADDLE_WITH_XPU #ifdef PADDLE_WITH_XPU
|| || is_xpu_unsupport
paddle::platform::is_xpu_place(kernel_type_->place_) && // NOLINT
!paddle::platform::is_xpu_support_op(
type_, *kernel_type_.get()) // NOLINT
|| paddle::platform::is_in_xpu_black_list(type_)
#endif #endif
) { ) {
auto pt_cpu_kernel_key = auto pt_cpu_kernel_key =
FallBackToCpu(*kernel_type_.get(), pt_kernel_key, *this); FallBackToCpu(*kernel_type_.get(), pt_kernel_key, *this);
pt_kernel_.reset( pt_kernel_.reset(
......
...@@ -161,6 +161,13 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins, ...@@ -161,6 +161,13 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
framework::KernelSignature pt_kernel_signature; framework::KernelSignature pt_kernel_signature;
phi::KernelKey pt_kernel_key; phi::KernelKey pt_kernel_key;
std::string pt_kernel_name; std::string pt_kernel_name;
#ifdef PADDLE_WITH_XPU
bool is_xpu_unsupport =
paddle::platform::is_xpu_place(expected_kernel_key.place_) &&
!paddle::platform::is_xpu_support_op(op.Type(),
expected_kernel_key) ||
paddle::platform::is_in_xpu_black_list(op.Type());
#endif
if (phi::KernelFactory::Instance().HasCompatiblePtenKernel(op.Type())) { if (phi::KernelFactory::Instance().HasCompatiblePtenKernel(op.Type())) {
pt_kernel_signature = op.GetExpectedPtenKernelArgs(dygraph_exe_ctx); pt_kernel_signature = op.GetExpectedPtenKernelArgs(dygraph_exe_ctx);
VLOG(6) << pt_kernel_signature; VLOG(6) << pt_kernel_signature;
...@@ -170,7 +177,11 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins, ...@@ -170,7 +177,11 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
auto pt_kernel = phi::KernelFactory::Instance().SelectKernel(pt_kernel_name, auto pt_kernel = phi::KernelFactory::Instance().SelectKernel(pt_kernel_name,
pt_kernel_key); pt_kernel_key);
if (pt_kernel.IsValid()) { if (pt_kernel.IsValid()
#ifdef PADDLE_WITH_XPU
&& !is_xpu_unsupport
#endif
) {
VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << pt_kernel_name VLOG(6) << "Dynamic mode PrepareImpl - kernel name: " << pt_kernel_name
<< " | kernel key: " << pt_kernel_key << " | kernel key: " << pt_kernel_key
<< " | kernel: " << pt_kernel; << " | kernel: " << pt_kernel;
...@@ -197,13 +208,9 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins, ...@@ -197,13 +208,9 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
kernels_iter->second.find(expected_kernel_key) == kernels_iter->second.find(expected_kernel_key) ==
kernels_iter->second.end()) kernels_iter->second.end())
#ifdef PADDLE_WITH_XPU #ifdef PADDLE_WITH_XPU
|| || is_xpu_unsupport
paddle::platform::is_xpu_place(expected_kernel_key.place_) &&
!paddle::platform::is_xpu_support_op(op.Type(),
expected_kernel_key) ||
paddle::platform::is_in_xpu_black_list(op.Type())
#endif #endif
) { ) {
if (phi::KernelFactory::Instance().HasCompatiblePtenKernel(op.Type())) { if (phi::KernelFactory::Instance().HasCompatiblePtenKernel(op.Type())) {
auto pt_cpu_kernel_key = auto pt_cpu_kernel_key =
FallBackToCpu(expected_kernel_key, pt_kernel_key, op); FallBackToCpu(expected_kernel_key, pt_kernel_key, op);
...@@ -230,9 +237,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins, ...@@ -230,9 +237,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
#ifdef PADDLE_WITH_XPU #ifdef PADDLE_WITH_XPU
if (paddle::platform::is_xpu_place(expected_kernel_key.place_) && if (paddle::platform::is_xpu_place(expected_kernel_key.place_) &&
(kernel_iter == kernels.end() || (kernel_iter == kernels.end() || is_xpu_unsupport)) {
!paddle::platform::is_xpu_support_op(op.Type(), expected_kernel_key) ||
paddle::platform::is_in_xpu_black_list(op.Type()))) {
VLOG(3) << "missing XPU kernel: " << op.Type() VLOG(3) << "missing XPU kernel: " << op.Type()
<< ", expected_kernel_key:" << expected_kernel_key << ", expected_kernel_key:" << expected_kernel_key
<< ", fallbacking to CPU one!"; << ", fallbacking to CPU one!";
......
...@@ -30,6 +30,8 @@ Backend TransToPtenBackend(const phi::Place& place) { ...@@ -30,6 +30,8 @@ Backend TransToPtenBackend(const phi::Place& place) {
return Backend::CPU; return Backend::CPU;
} else if (place.GetType() == phi::AllocationType::GPU) { } else if (place.GetType() == phi::AllocationType::GPU) {
return Backend::GPU; return Backend::GPU;
} else if (place.GetType() == phi::AllocationType::XPU) {
return Backend::XPU;
} else if (place.GetType() == phi::AllocationType::CUSTOM) { } else if (place.GetType() == phi::AllocationType::CUSTOM) {
return static_cast<Backend>( return static_cast<Backend>(
static_cast<size_t>(Backend::NUM_BACKENDS) + static_cast<size_t>(Backend::NUM_BACKENDS) +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册