Fix py opcode (#118977)

Added a C file that includes the symbols  _PyOpcode_Deopt and _PyOpcode_Caches since they are not available in the python lib but they are available on Linux in order to fix linking issues in Windows in python 3.11.
Fixes #93854

Test by running on python 3.11 `python test/functorch/test_dims.py`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118977
Approved by: https://github.com/ezyang
This commit is contained in:
mantaionut
2024-04-10 02:39:15 +00:00
committed by PyTorch MergeBot
parent b7f898c4a6
commit 247646333e
3 changed files with 9 additions and 3 deletions

View File

@ -6,7 +6,7 @@ include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(FT_DIR csrc)
file(GLOB_RECURSE FT_SOURCES ${FT_DIR}/*.cpp)
file(GLOB_RECURSE FT_SOURCES ${FT_DIR}/*.cpp ${FT_DIR}/*.c)
add_library(${PROJECT_NAME} MODULE ${FT_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1518,14 +1518,14 @@ struct PyInstDecoder {
// On Windows, _PyOpcode_Caches and _PyOpcode_Deopt are private symbols
// See https://github.com/pytorch/pytorch/issues/93854
void next() {
#if IS_PYTHON_3_11_PLUS && !defined(_WIN32)
#if IS_PYTHON_3_11_PLUS
offset_ += _PyOpcode_Caches[opcode()];
#endif
offset_ += 1;
}
int opcode() {
auto r = _Py_OPCODE(code_[offset_]);
#if IS_PYTHON_3_11_PLUS && !defined(_WIN32)
#if IS_PYTHON_3_11_PLUS
r = _PyOpcode_Deopt[r];
#endif
return r;

View File

@ -0,0 +1,6 @@
#include <torch/csrc/utils/python_compat.h>
#if defined(_WIN32) && IS_PYTHON_3_11_PLUS
#define Py_BUILD_CORE
#define NEED_OPCODE_TABLES
#include "internal/pycore_opcode.h"
#endif