mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Better approach to https://github.com/pytorch/pytorch/pull/158171, according to https://github.com/python/cpython/issues/137178#issuecomment-3131617493. Pull Request resolved: https://github.com/pytorch/pytorch/pull/159369 Approved by: https://github.com/Skylion007
61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
#pragma once
|
|
#include <stdbool.h>
|
|
|
|
#include <torch/csrc/dynamo/extra_state.h>
|
|
#include <torch/csrc/utils/python_compat.h>
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
PyObject* torch_c_dynamo_eval_frame_init(void);
|
|
|
|
#endif
|
|
|
|
// All the eval APIs change in 3.11 so we need to decide which one to use on the
|
|
// fly https://docs.python.org/3/c-api/init.html#c._PyFrameEvalFunction
|
|
#if IS_PYTHON_3_11_PLUS
|
|
#define THP_EVAL_API_FRAME_OBJECT _PyInterpreterFrame
|
|
#else
|
|
#define THP_EVAL_API_FRAME_OBJECT PyFrameObject
|
|
#endif // IS_PYTHON_3_11_PLUS
|
|
|
|
// We need to be able to return the _PyInterpreterFrame to python so create
|
|
// a python binding for it
|
|
|
|
typedef struct THPPyInterpreterFrame {
|
|
PyObject_HEAD
|
|
THP_EVAL_API_FRAME_OBJECT* frame; // Borrowed reference
|
|
PyObject* locals;
|
|
} THPPyInterpreterFrame;
|
|
|
|
THPPyInterpreterFrame* THPPyInterpreterFrame_New(
|
|
THP_EVAL_API_FRAME_OBJECT* frame);
|
|
|
|
extern bool is_skip_guard_eval_unsafe;
|
|
|
|
void clear_old_frame_if_python_312_plus(
|
|
PyThreadState* tstate,
|
|
THP_EVAL_API_FRAME_OBJECT* frame);
|
|
|
|
void eval_frame_callback_set(PyObject* obj);
|
|
|
|
const char* get_frame_name(THP_EVAL_API_FRAME_OBJECT* frame);
|
|
|
|
PyObject* dynamo_eval_frame_default(
|
|
PyThreadState* tstate,
|
|
THP_EVAL_API_FRAME_OBJECT* frame,
|
|
int throw_flag);
|
|
|
|
PyObject* dynamo_eval_custom_code(
|
|
PyThreadState* tstate,
|
|
THP_EVAL_API_FRAME_OBJECT* frame,
|
|
PyCodeObject* code,
|
|
const char* trace_annotation,
|
|
int throw_flag);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|