Release GIL when assigning to real or imag components (#71747)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71747
The getter is trivial as it's just creating a view tensor, but the
setter is actually copying data so does call into kernel code.
Test Plan: Imported from OSS
Reviewed By: anjali411
Differential Revision: D33770046
Pulled By: albanD
fbshipit-source-id: f0a70acaef790ae1e5b2f68ac4ce046e850c9624
(cherry picked from commit 36a0109400b256b32a185fcd05f21f302197c081)
diff --git a/torch/csrc/autograd/python_variable.cpp b/torch/csrc/autograd/python_variable.cpp
index bec7012..2b16742 100644
--- a/torch/csrc/autograd/python_variable.cpp
+++ b/torch/csrc/autograd/python_variable.cpp
@@ -1061,9 +1061,13 @@
{
HANDLE_TH_ERRORS
auto& self_ = THPVariable_Unpack(self);
- auto self_real = at::real(self_);
- self_real.copy_(THPVariable_Unpack(real));
- return 0;
+ auto& real_ = THPVariable_Unpack(real);
+ {
+ pybind11::gil_scoped_release no_gil;
+ auto self_real = at::real(self_);
+ self_real.copy_(real_);
+ return 0;
+ }
END_HANDLE_TH_ERRORS_RET(-1)
}
@@ -1071,9 +1075,13 @@
{
HANDLE_TH_ERRORS
auto& self_ = THPVariable_Unpack(self);
- auto self_imag = at::imag(self_);
- self_imag.copy_(THPVariable_Unpack(imag));
- return 0;
+ auto& imag_ = THPVariable_Unpack(imag);
+ {
+ pybind11::gil_scoped_release no_gil;
+ auto self_imag = at::imag(self_);
+ self_imag.copy_(imag_);
+ return 0;
+ }
END_HANDLE_TH_ERRORS_RET(-1)
}