|
#pragma once |
|
|
|
#include <c10/util/Exception.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace c10 { |
|
|
|
#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 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() { |
|
SetPythonGILHooks(nullptr); |
|
} |
|
}; |
|
|
|
} |
|
} |
|
|