Skip to content

Commit 1a797ec

Browse files
ezyangfacebook-github-bot
authored andcommitted
Revert "clean up the build a bit. We no longer need the separate buil… (pytorch#10285)
Summary: …d_libtorch entrypoint (pytorch#9836)" This reverts commit 62e23a1. Pull Request resolved: pytorch#10285 Differential Revision: D9193107 Pulled By: ezyang fbshipit-source-id: de96dce12fdf74410413ae18feee5caf0bed0025
1 parent b640264 commit 1a797ec

File tree

8 files changed

+136
-13
lines changed

8 files changed

+136
-13
lines changed

.jenkins/pytorch/build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fi
7474
WERROR=1 python setup.py install
7575

7676
# Add the test binaries so that they won't be git clean'ed away
77-
git add -f build/bin build/lib
77+
git add -f build/bin
7878

7979
# Testing ATen install
8080
if [[ "$BUILD_ENVIRONMENT" != *cuda* ]]; then
@@ -101,3 +101,11 @@ if [[ "$BUILD_ENVIRONMENT" == *xenial-cuda8-cudnn6-py3* ]]; then
101101
make html
102102
popd
103103
fi
104+
105+
# Test no-Python build
106+
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
107+
echo "Building libtorch"
108+
# NB: Install outside of source directory (at the same level as the root
109+
# pytorch folder) so that it doesn't get cleaned away prior to docker push.
110+
WERROR=1 VERBOSE=1 tools/cpp_build/build_caffe2.sh "$PWD/../cpp-build"
111+
fi

.jenkins/pytorch/macos-build.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ export IMAGE_COMMIT_TAG=${BUILD_ENVIRONMENT}-${IMAGE_COMMIT_ID}
6161

6262
python setup.py install
6363

64-
# this is a bit hacky, but not too bad. Bundle the test binaries into
65-
# the installation directory, so they can catch a free ride on the 7z
66-
# train.
67-
mkdir -p ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build
68-
mv build/{bin,lib} ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build/
69-
7064
# Upload torch binaries when the build job is finished
7165
7z a ${IMAGE_COMMIT_TAG}.7z ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch*
7266
aws s3 cp ${IMAGE_COMMIT_TAG}.7z s3://ossci-macos-build/pytorch/${IMAGE_COMMIT_TAG}.7z --acl public-read

.jenkins/pytorch/macos-test.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,22 @@ test_python_all() {
5050
test_cpp_api() {
5151
# C++ API
5252

53+
# NB: Install outside of source directory (at the same level as the root
54+
# pytorch folder) so that it doesn't get cleaned away prior to docker push.
55+
# But still clean it before we perform our own build.
56+
#
57+
CPP_BUILD="$PWD/../cpp-build"
58+
rm -rf $CPP_BUILD
59+
mkdir -p $CPP_BUILD
60+
WERROR=1 VERBOSE=1 tools/cpp_build/build_caffe2.sh "$CPP_BUILD"
61+
5362
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
5463

5564
# Unfortunately it seems like the test can't load from miniconda3
5665
# without these paths being set
5766
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD/miniconda3/lib"
5867
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/miniconda3/lib"
59-
${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch/test_binaries/build/bin/test_api
68+
"$CPP_BUILD"/caffe2/bin/test_api
6069
}
6170

6271
if [ -z "${JOB_BASE_NAME}" ] || [[ "${JOB_BASE_NAME}" == *-test ]]; then

.jenkins/pytorch/test.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ test_torchvision() {
108108
test_libtorch() {
109109
if [[ "$BUILD_TEST_LIBTORCH" == "1" ]]; then
110110
echo "Testing libtorch"
111+
CPP_BUILD="$PWD/../cpp-build"
111112
if [[ "$BUILD_ENVIRONMENT" == *cuda* ]]; then
112-
./build/bin/test_jit
113+
"$CPP_BUILD"/caffe2/bin/test_jit
113114
else
114-
./build/bin/test_jit "[cpu]"
115+
"$CPP_BUILD"/caffe2/bin/test_jit "[cpu]"
115116
fi
116117
python tools/download_mnist.py --quiet -d test/cpp/api/mnist
117-
OMP_NUM_THREADS=2 ./build/bin/test_api
118+
OMP_NUM_THREADS=2 "$CPP_BUILD"/caffe2/bin/test_api
118119
fi
119120
}
120121

tools/cpp_build/build_caffe2.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
6+
7+
pushd $SCRIPTPATH
8+
source ./build_common.sh
9+
10+
echo "Building Caffe2"
11+
12+
mkdir -p $CAFFE2_BUILDPATH
13+
pushd $CAFFE2_BUILDPATH
14+
15+
cmake -DUSE_CUDA:BOOL=$USE_CUDA \
16+
-DBUILD_TORCH=ON \
17+
-DUSE_OPENMP:BOOL=${USE_OPENMP:ON} \
18+
-DBUILD_CAFFE2=OFF \
19+
-DBUILD_ATEN=ON \
20+
-DBUILD_PYTHON=OFF \
21+
-DBUILD_BINARY=OFF \
22+
-DBUILD_SHARED_LIBS=ON \
23+
-DONNX_NAMESPACE=$ONNX_NAMESPACE \
24+
-DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE \
25+
-DCMAKE_INSTALL_PREFIX:STRING=$INSTALL_PREFIX \
26+
-DCMAKE_INSTALL_MESSAGE=NEVER \
27+
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
28+
-G "$GENERATE" \
29+
$PYTORCHPATH/
30+
$MAKE -j "$JOBS" install
31+
32+
popd
33+
popd

tools/cpp_build/build_common.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
BUILD_PATH="${1:-$SCRIPTPATH/build}"
4+
INSTALL_PREFIX="$BUILD_PATH/install"
5+
PYTORCHPATH="$SCRIPTPATH/../.."
6+
7+
USE_CUDA=0
8+
if [ -x "$(command -v nvcc)" ]; then
9+
USE_CUDA=1
10+
fi
11+
12+
CAFFE2_BUILDPATH="$BUILD_PATH/caffe2"
13+
NANOPB_BUILDPATH="$BUILD_PATH/nanopb"
14+
15+
# Build with Ninja if available. It has much cleaner output.
16+
GENERATE="Unix Makefiles"
17+
MAKE=make
18+
if [ -x "$(command -v ninja)" ]; then
19+
GENERATE=Ninja
20+
MAKE=ninja
21+
fi
22+
23+
# Code is developed a lot more than released, so default to Debug.
24+
BUILD_TYPE=${BUILD_TYPE:-Debug}
25+
26+
# Try to build with as many threads as we have cores, default to 4 if the
27+
# command fails.
28+
set +e
29+
if [ -n "$MAX_JOBS" ]; then # Use MAX_JOBS if it is set
30+
JOBS=$MAX_JOBS
31+
elif [[ "$(uname)" == "Linux" ]]; then
32+
# https://stackoverflow.com/questions/6481005/how-to-obtain-the-number-of-cpus-cores-in-linux-from-the-command-line
33+
JOBS="$(grep -c '^processor' /proc/cpuinfo)"
34+
else # if [[ "$(uname)" == "Darwin"]]
35+
# https://stackoverflow.com/questions/1715580/how-to-discover-number-of-logical-cores-on-mac-os-x
36+
JOBS="$(sysctl -n hw.ncpu)"
37+
fi
38+
set -e
39+
if [[ $? -ne 0 ]]; then
40+
JOBS=4
41+
fi
42+
43+
# Make sure an ONNX namespace is set
44+
if [ -z "$ONNX_NAMESPACE" ]; then
45+
ONNX_NAMESPACE="onnx_torch"
46+
fi

tools/cpp_build/build_libtorch.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
6+
7+
pushd $SCRIPTPATH
8+
source ./build_common.sh
9+
10+
echo "Building Torch"
11+
12+
mkdir -p $LIBTORCH_BUILDPATH
13+
pushd $LIBTORCH_BUILDPATH
14+
15+
cmake -DUSE_CUDA:BOOL=$USE_CUDA \
16+
-DNO_API:BOOL=${NO_API:-0} \
17+
-DCAFFE2_PATH=$PYTORCHPATH/ \
18+
-DCAFFE2_BUILD_PATH=$CAFFE2_BUILDPATH \
19+
-DONNX_NAMESPACE=$ONNX_NAMESPACE \
20+
-DNANOPB_BUILD_PATH=$NANOPB_BUILDPATH \
21+
-DINSTALL_PREFIX=$INSTALL_PREFIX \
22+
-DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE \
23+
-DCMAKE_INSTALL_PREFIX:STRING=$INSTALL_PREFIX \
24+
-DCMAKE_INSTALL_MESSAGE=NEVER \
25+
-Dnanopb_BUILD_GENERATOR:BOOL=OFF \
26+
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
27+
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
28+
-DVERBOSE:BOOL=${VERBOSE:-0} \
29+
-G "$GENERATE" \
30+
$PYTORCHPATH/torch
31+
$MAKE -j "$JOBS"
32+
33+
popd
34+
popd

torch/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ if (BUILD_TORCH_TEST AND NOT MSVC AND NOT APPLE AND NOT USE_ROCM)
389389
if (USE_CUDA)
390390
target_link_libraries(test_jit ${CUDA_LIBRARIES})
391391
endif()
392-
393392
endif()
394393

395394
if (BUILD_TORCH_TEST AND NOT NO_API AND NOT USE_ROCM)
@@ -438,5 +437,4 @@ if (BUILD_TORCH_TEST AND NOT NO_API AND NOT USE_ROCM)
438437
-Wno-unused-but-set-parameter)
439438
endif()
440439
endif()
441-
442440
endif()

0 commit comments

Comments
 (0)