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

Fix the caffe2_gpu linkage with torch on Windows #16071

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions torch/CMakeLists.txt
Expand Up @@ -413,6 +413,12 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.1")
set_property(TARGET torch PROPERTY CXX_STANDARD 11)
endif()

# Prevent the unused functions being optimized away
# Otherwise torch.dll will be linked without caffe2_gpu.dll
if (MSVC)
set_target_properties(torch PROPERTIES LINK_FLAGS "/OPT:NOREF")
endif(MSVC)

install(DIRECTORY "${TORCH_SRC_DIR}/csrc"
DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch
FILES_MATCHING PATTERN "*.h")
Expand Down
12 changes: 12 additions & 0 deletions torch/csrc/cuda/comm.cpp
Expand Up @@ -18,6 +18,18 @@
#include <cstddef>
#include <vector>


// The following code is used to ensure torch is linked against caffe2_gpu.
#ifdef _MSC_VER
namespace {
#pragma optimize("", off)
int warp_size() {
return at::cuda::warp_size();
}
#pragma optimize("", on)
}
#endif

namespace torch { namespace cuda {
using namespace at;
using namespace torch::autograd;
Expand Down