Skip to content

Commit daed864

Browse files
xuhancnpytorchmergebot
authored andcommitted
export AOTI_TORCH_EXPORT on Windows. (pytorch#140030)
Fixes pytorch#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) Pull Request resolved: pytorch#140030 Approved by: https://github.com/jgong5, https://github.com/desertfire
1 parent 81ab2cc commit daed864

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

caffe2/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ endif()
779779

780780
if(NOT BUILD_LIBTORCHLESS)
781781
add_library(torch_cpu ${Caffe2_CPU_SRCS})
782+
target_compile_definitions(torch_cpu PRIVATE -DEXPORT_AOTI_FUNCTIONS)
782783
if(HAVE_SOVERSION)
783784
set_target_properties(torch_cpu PROPERTIES
784785
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
@@ -963,6 +964,7 @@ elseif(USE_CUDA)
963964
set(CUDA_LINK_LIBRARIES_KEYWORD)
964965
torch_compile_options(torch_cuda) # see cmake/public/utils.cmake
965966
target_compile_definitions(torch_cuda PRIVATE USE_CUDA)
967+
target_compile_definitions(torch_cuda PRIVATE -DEXPORT_AOTI_FUNCTIONS)
966968

967969
if(USE_CUFILE)
968970
target_link_libraries(torch_cuda PRIVATE torch::cufile)
@@ -1053,6 +1055,7 @@ if(USE_XPU)
10531055
add_library(torch_xpu ${Caffe2_XPU_SRCS})
10541056
torch_compile_options(torch_xpu) # see cmake/public/utils.cmake
10551057
target_compile_definitions(torch_xpu PRIVATE USE_XPU)
1058+
target_compile_definitions(torch_xpu PRIVATE -DEXPORT_AOTI_FUNCTIONS)
10561059
if(WIN32)
10571060
target_compile_options(torch_xpu PRIVATE /permissive-)
10581061
endif()

torch/csrc/inductor/aoti_torch/c/shim.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
// to symbol clashes at link time if libtorch is included in a DLL and binary
4545
// that depends on the DLL. As a short term fix, we don't export the symbols.
4646
// In the long term, this will need to be addressed when Windows is supported.
47-
// #define AOTI_TORCH_EXPORT __declspec(dllexport)
48-
#define AOTI_TORCH_EXPORT
47+
#ifdef EXPORT_AOTI_FUNCTIONS
48+
#define AOTI_TORCH_EXPORT __declspec(dllexport)
49+
#else
50+
#define AOTI_TORCH_EXPORT __declspec(dllimport)
51+
#endif
4952
#else // !_WIN32
5053
#define AOTI_TORCH_EXPORT
5154
#endif // _WIN32

0 commit comments

Comments
 (0)