Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export AOTI_TORCH_EXPORT on Windows. #140030

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,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
Expand Down
3 changes: 3 additions & 0 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ endif()

if(NOT BUILD_LIBTORCHLESS)
add_library(torch_cpu ${Caffe2_CPU_SRCS})
# target_compile_definitions(torch_cpu PRIVATE -DEXPORT_AOTI_FUNCTIONS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess all the changes here and in the file below are leftovers and should be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albanD sure, this PR was reverted many times, I'm not sure how to pass meta internal CI, so I keep the old code here.
I will clean up code certainly landed.

if(HAVE_SOVERSION)
set_target_properties(torch_cpu PROPERTIES
VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION})
Expand Down Expand Up @@ -958,6 +959,7 @@ elseif(USE_CUDA)
set(CUDA_LINK_LIBRARIES_KEYWORD)
torch_compile_options(torch_cuda) # see cmake/public/utils.cmake
target_compile_definitions(torch_cuda PRIVATE USE_CUDA)
# target_compile_definitions(torch_cuda PRIVATE -DEXPORT_AOTI_FUNCTIONS)

if(USE_CUFILE)
target_link_libraries(torch_cuda PRIVATE torch::cufile)
Expand Down Expand Up @@ -1049,6 +1051,7 @@ if(USE_XPU)
add_library(torch_xpu ${Caffe2_XPU_SRCS})
torch_compile_options(torch_xpu) # see cmake/public/utils.cmake
target_compile_definitions(torch_xpu PRIVATE USE_XPU)
# target_compile_definitions(torch_xpu PRIVATE -DEXPORT_AOTI_FUNCTIONS)
if(WIN32)
target_compile_options(torch_xpu PRIVATE /permissive-)
endif()
Expand Down
1 change: 1 addition & 0 deletions torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ endif()

add_library(torch_python SHARED ${TORCH_PYTHON_SRCS})
torch_compile_options(torch_python) # see cmake/public/utils.cmake
target_compile_definitions(torch_python PRIVATE -DEXPORT_AOTI_FUNCTIONS)
if(APPLE)
target_compile_options(torch_python PRIVATE
$<$<COMPILE_LANGUAGE:CXX>: -fvisibility=default>)
Expand Down
7 changes: 5 additions & 2 deletions torch/csrc/inductor/aoti_torch/c/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
// 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)
#define AOTI_TORCH_EXPORT
#ifdef EXPORT_AOTI_FUNCTIONS
#define AOTI_TORCH_EXPORT __declspec(dllexport)
#else
#define AOTI_TORCH_EXPORT __declspec(dllimport)
#endif
#else // !_WIN32
#define AOTI_TORCH_EXPORT
#endif // _WIN32
Expand Down
Loading