From cb47ade33f1041fe63fbe49707d1939a5cca97e9 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 2 Feb 2025 17:35:51 +1100 Subject: [PATCH] backport patch for torchinductor failures on windows --- recipe/meta.yaml | 2 + ...-of-python-3-and-error-without-numpy.patch | 2 +- recipe/patches/0002-Help-find-numpy.patch | 2 +- .../patches/0003-Update-sympy-version.patch | 2 +- .../0004-Fix-duplicate-linker-script.patch | 2 +- ...-Allow-overriding-CUDA-related-paths.patch | 2 +- ...AS_USE_CBLAS_DOT-for-OpenBLAS-builds.patch | 2 +- recipe/patches/0007-fix-issue-142484.patch | 2 +- recipe/patches/0008-Fix-FindOpenBLAS.patch | 2 +- ...tils.cpp_extension.include_paths-use.patch | 2 +- ...oint-include-paths-to-PREFIX-include.patch | 2 +- ...nda-prefix-to-inductor-include-paths.patch | 2 +- ...E_DIR-relative-to-TORCH_INSTALL_PREF.patch | 2 +- ...ON-lib-from-CMake-install-TARGETS-di.patch | 2 +- ...e-in-test_mutable_custom_op_fixed_la.patch | 2 +- ...-find_package-CUDA-in-caffe2-CMake-m.patch | 2 +- ...AOTI_TORCH_EXPORT-on-Windows.-140030.patch | 66 +++++++++++++++++++ 17 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 recipe/patches/0016-export-AOTI_TORCH_EXPORT-on-Windows.-140030.patch diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 9a554e38..476526f6 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -59,6 +59,8 @@ source: - patches/0013-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch # [win] - patches/0014-make-library-name-in-test_mutable_custom_op_fixed_la.patch - patches/0015-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch + # backport https://github.com/pytorch/pytorch/pull/140030 + - patches/0016-export-AOTI_TORCH_EXPORT-on-Windows.-140030.patch - patches_submodules/fbgemm/0001-remove-DESTINATION-lib-from-CMake-install-directives.patch # [win] - patches_submodules/tensorpipe/0001-switch-away-from-find_package-CUDA.patch # backport https://github.com/google/XNNPACK/commit/5f23827e66cca435fa400b6e221892ac95af0079 diff --git a/recipe/patches/0001-Force-usage-of-python-3-and-error-without-numpy.patch b/recipe/patches/0001-Force-usage-of-python-3-and-error-without-numpy.patch index 5f175049..716cafec 100644 --- a/recipe/patches/0001-Force-usage-of-python-3-and-error-without-numpy.patch +++ b/recipe/patches/0001-Force-usage-of-python-3-and-error-without-numpy.patch @@ -1,7 +1,7 @@ From b1493b8712c1fc4ad02b2640c191f3c7f1fc6c9d Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 1 Sep 2024 17:35:40 -0400 -Subject: [PATCH 01/15] Force usage of python 3 and error without numpy +Subject: [PATCH 01/16] Force usage of python 3 and error without numpy --- cmake/Dependencies.cmake | 6 +++--- diff --git a/recipe/patches/0002-Help-find-numpy.patch b/recipe/patches/0002-Help-find-numpy.patch index 653c4b5d..26bb6ac8 100644 --- a/recipe/patches/0002-Help-find-numpy.patch +++ b/recipe/patches/0002-Help-find-numpy.patch @@ -1,7 +1,7 @@ From e88ebf63cc47b4471e6be3142cda1c2483b4dc9b Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 1 Oct 2024 00:28:40 -0400 -Subject: [PATCH 02/15] Help find numpy +Subject: [PATCH 02/16] Help find numpy --- tools/setup_helpers/cmake.py | 6 ++++++ diff --git a/recipe/patches/0003-Update-sympy-version.patch b/recipe/patches/0003-Update-sympy-version.patch index 52df04c9..89a20693 100644 --- a/recipe/patches/0003-Update-sympy-version.patch +++ b/recipe/patches/0003-Update-sympy-version.patch @@ -1,7 +1,7 @@ From 3fb6b3704a6359521e186bfd4c6644a56aa08d90 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Thu, 17 Oct 2024 15:04:05 -0700 -Subject: [PATCH 03/15] Update sympy version +Subject: [PATCH 03/16] Update sympy version --- setup.py | 2 +- diff --git a/recipe/patches/0004-Fix-duplicate-linker-script.patch b/recipe/patches/0004-Fix-duplicate-linker-script.patch index 8458e4a8..13aeaf09 100644 --- a/recipe/patches/0004-Fix-duplicate-linker-script.patch +++ b/recipe/patches/0004-Fix-duplicate-linker-script.patch @@ -1,7 +1,7 @@ From be785be20dab23d5cee88e13adf40150ce9ead3c Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Sun, 3 Nov 2024 01:12:36 -0700 -Subject: [PATCH 04/15] Fix duplicate linker script +Subject: [PATCH 04/16] Fix duplicate linker script --- setup.py | 4 +++- diff --git a/recipe/patches/0005-Allow-overriding-CUDA-related-paths.patch b/recipe/patches/0005-Allow-overriding-CUDA-related-paths.patch index 23d83bab..a349fb8a 100644 --- a/recipe/patches/0005-Allow-overriding-CUDA-related-paths.patch +++ b/recipe/patches/0005-Allow-overriding-CUDA-related-paths.patch @@ -1,7 +1,7 @@ From e0cb086099287bd51fdbe8e6f847ec2d0646f085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 27 Nov 2024 13:47:23 +0100 -Subject: [PATCH 05/15] Allow overriding CUDA-related paths +Subject: [PATCH 05/16] Allow overriding CUDA-related paths --- cmake/Modules/FindCUDAToolkit.cmake | 2 +- diff --git a/recipe/patches/0006-Use-BLAS_USE_CBLAS_DOT-for-OpenBLAS-builds.patch b/recipe/patches/0006-Use-BLAS_USE_CBLAS_DOT-for-OpenBLAS-builds.patch index 2ababacc..d2672ba5 100644 --- a/recipe/patches/0006-Use-BLAS_USE_CBLAS_DOT-for-OpenBLAS-builds.patch +++ b/recipe/patches/0006-Use-BLAS_USE_CBLAS_DOT-for-OpenBLAS-builds.patch @@ -1,7 +1,7 @@ From 7e7547dab6c26e7fd324fde6cb6aad5d57bebcf9 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 18 Dec 2024 03:59:00 +0000 -Subject: [PATCH 06/15] Use BLAS_USE_CBLAS_DOT for OpenBLAS builds +Subject: [PATCH 06/16] Use BLAS_USE_CBLAS_DOT for OpenBLAS builds There are two calling conventions for *dotu functions diff --git a/recipe/patches/0007-fix-issue-142484.patch b/recipe/patches/0007-fix-issue-142484.patch index 30674b10..1b651ad2 100644 --- a/recipe/patches/0007-fix-issue-142484.patch +++ b/recipe/patches/0007-fix-issue-142484.patch @@ -1,7 +1,7 @@ From 63f0d3218792d874650a7926f2b956ecbe74eac0 Mon Sep 17 00:00:00 2001 From: "Zheng, Zhaoqiong" Date: Fri, 27 Dec 2024 13:49:36 +0800 -Subject: [PATCH 07/15] fix issue 142484 +Subject: [PATCH 07/16] fix issue 142484 From https://github.com/pytorch/pytorch/pull/143894 --- diff --git a/recipe/patches/0008-Fix-FindOpenBLAS.patch b/recipe/patches/0008-Fix-FindOpenBLAS.patch index 6a430787..5c684414 100644 --- a/recipe/patches/0008-Fix-FindOpenBLAS.patch +++ b/recipe/patches/0008-Fix-FindOpenBLAS.patch @@ -1,7 +1,7 @@ From 6e00778c46305f6a36670fa99a326c2426203a42 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Thu, 16 May 2024 10:46:49 +0200 -Subject: [PATCH 08/15] Fix FindOpenBLAS +Subject: [PATCH 08/16] Fix FindOpenBLAS --- cmake/Modules/FindOpenBLAS.cmake | 15 +++++++++------ diff --git a/recipe/patches/0009-simplify-torch.utils.cpp_extension.include_paths-use.patch b/recipe/patches/0009-simplify-torch.utils.cpp_extension.include_paths-use.patch index 8b898e57..025dd311 100644 --- a/recipe/patches/0009-simplify-torch.utils.cpp_extension.include_paths-use.patch +++ b/recipe/patches/0009-simplify-torch.utils.cpp_extension.include_paths-use.patch @@ -1,7 +1,7 @@ From 12a4473ae7a47da2a30121f329a2c3c8f3f456c5 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 23 Jan 2025 22:46:58 +1100 -Subject: [PATCH 09/15] simplify torch.utils.cpp_extension.include_paths; use +Subject: [PATCH 09/16] simplify torch.utils.cpp_extension.include_paths; use it in cpp_builder The /TH headers have not existed since pytorch 1.11 diff --git a/recipe/patches/0010-point-include-paths-to-PREFIX-include.patch b/recipe/patches/0010-point-include-paths-to-PREFIX-include.patch index 7c5efb37..73ffc461 100644 --- a/recipe/patches/0010-point-include-paths-to-PREFIX-include.patch +++ b/recipe/patches/0010-point-include-paths-to-PREFIX-include.patch @@ -1,7 +1,7 @@ From 0295752d2c44d86681d0381ef97d42ca0199ca56 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 23 Jan 2025 22:58:14 +1100 -Subject: [PATCH 10/15] point include paths to $PREFIX/include +Subject: [PATCH 10/16] point include paths to $PREFIX/include --- torch/utils/cpp_extension.py | 9 +++++++++ diff --git a/recipe/patches/0011-Add-conda-prefix-to-inductor-include-paths.patch b/recipe/patches/0011-Add-conda-prefix-to-inductor-include-paths.patch index b637adc6..92de63a7 100644 --- a/recipe/patches/0011-Add-conda-prefix-to-inductor-include-paths.patch +++ b/recipe/patches/0011-Add-conda-prefix-to-inductor-include-paths.patch @@ -1,7 +1,7 @@ From a9ca43e842b6d550a364d62a286bcb161e1e8f04 Mon Sep 17 00:00:00 2001 From: Daniel Petry Date: Tue, 21 Jan 2025 17:45:23 -0600 -Subject: [PATCH 11/15] Add conda prefix to inductor include paths +Subject: [PATCH 11/16] Add conda prefix to inductor include paths Currently inductor doesn't look in conda's includes and libs. This results in errors when it tries to compile, if system versions are being used of diff --git a/recipe/patches/0012-make-ATEN_INCLUDE_DIR-relative-to-TORCH_INSTALL_PREF.patch b/recipe/patches/0012-make-ATEN_INCLUDE_DIR-relative-to-TORCH_INSTALL_PREF.patch index 36cddbe1..f6fc082c 100644 --- a/recipe/patches/0012-make-ATEN_INCLUDE_DIR-relative-to-TORCH_INSTALL_PREF.patch +++ b/recipe/patches/0012-make-ATEN_INCLUDE_DIR-relative-to-TORCH_INSTALL_PREF.patch @@ -1,7 +1,7 @@ From 10ebfd7e5b04d022eab602889b4f06659b12b75a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 28 Jan 2025 14:15:34 +1100 -Subject: [PATCH 12/15] make ATEN_INCLUDE_DIR relative to TORCH_INSTALL_PREFIX +Subject: [PATCH 12/16] make ATEN_INCLUDE_DIR relative to TORCH_INSTALL_PREFIX we cannot set CMAKE_INSTALL_PREFIX without the pytorch build complaining, but we can use TORCH_INSTALL_PREFIX, which is set correctly relative to our CMake files already: diff --git a/recipe/patches/0013-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch b/recipe/patches/0013-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch index 3a6f9915..8da32aad 100644 --- a/recipe/patches/0013-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch +++ b/recipe/patches/0013-remove-DESTINATION-lib-from-CMake-install-TARGETS-di.patch @@ -1,7 +1,7 @@ From 24eece84ed217e14628983f0941c5ec274717b9f Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 28 Jan 2025 10:58:29 +1100 -Subject: [PATCH 13/15] remove `DESTINATION lib` from CMake `install(TARGETS` +Subject: [PATCH 13/16] remove `DESTINATION lib` from CMake `install(TARGETS` directives Suggested-By: Silvio Traversaro diff --git a/recipe/patches/0014-make-library-name-in-test_mutable_custom_op_fixed_la.patch b/recipe/patches/0014-make-library-name-in-test_mutable_custom_op_fixed_la.patch index 5bbdbb88..5aed8a27 100644 --- a/recipe/patches/0014-make-library-name-in-test_mutable_custom_op_fixed_la.patch +++ b/recipe/patches/0014-make-library-name-in-test_mutable_custom_op_fixed_la.patch @@ -1,7 +1,7 @@ From 93c1af8129efcacb58db9a8f2ec16eb6ec17dfed Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 30 Jan 2025 13:23:14 +1100 -Subject: [PATCH 14/15] make library name in +Subject: [PATCH 14/16] make library name in `test_mutable_custom_op_fixed_layout{,2}` unique Suggested-By: Daniel Petry diff --git a/recipe/patches/0015-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch b/recipe/patches/0015-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch index 51e98bbe..8e7feb41 100644 --- a/recipe/patches/0015-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch +++ b/recipe/patches/0015-avoid-deprecated-find_package-CUDA-in-caffe2-CMake-m.patch @@ -1,7 +1,7 @@ From b5084af57c14cdee26936fdfa6425598e8659eb6 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 30 Jan 2025 08:33:44 +1100 -Subject: [PATCH 15/15] avoid deprecated `find_package(CUDA)` in caffe2 CMake +Subject: [PATCH 15/16] avoid deprecated `find_package(CUDA)` in caffe2 CMake metadata vendor the not-available-anymore function torch_cuda_get_nvcc_gencode_flag from CMake diff --git a/recipe/patches/0016-export-AOTI_TORCH_EXPORT-on-Windows.-140030.patch b/recipe/patches/0016-export-AOTI_TORCH_EXPORT-on-Windows.-140030.patch new file mode 100644 index 00000000..7c85e1ad --- /dev/null +++ b/recipe/patches/0016-export-AOTI_TORCH_EXPORT-on-Windows.-140030.patch @@ -0,0 +1,66 @@ +From 2869f014b34cc01662a9c3542d11d53dafd0bb0a Mon Sep 17 00:00:00 2001 +From: Xu Han +Date: Wed, 15 Jan 2025 23:43:41 +0000 +Subject: [PATCH 16/16] export AOTI_TORCH_EXPORT on Windows. (#140030) + +Fixes #139954 + +reproduce UT: +```cmd +pytest test/inductor/test_torchinductor_codegen_dynamic_shapes.py -k test_device_assert_dynamic_shapes_cpu +``` +Issue: +image + +After fixing: +![Image](https://github.com/user-attachments/assets/883846fb-8e92-4b9c-9400-daab32382a3a) + +Reland: +1. Declare export on Windows explicitly. +2. Support cpu, cuda and xpu devices. + +Pull Request resolved: https://github.com/pytorch/pytorch/pull/140030 +Approved by: https://github.com/jgong5, https://github.com/desertfire, https://github.com/malfet + +Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com> +--- + CMakeLists.txt | 3 +++ + torch/csrc/inductor/aoti_torch/c/shim.h | 10 +++++++++- + 2 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c8af5f00b5c..c1733a99e91 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1097,6 +1097,9 @@ if(NOT MSVC) + append_cxx_flag_if_supported("-Wno-error=redundant-move" CMAKE_CXX_FLAGS) + endif() + else() ++ # Define export functions for AOTI. ++ add_compile_definitions(EXPORT_AOTI_FUNCTIONS) ++ + # skip unwanted includes from windows.h + add_compile_definitions(WIN32_LEAN_AND_MEAN) + # Windows SDK broke compatibility since version 25131, but introduced this +diff --git a/torch/csrc/inductor/aoti_torch/c/shim.h b/torch/csrc/inductor/aoti_torch/c/shim.h +index 4c6c9afcacc..b2202b24b91 100644 +--- a/torch/csrc/inductor/aoti_torch/c/shim.h ++++ b/torch/csrc/inductor/aoti_torch/c/shim.h +@@ -44,8 +44,16 @@ + // to symbol clashes at link time if libtorch is included in a DLL and binary + // that depends on the DLL. As a short term fix, we don't export the symbols. + // In the long term, this will need to be addressed when Windows is supported. +-// #define AOTI_TORCH_EXPORT __declspec(dllexport) ++#ifdef OVRSOURCE ++// Do not export AOTI on Windows for internal builds + #define AOTI_TORCH_EXPORT ++#else /* OVRSOURCE */ ++#ifdef EXPORT_AOTI_FUNCTIONS ++#define AOTI_TORCH_EXPORT __declspec(dllexport) ++#else ++#define AOTI_TORCH_EXPORT __declspec(dllimport) ++#endif ++#endif /* OVRSOURCE */ + #else // !_WIN32 + #define AOTI_TORCH_EXPORT + #endif // _WIN32