clean up GIL usuage (#32748)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32748

This is to follow up PR #30630, we need to have GIL when calling jit::toPyObject(), for some binded functions need to be taged with GIL release if underneath C++ codes requires GIL. so
1. pyRef::to_here() and pyRef::local_value() added GIL
2. pyRef::pickle and pyRef::unpickle() added GIL release tag
3. in request_callback_impl, also added GIL as needed
4. for typeParser, use cached jitCompilationUnit_, also clean it up in cleanUp() function
ghstack-source-id: 97373011

Test Plan: unit test

Differential Revision: D19612337

fbshipit-source-id: 4d09f9b52ba626545ae7d31fea6b671301ed3890
This commit is contained in:
Yanli Zhao
2020-01-29 11:51:30 -08:00
committed by Facebook Github Bot
parent eab99ab08e
commit b5d8982ae2
5 changed files with 49 additions and 47 deletions

View File

@ -25,8 +25,7 @@ struct PythonTypeResolver : public jit::script::Resolver {
if (name == "PyObject") {
return PyObjectType::get();
}
auto python_cu = torch::jit::get_python_cu();
return python_cu->get_type(name);
return PythonRpcHandler::getInstance().jitCompilationUnit()->get_type(name);
}
};
@ -61,6 +60,7 @@ void PythonRpcHandler::cleanup() {
pySerialize_ = py::none();
pyHandleException_ = py::none();
jitCompilationUnit_ = nullptr;
typeParser_ = nullptr;
}
PythonRpcHandler& PythonRpcHandler::getInstance() {