未验证 提交 5dae6da0 编写于 作者: L Leo Chen 提交者: GitHub

[new-exec] move WaitEvent/RecordEvent into try-catch (#41222)

* move WaitEvent/RecordEvent into try-catch

* refine supportNpu
上级 e6a19aea
......@@ -501,7 +501,7 @@ void InterpreterCore::RunInstruction(const Instruction& instr_node) {
}
// for debug nan/inf
if (FLAGS_check_nan_inf) {
if (op_with_kernel != nullptr && FLAGS_check_nan_inf) {
VLOG(4) << "Check nan/inf";
framework::details::CheckOpHasNanOrInf(
*op, *global_scope_,
......@@ -542,10 +542,12 @@ void InterpreterCore::ExecuteInstructionList(
if (exception_holder_.Type() != "EOF") {
async_work_queue_->Cancel();
}
VLOG(4) << "Cancel ok";
PADDLE_ENFORCE_EQ(
main_thread_blocker_.Clear(), 0,
platform::errors::PreconditionNotMet(
"main_thread_blocker_.Clear() return -1, clear failed"));
VLOG(4) << "clear ok";
exception_holder_.ReThrow();
}
}
......@@ -637,15 +639,18 @@ void InterpreterCore::RunInstructionAsync(
auto* op = instr_node.OpBase();
platform::RecordEvent instruction_event(
op->Type(), platform::TracerEventType::Operator, 1);
interpreter::WaitEvent(instr_node, place_);
try {
interpreter::WaitEvent(instr_node, place_);
RunInstruction(instr_node);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
RecordStreamForGC(instr_node);
#endif
CheckGC(instr_node, atomic_var_ref);
interpreter::RecordEvent(instr_node, place_);
} catch (platform::EnforceNotMet& ex) {
framework::InsertCallStackInfo(op->Type(), op->Attrs(), &ex);
exception_holder_.Catch(std::make_exception_ptr(std::move(ex)));
......@@ -677,8 +682,6 @@ void InterpreterCore::RunInstructionAsync(
}
}
interpreter::RecordEvent(instr_node, place_);
RunNextInstructions(instr_node, &ready_ops, atomic_deps, atomic_var_ref);
}
}
......
......@@ -1120,6 +1120,56 @@ static void CheckTensorNANOrInf(const std::string& op_type,
op_type, name));
}
bool OperatorWithKernel::SupportGPU() const {
auto phi_kernels = phi::KernelFactory::Instance().SelectKernelMap(
phi::TransToPhiKernelName(type_));
auto has_phi_kernel =
std::any_of(phi_kernels.begin(), phi_kernels.end(),
[](phi::KernelKeyMap::const_reference kern_pair) {
return kern_pair.first.backend() == phi::Backend::GPU;
});
if (has_phi_kernel) {
return true;
} else {
auto kernel_iter = OperatorWithKernel::AllOpKernels().find(type_);
if (kernel_iter == OperatorWithKernel::AllOpKernels().end()) {
return false;
} else {
auto& op_kernels = kernel_iter->second;
return std::any_of(
op_kernels.begin(), op_kernels.end(),
[](OpKernelMap::const_reference kern_pair) {
return platform::is_gpu_place(kern_pair.first.place_);
});
}
}
}
bool OperatorWithKernel::SupportNPU() const {
auto phi_kernels = phi::KernelFactory::Instance().SelectKernelMap(
phi::TransToPhiKernelName(type_));
auto has_phi_kernel =
std::any_of(phi_kernels.begin(), phi_kernels.end(),
[](phi::KernelKeyMap::const_reference kern_pair) {
return kern_pair.first.backend() == phi::Backend::NPU;
});
if (has_phi_kernel) {
return true;
} else {
auto kernel_iter = OperatorWithKernel::AllOpKernels().find(type_);
if (kernel_iter == OperatorWithKernel::AllOpKernels().end()) {
return false;
} else {
auto& op_kernels = kernel_iter->second;
return std::any_of(
op_kernels.begin(), op_kernels.end(),
[](OpKernelMap::const_reference kern_pair) {
return platform::is_npu_place(kern_pair.first.place_);
});
}
}
}
bool OperatorWithKernel::SupportsMKLDNN(
const proto::VarType::Type data_type) const {
auto op_kernel_iter = OperatorWithKernel::AllOpKernels().find(type_);
......
......@@ -560,39 +560,10 @@ class OperatorWithKernel : public OperatorBase {
return g_all_op_kernels;
}
bool SupportGPU() const override {
auto phi_kernels = phi::KernelFactory::Instance().SelectKernelMap(
phi::TransToPhiKernelName(type_));
auto has_phi_kernel =
std::any_of(phi_kernels.begin(), phi_kernels.end(),
[](phi::KernelKeyMap::const_reference kern_pair) {
return kern_pair.first.backend() == phi::Backend::GPU;
});
if (has_phi_kernel) {
return true;
} else {
auto kernel_iter = OperatorWithKernel::AllOpKernels().find(type_);
if (kernel_iter == OperatorWithKernel::AllOpKernels().end()) {
return false;
} else {
auto& op_kernels = kernel_iter->second;
return std::any_of(
op_kernels.begin(), op_kernels.end(),
[](OpKernelMap::const_reference kern_pair) {
return platform::is_gpu_place(kern_pair.first.place_);
});
}
}
}
bool SupportGPU() const override;
bool SupportNPU() const override;
bool SupportNPU() const override {
// TODO(zhiqiu): support phi if needed?
auto& op_kernels = OperatorWithKernel::AllOpKernels().at(type_);
return std::any_of(op_kernels.begin(), op_kernels.end(),
[](OpKernelMap::const_reference kern_pair) {
return platform::is_npu_place(kern_pair.first.place_);
});
}
bool SupportMLU() const override {
// TODO(zhiqiu): support phi if needed?
auto& op_kernels = OperatorWithKernel::AllOpKernels().at(type_);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册