Fix pijit core dump problem

This commit is contained in:
liangzhibo 2024-02-06 10:10:27 +08:00 committed by r1chardf1d0
parent 973c41fb50
commit 6825823414
4 changed files with 19 additions and 0 deletions

View File

@ -871,6 +871,11 @@ static bool JitCompile(PyThreadState *tstate, JitCompileResults *c) {
PyFrameObject *f = PrepareCallCompiledCallable(tstate, c->origin_frame_, c);
frame = py::reinterpret_steal<py::object>(reinterpret_cast<PyObject *>(f));
}
if (c->conf->GetBoolConfig(GraphJitConfig::kTraceFlag)) {
PyFrameObject *f = reinterpret_cast<PyFrameObject *>(frame.ptr());
GuardForFrame(f, c->code, *c->conf);
AddGuardForGlobals(f, c->code->GetGuard(), c->conf->GetBoolConfig(GraphJitConfig::kGuardDetachObject));
}
}
if (c->stat == JitCompileResults::GRAPH_CAPTURED) {
@ -1403,6 +1408,8 @@ PyObject *EvalFrame(PyThreadState *tstate, PyFrameObject *f, int exc) {
<< std::string(py::str(reinterpret_cast<PyObject *>(f->f_code)));
e.restore();
} catch (const std::exception &) {
PyErr_SetString(PyExc_RuntimeError, "CodeHook Failed for one stage");
}
if (PyErr_Occurred()) {
res = py::object();

View File

@ -315,6 +315,9 @@ class AbstractTraceNode : public AbstractObject {
explicit AbstractTraceNode(Type type, const py::object &o) : AbstractObject(type, o) {}
virtual ~AbstractTraceNode() {}
static AObject *MakeAObject(const py::object &o) {
if (o.ptr() == nullptr) {
return AObject::MakeAObject(AObject::kTypeAnyValue);
}
auto node = aobject_mem_pool_.New<AbstractObject>(kTypeTraceNode, o);
node->SetTypeObject(Py_TYPE(o.ptr()));
return node;

View File

@ -1064,6 +1064,9 @@ py::object MindCodeBreakGenerator::MakeCopyCode(const std::string &co_name, int
auto b = std::dynamic_pointer_cast<MindGraphBuilder>(builder_);
MS_EXCEPTION_IF_NULL(b);
auto func_graph = FGBuilder()->graph();
if (func_graph == nullptr) {
MS_LOG(EXCEPTION) << "Get function graph from function graph builder failed.";
}
std::string phase =
py::cast<std::string>(co_->co_filename) + "_" + std::to_string(co_->co_firstlineno) + "_" + co_name;
const auto &parameters = func_graph->parameters();

View File

@ -2491,6 +2491,9 @@ bool GraphBuilder::HandlePositionParams(const py::object &func, std::vector<Valu
}
bool GraphBuilder::HandleCallParameters(const py::object &func_info, CallNode *call_node, FrameStates *frame) {
if (func_info.ptr() == nullptr) {
MS_LOG(EXCEPTION) << "HandleCallParameters with empty func_info input.";
}
PyCodeObject *co = reinterpret_cast<PyCodeObject *>(PyFunction_GET_CODE(func_info.ptr()));
frame->ResizeLocal(co->co_nlocals);
@ -2691,6 +2694,9 @@ AObject *MindGraphBuilder::HandleMultiOp(const Instr &instr, const std::vector<V
return AObject::MakeAObject(AObject::kTypeAnyValue);
}
auto node = fg_builder_->AddMultiNode(op_name, input_obj);
if (node.ptr() == nullptr) {
return AObject::MakeAObject(AObject::kTypeAnyValue);
}
return AbstractTraceNode::MakeAObject(node);
}