|
|
#pragma once
|
|
|
|
|
|
#include <c10/macros/Export.h>
|
|
|
#include <c10/util/Exception.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TORCH_ASSERT_NO_GIL_WITHOUT_PYTHON_DEP() \
|
|
|
TORCH_INTERNAL_ASSERT( \
|
|
|
!c10::impl::check_python_gil(), \
|
|
|
"Holding GIL before a blocking operation! Please release the GIL before blocking, or see https://github.com/pytorch/pytorch/issues/56297 for how to release the GIL for destructors of objects")
|
|
|
|
|
|
namespace c10::impl {
|
|
|
|
|
|
C10_API bool check_python_gil();
|
|
|
|
|
|
struct C10_API PythonGILHooks {
|
|
|
virtual ~PythonGILHooks() = default;
|
|
|
|
|
|
|
|
|
virtual bool check_python_gil() const = 0;
|
|
|
};
|
|
|
|
|
|
C10_API void SetPythonGILHooks(PythonGILHooks* factory);
|
|
|
|
|
|
|
|
|
|
|
|
struct C10_API PythonGILHooksRegisterer {
|
|
|
explicit PythonGILHooksRegisterer(PythonGILHooks* factory) {
|
|
|
SetPythonGILHooks(factory);
|
|
|
}
|
|
|
PythonGILHooksRegisterer(const PythonGILHooksRegisterer&) = delete;
|
|
|
PythonGILHooksRegisterer(PythonGILHooksRegisterer&&) = delete;
|
|
|
PythonGILHooksRegisterer& operator=(const PythonGILHooksRegisterer&) = delete;
|
|
|
PythonGILHooksRegisterer& operator=(PythonGILHooksRegisterer&&) = delete;
|
|
|
~PythonGILHooksRegisterer() {
|
|
|
SetPythonGILHooks(nullptr);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|