Skip to content

Commit

Permalink
backport patch for torchinductor failures on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Feb 2, 2025
1 parent ceb0114 commit cb47ade
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 15 deletions.
2 changes: 2 additions & 0 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b1493b8712c1fc4ad02b2640c191f3c7f1fc6c9d Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
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 +++---
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0002-Help-find-numpy.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e88ebf63cc47b4471e6be3142cda1c2483b4dc9b Mon Sep 17 00:00:00 2001
From: Mark Harfouche <mark.harfouche@gmail.com>
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 ++++++
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0003-Update-sympy-version.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 3fb6b3704a6359521e186bfd4c6644a56aa08d90 Mon Sep 17 00:00:00 2001
From: Jeongseok Lee <jeongseok@meta.com>
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 +-
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0004-Fix-duplicate-linker-script.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From be785be20dab23d5cee88e13adf40150ce9ead3c Mon Sep 17 00:00:00 2001
From: Jeongseok Lee <jeongseok@meta.com>
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 +++-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e0cb086099287bd51fdbe8e6f847ec2d0646f085 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
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 +-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 7e7547dab6c26e7fd324fde6cb6aad5d57bebcf9 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <ifernando@quansight.com>
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

Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0007-fix-issue-142484.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 63f0d3218792d874650a7926f2b956ecbe74eac0 Mon Sep 17 00:00:00 2001
From: "Zheng, Zhaoqiong" <zhaoqiong.zheng@intel.com>
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
---
Expand Down
2 changes: 1 addition & 1 deletion recipe/patches/0008-Fix-FindOpenBLAS.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 6e00778c46305f6a36670fa99a326c2426203a42 Mon Sep 17 00:00:00 2001
From: Bas Zalmstra <bas@prefix.dev>
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 +++++++++------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 12a4473ae7a47da2a30121f329a2c3c8f3f456c5 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0295752d2c44d86681d0381ef97d42ca0199ca56 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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 +++++++++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From a9ca43e842b6d550a364d62a286bcb161e1e8f04 Mon Sep 17 00:00:00 2001
From: Daniel Petry <dpetry@anaconda.com>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 10ebfd7e5b04d022eab602889b4f06659b12b75a Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 24eece84ed217e14628983f0941c5ec274717b9f Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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 <silvio@traversaro.it>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 93c1af8129efcacb58db9a8f2ec16eb6ec17dfed Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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 <dpetry@anaconda.com>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b5084af57c14cdee26936fdfa6425598e8659eb6 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <h.vetinari@gmx.com>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From 2869f014b34cc01662a9c3542d11d53dafd0bb0a Mon Sep 17 00:00:00 2001
From: Xu Han <xu.han@outlook.com>
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:
<img width="856" alt="image" src="https://github.com/user-attachments/assets/5fc501a9-54e5-45ac-9fb3-509ec11a7abe">

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

0 comments on commit cb47ade

Please sign in to comment.