[FRONTEND] Fix GIL handling in error conditions (#2225)

The use of the opaque GIL state APIs should mean that the
PyErr_SetString is now safe, regardless of whether the caller has the
GIL or not.
This commit is contained in:
Shantanu
2023-09-01 13:30:42 -07:00
committed by GitHub
parent 691c963550
commit a4df60e20a
3 changed files with 9 additions and 0 deletions

View File

@@ -11,7 +11,10 @@ static inline void gpuAssert(CUresult code, const char *file, int line) {
char err[1024] = {0};
strcat(err, prefix);
strcat(err, str);
PyGILState_STATE gil_state;
gil_state = PyGILState_Ensure();
PyErr_SetString(PyExc_RuntimeError, err);
PyGILState_Release(gil_state);
}
}

View File

@@ -13,7 +13,10 @@ static inline void gpuAssert(hipError_t code, const char *file, int line) {
const char *str = hipGetErrorString(code);
char err[1024] = {0};
snprintf(err, 1024, "%s Code: %d, Messsage: %s", prefix, code, str);
PyGILState_STATE gil_state;
gil_state = PyGILState_Ensure();
PyErr_SetString(PyExc_RuntimeError, err);
PyGILState_Release(gil_state);
}
}
}