未验证 提交 683287ba 编写于 作者: R ronnywang 提交者: GitHub

[CustomDevice] release gil in predictor.run (#55783)

上级 2b258c58
...@@ -650,6 +650,9 @@ void BindPaddlePredictor(py::module *m) { ...@@ -650,6 +650,9 @@ void BindPaddlePredictor(py::module *m) {
paddle_predictor paddle_predictor
.def("run", .def("run",
[](PaddlePredictor &self, const std::vector<PaddleTensor> &inputs) { [](PaddlePredictor &self, const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs; std::vector<PaddleTensor> outputs;
self.Run(inputs, &outputs); self.Run(inputs, &outputs);
return outputs; return outputs;
...@@ -698,6 +701,9 @@ void BindNativePredictor(py::module *m) { ...@@ -698,6 +701,9 @@ void BindNativePredictor(py::module *m) {
.def("run", .def("run",
[](NativePaddlePredictor &self, [](NativePaddlePredictor &self,
const std::vector<PaddleTensor> &inputs) { const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs; std::vector<PaddleTensor> outputs;
self.Run(inputs, &outputs); self.Run(inputs, &outputs);
return outputs; return outputs;
...@@ -1064,6 +1070,9 @@ void BindAnalysisPredictor(py::module *m) { ...@@ -1064,6 +1070,9 @@ void BindAnalysisPredictor(py::module *m) {
.def( .def(
"run", "run",
[](AnalysisPredictor &self, const std::vector<PaddleTensor> &inputs) { [](AnalysisPredictor &self, const std::vector<PaddleTensor> &inputs) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
std::vector<PaddleTensor> outputs; std::vector<PaddleTensor> outputs;
self.Run(inputs, &outputs); self.Run(inputs, &outputs);
return outputs; return outputs;
...@@ -1114,6 +1123,9 @@ void BindPaddleInferPredictor(py::module *m) { ...@@ -1114,6 +1123,9 @@ void BindPaddleInferPredictor(py::module *m) {
.def( .def(
"run", "run",
[](paddle_infer::Predictor &self, py::handle py_in_tensor_list) { [](paddle_infer::Predictor &self, py::handle py_in_tensor_list) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
auto in_tensor_list = auto in_tensor_list =
CastPyArg2VectorOfTensor(py_in_tensor_list.ptr(), 0); CastPyArg2VectorOfTensor(py_in_tensor_list.ptr(), 0);
std::vector<paddle::Tensor> outputs; std::vector<paddle::Tensor> outputs;
...@@ -1121,7 +1133,13 @@ void BindPaddleInferPredictor(py::module *m) { ...@@ -1121,7 +1133,13 @@ void BindPaddleInferPredictor(py::module *m) {
return py::handle(ToPyObject(outputs)); return py::handle(ToPyObject(outputs));
}, },
py::arg("inputs")) py::arg("inputs"))
.def("run", [](paddle_infer::Predictor &self) { self.Run(); }) .def("run",
[](paddle_infer::Predictor &self) {
#if defined(PADDLE_WITH_CUSTOM_DEVICE) && !defined(PADDLE_NO_PYTHON)
pybind11::gil_scoped_release release;
#endif
self.Run();
})
.def("clone", .def("clone",
[](paddle_infer::Predictor &self) { return self.Clone(nullptr); }) [](paddle_infer::Predictor &self) { return self.Clone(nullptr); })
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册