未验证 提交 84d34ddd 编写于 作者: Y Yuanle Liu 提交者: GitHub

fix bug only on win (#52839)

上级 4c7d5045
...@@ -1241,8 +1241,7 @@ bool AnalysisPredictor::GetFetch(std::vector<paddle::Tensor> *outputs, ...@@ -1241,8 +1241,7 @@ bool AnalysisPredictor::GetFetch(std::vector<paddle::Tensor> *outputs,
for (size_t i = 0; i < fetches_.size(); ++i) { for (size_t i = 0; i < fetches_.size(); ++i) {
auto const &name = idx2fetches_[i]; auto const &name = idx2fetches_[i];
auto &t = framework::GetVariableTensor(*scope, name); auto &t = framework::GetVariableTensor(*scope, name);
(*outputs)[i] = (*outputs)[i] = paddle::Tensor(std::make_shared<phi::DenseTensor>(t), name);
std::move(paddle::Tensor(std::make_shared<phi::DenseTensor>(t), name));
} }
return true; return true;
} }
......
...@@ -770,11 +770,15 @@ PyObject* ToPyObject(const std::vector<std::vector<size_t>>& value) { ...@@ -770,11 +770,15 @@ PyObject* ToPyObject(const std::vector<std::vector<size_t>>& value) {
PyObject* ToPyObject(const std::vector<paddle::Tensor>& value, PyObject* ToPyObject(const std::vector<paddle::Tensor>& value,
bool return_py_none_if_not_initialize) { bool return_py_none_if_not_initialize) {
// NOTE(liuyuanle): I encountered a bug(access violation) in windows. ref to // NOTE(liuyuanle): I encountered a bug(access violation) in windows. ref to
// https://stackoverflow.com/questions/55598839/how-to-fix-access-violation-error-when-returning-pyobject-from-c-function-usin // https://stackoverflow.com/questions/55598839/how-to-fix-access-violation-error-when-returning-pyobject-from-c-function-usin
#ifdef _WIN32
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
#endif
PyObject* result = PyList_New((Py_ssize_t)value.size()); PyObject* result = PyList_New((Py_ssize_t)value.size());
#ifdef _WIN32
PyGILState_Release(gstate); PyGILState_Release(gstate);
#endif
for (size_t i = 0; i < value.size(); i++) { for (size_t i = 0; i < value.size(); i++) {
if (!value[i].initialized() && return_py_none_if_not_initialize) { if (!value[i].initialized() && return_py_none_if_not_initialize) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册