mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This reverts commit 05ee8114f818a95745c812c3cd7aa8e784e61a9a. Reverted https://github.com/pytorch/pytorch/pull/162659 on behalf of https://github.com/jeanschmidt due to seems to have introduced errors in linting see https://github.com/pytorch/pytorch/actions/runs/17750689989/job/50444910643 ([comment](https://github.com/pytorch/pytorch/pull/162659#issuecomment-3298626136))
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <c10/core/impl/PyInterpreter.h>
|
|
#include <c10/macros/Export.h>
|
|
#include <c10/util/Registry.h>
|
|
#include <memory>
|
|
|
|
namespace c10::impl {
|
|
|
|
// Minimal interface for PyInterpreter hooks
|
|
struct C10_API PyInterpreterHooksInterface {
|
|
virtual ~PyInterpreterHooksInterface() = default;
|
|
|
|
// Get the PyInterpreter instance
|
|
// Stub implementation throws error when Python is not available
|
|
virtual PyInterpreter* getPyInterpreter() const {
|
|
TORCH_CHECK(
|
|
false,
|
|
"PyTorch was compiled without Python support. "
|
|
"Cannot access Python interpreter from C++.");
|
|
}
|
|
};
|
|
|
|
struct C10_API PyInterpreterHooksArgs{};
|
|
|
|
C10_DECLARE_REGISTRY(
|
|
PyInterpreterHooksRegistry,
|
|
PyInterpreterHooksInterface,
|
|
PyInterpreterHooksArgs);
|
|
|
|
#define REGISTER_PYTHON_HOOKS(clsname) \
|
|
C10_REGISTER_CLASS(PyInterpreterHooksRegistry, clsname, clsname)
|
|
|
|
// Get the global PyInterpreter hooks instance
|
|
C10_API const PyInterpreterHooksInterface& getPyInterpreterHooks();
|
|
|
|
C10_API PyInterpreter* getGlobalPyInterpreter();
|
|
|
|
} // namespace c10::impl
|