diff options
author | peter <peterghost86@gmail.com> | 2019-01-16 23:31:57 -0800 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-01-16 23:34:32 -0800 |
commit | f7733526aa84af9001fe024117cc66221f9df85e (patch) | |
tree | ebfcb94fd6d62973eeb0486067a0f4e4e5a49860 /torch/CMakeLists.txt | |
parent | 0dfdc2cbdb71b5a8dcac0c3e6cc59b74ad2b30dc (diff) | |
download | pytorch-f7733526aa84af9001fe024117cc66221f9df85e.tar.gz pytorch-f7733526aa84af9001fe024117cc66221f9df85e.tar.bz2 pytorch-f7733526aa84af9001fe024117cc66221f9df85e.zip |
Generate PDB files for better debugging on Windows (#16008)
Summary:
1. Unify `build_pytorch_libs.bat`, `setup.py` and `torch/CMakeLists.txt` on the debugging flags with the `CMAKE_BUILD_TYPE` being `Debug`, `Release` and `RelWithDebInfo`.
2. Install PDBs through CMake if they are generated.
Reference:
1. CMake PDB install: https://gitlab.kitware.com/cmake/cmake/issues/18393#note_459199
2. About debugging flags https://stackoverflow.com/a/4662345
3. MSDN page about /DEBUG flag: https://docs.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info?view=vs-2017
4. MSDN page about /Z{i/I/7}: https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format?view=vs-2017
Work to do:
- [x] Test the changes work in Release config through this PR
- [ ] <del> Test debug build through https://github.com/pytorch/pytorch/pull/16009 </del>
- [x] Test release build with debugging symbols through #16013
Difficulties:
- [x] Replace /Zi flags with /Z7 (which will be added if DEBUG or RelWithDebInfo is used), as it is not supported by sccache
- [x] Resolve `LINK : fatal error LNK1210: exceeded internal ILK size limit; link with /INCREMENTAL:NO` in the debug build
- [ ] DEBUG build blocked by a MSVC bug. In order to resolve it, we'll need to update the MSVC in CI: https://developercommunity.visualstudio.com/content/problem/225957/fatal-error-lnk1318-unexpected-pdb-error-ok-0.html
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16008
Differential Revision: D13709527
Pulled By: ezyang
fbshipit-source-id: e8365bc75d9ec64099093f7001f83d99a06b196b
Diffstat (limited to 'torch/CMakeLists.txt')
-rw-r--r-- | torch/CMakeLists.txt | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index 210b3bc369..9254816036 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -436,6 +436,10 @@ install(TARGETS torch LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}" ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}") +if (MSVC AND NOT TORCH_STATIC) + install(FILES $<TARGET_PDB_FILE:torch> DESTINATION "${TORCH_INSTALL_LIB_DIR}" OPTIONAL) +endif() + if (BUILD_TEST AND NOT MSVC AND NOT USE_ROCM) add_subdirectory(${TORCH_ROOT}/test/cpp/jit ${CMAKE_BINARY_DIR}/test_jit) endif() @@ -598,13 +602,16 @@ if (BUILD_PYTHON) set(TORCH_PYTHON_COMPILE_OPTIONS) - set(TORCH_PYTHON_LINK_FLAGS) + set(TORCH_PYTHON_LINK_FLAGS "") if (MSVC) - list(APPEND TORCH_PYTHON_LINK_FLAGS " /NODEFAULTLIB:LIBCMT.LIB") + string(APPEND TORCH_PYTHON_LINK_FLAGS " /NODEFAULTLIB:LIBCMT.LIB") list(APPEND TORCH_PYTHON_LINK_LIBRARIES ${PYTHON_LIBRARIES}) + if (NOT ${CMAKE_BUILD_TYPE} MATCHES "Release") + string(APPEND TORCH_PYTHON_LINK_FLAGS " /DEBUG:FULL") + endif() elseif (APPLE) - list(APPEND TORCH_PYTHON_LINK_FLAGS " -undefined dynamic_lookup") + string(APPEND TORCH_PYTHON_LINK_FLAGS " -undefined dynamic_lookup") else() list(APPEND TORCH_PYTHON_COMPILE_OPTIONS -fno-strict-aliasing @@ -628,7 +635,6 @@ if (BUILD_PYTHON) if(MSVC) list(APPEND TORCH_PYTHON_LINK_LIBRARIES ${NVTOOLEXT_HOME}/lib/x64/nvToolsExt64_1.lib) list(APPEND TORCH_PYTHON_INCLUDE_DIRECTORIES "${NVTOOLEXT_HOME}/include") - list(APPEND TORCH_PYTHON_LINK_FLAGS " /FORCE:UNRESOLVED") elseif(APPLE) list(APPEND TORCH_PYTHON_LINK_LIBRARIES ${CUDA_TOOLKIT_ROOT_DIR}/lib/libnvToolsExt.dylib) else() @@ -711,8 +717,8 @@ if (BUILD_PYTHON) target_include_directories(torch_python PUBLIC ${TORCH_PYTHON_INCLUDE_DIRECTORIES}) - if (TORCH_PYTHON_LINK_FLAGS) - set_target_properties(torch_python PROPERTIES LINK_FLAGS "${TORCH_PYTHON_LINK_FLAGS}") + if (NOT TORCH_PYTHON_LINK_FLAGS STREQUAL "") + set_target_properties(torch_python PROPERTIES LINK_FLAGS ${TORCH_PYTHON_LINK_FLAGS}) endif() install(TARGETS torch_python |