Skip to content

Commit 794ee6d

Browse files
peterjc123facebook-github-bot
authored andcommitted
Switch to out-source builds for LibTorch
Summary: Pull Request resolved: #21772 Differential Revision: D15839332 Pulled By: yf225 fbshipit-source-id: 017cf61c5682c6a8ffeaf2ca952e1418c27be30e
1 parent 4a2fc00 commit 794ee6d

File tree

8 files changed

+36
-15
lines changed

8 files changed

+36
-15
lines changed

.jenkins/pytorch/test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ test_libtorch() {
163163
python test/cpp/jit/tests_setup.py setup
164164
CPP_BUILD="$PWD/../cpp-build"
165165
if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
166-
"$CPP_BUILD"/caffe2/bin/test_jit
166+
"$CPP_BUILD"/caffe2/build/bin/test_jit
167167
else
168-
"$CPP_BUILD"/caffe2/bin/test_jit "[cpu]"
168+
"$CPP_BUILD"/caffe2/build/bin/test_jit "[cpu]"
169169
fi
170170
python test/cpp/jit/tests_setup.py shutdown
171171
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
172-
OMP_NUM_THREADS=2 TORCH_CPP_TEST_MNIST_PATH="test/cpp/api/mnist" "$CPP_BUILD"/caffe2/bin/test_api
172+
OMP_NUM_THREADS=2 TORCH_CPP_TEST_MNIST_PATH="test/cpp/api/mnist" "$CPP_BUILD"/caffe2/build/bin/test_api
173173
assert_git_not_dirty
174174
fi
175175
}

.jenkins/pytorch/win-test-helpers/build_pytorch.bat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ if not "%USE_CUDA%"=="0" (
102102
if "%BUILD_ENVIRONMENT%"=="" (
103103
echo NOTE: To run `import torch`, please make sure to activate the conda environment by running `call %CONDA_PARENT_DIR%\Miniconda3\Scripts\activate.bat %CONDA_PARENT_DIR%\Miniconda3` in Command Prompt before running Git Bash.
104104
) else (
105-
mv %CD%\build\bin\test_api.exe %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torch\lib
106105
7z a %TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torch %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\caffe2 && python %SCRIPT_HELPERS_DIR%\upload_image.py %TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z
107106
)
108107
)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
call %SCRIPT_HELPERS_DIR%\setup_pytorch_env.bat
22

3-
dir
4-
dir %TMP_DIR_WIN%\build
5-
dir %TMP_DIR_WIN%\build\torch
6-
dir %TMP_DIR_WIN%\build\torch\lib
7-
cd %TMP_DIR_WIN%\build\torch\lib
3+
cd %TMP_DIR_WIN%\build\torch\bin
84
set PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\bin\x64;%TMP_DIR_WIN%\build\torch\lib;%PATH%
95
test_api.exe --gtest_filter="-IntegrationTest.MNIST*"
6+
7+
if errorlevel 1 exit /b 1

caffe2/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,10 @@ if (BUILD_TEST)
10401040
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
10411041
if (INSTALL_TEST)
10421042
install(TARGETS ${test_name} DESTINATION test)
1043-
# Install PDB files for MSVC builds
1044-
if (MSVC AND BUILD_SHARED_LIBS)
1045-
install(FILES $<TARGET_PDB_FILE:${test_name}> DESTINATION test OPTIONAL)
1046-
endif()
1043+
# Install PDB files for MSVC builds
1044+
if (MSVC AND BUILD_SHARED_LIBS)
1045+
install(FILES $<TARGET_PDB_FILE:${test_name}> DESTINATION test OPTIONAL)
1046+
endif()
10471047
endif()
10481048
endforeach()
10491049

cmake/public/cuda.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ if(CUDA_FOUND)
4747
# compiling with, e.g., if a ccache nvcc is fed to us by CUDA_NVCC_EXECUTABLE
4848
# but the PATH is not consistent with CUDA_HOME. It's better safe
4949
# than sorry: make sure everything is consistent.
50+
if(MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio")
51+
# When using Visual Studio, it attempts to lock the whole binary dir when
52+
# `try_run` is called, which will cause the build to fail.
53+
string(RANDOM BUILD_SUFFIX)
54+
set(PROJECT_RANDOM_BINARY_DIR "${PROJECT_BINARY_DIR}/${BUILD_SUFFIX}")
55+
else()
56+
set(PROJECT_RANDOM_BINARY_DIR "${PROJECT_BINARY_DIR}")
57+
endif()
5058
set(file "${PROJECT_BINARY_DIR}/detect_cuda_version.cc")
5159
file(WRITE ${file} ""
5260
"#include <cuda.h>\n"
@@ -56,7 +64,7 @@ if(CUDA_FOUND)
5664
" return 0;\n"
5765
"}\n"
5866
)
59-
try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file}
67+
try_run(run_result compile_result ${PROJECT_RANDOM_BINARY_DIR} ${file}
6068
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
6169
LINK_LIBRARIES ${CUDA_LIBRARIES}
6270
RUN_OUTPUT_VARIABLE cuda_version_from_header

test/cpp/api/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@ if (NOT MSVC)
5757
-Wno-unused-but-set-parameter)
5858
endif()
5959
endif()
60+
61+
if (INSTALL_TEST)
62+
install(TARGETS test_api DESTINATION bin)
63+
# Install PDB files for MSVC builds
64+
if (MSVC AND BUILD_SHARED_LIBS)
65+
install(FILES $<TARGET_PDB_FILE:test_api> DESTINATION bin OPTIONAL)
66+
endif()
67+
endif()

test/cpp/jit/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ if (USE_CUDA)
1717

1818
target_compile_definitions(test_jit PRIVATE USE_CUDA)
1919
endif()
20+
21+
if (INSTALL_TEST)
22+
install(TARGETS test_jit DESTINATION bin)
23+
# Install PDB files for MSVC builds
24+
if (MSVC AND BUILD_SHARED_LIBS)
25+
install(FILES $<TARGET_PDB_FILE:test_jit> DESTINATION bin OPTIONAL)
26+
endif()
27+
endif()

tools/build_libtorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
options = parser.parse_args()
2121

2222
build_caffe2(version=None, cmake_python_library=None, build_python=False,
23-
rerun_cmake=True, cmake_only=False, cmake=CMake('.'))
23+
rerun_cmake=True, cmake_only=False, cmake=CMake('build'))

0 commit comments

Comments
 (0)