22
33set -ex
44
5+ # The INSTALL_PREFIX here must match up with test.sh
6+ INSTALL_PREFIX=" /usr/local/caffe2"
57LOCAL_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
68ROOT_DIR=$( cd " $LOCAL_DIR " /../.. && pwd)
9+ CMAKE_ARGS=()
10+
711
12+ # Setup SCCACHE
13+ # ##############################################################################
814# Setup sccache if SCCACHE_BUCKET is set
915if [ -n " ${SCCACHE_BUCKET} " ]; then
1016 mkdir -p ./sccache
@@ -61,24 +67,29 @@ report_compile_cache_stats() {
6167 fi
6268}
6369
64- CMAKE_ARGS=(" -DBUILD_BINARY=ON" )
65- CMAKE_ARGS+=(" -DUSE_OBSERVERS=ON" )
66- CMAKE_ARGS+=(" -DUSE_ZSTD=ON" )
6770
68- if [[ $BUILD_ENVIRONMENT == * -aten-* ]]; then
69- if [[ CMAKE_ARGS != * USE_ATEN* ]] && [[ CMAKE_ARGS != * BUILD_ATEN* ]]; then
70- CMAKE_ARGS+=(" -DBUILD_ATEN=ON" )
71- fi
71+ # ##############################################################################
72+ # Explicitly set Python executable.
73+ # ##############################################################################
74+ # On Ubuntu 16.04 the default Python is still 2.7.
75+ PYTHON=" $( which python) "
76+ if [[ " ${BUILD_ENVIRONMENT} " =~ py(( 2 | 3 )\.? [0 - 9 ]? \.? [0 - 9 ]? ) ]]; then
77+ PYTHON=$(which "python${BASH_REMATCH[1]} ")
78+ CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=${PYTHON} ")
7279fi
7380
74- # Run build script from scripts if applicable
81+
82+ ###############################################################################
83+ # Use special scripts for Android, conda, and setup builds
84+ ###############################################################################
7585if [[ "${BUILD_ENVIRONMENT} " == *- android* ]]; then
7686 export ANDROID_NDK=/opt/ndk
87+ CMAKE_ARGS+=("-DBUILD_BINARY=ON")
88+ CMAKE_ARGS+=("-DUSE_OBSERVERS=ON")
89+ CMAKE_ARGS+=("-DUSE_ZSTD=ON")
7790 "${ROOT_DIR} / scripts/ build_android.sh" ${CMAKE_ARGS[*]} "$@ "
7891 exit 0
79- fi
80- if [[ " ${BUILD_ENVIRONMENT} " == conda* ]]; then
81-
92+ elif [[ "${BUILD_ENVIRONMENT} " == conda* ]]; then
8293 # click (required by onnx) wants these set
8394 # TODO don't think this fixes the problem for conda3 yet
8495 export LANG=C.UTF-8
@@ -96,51 +107,50 @@ if [[ "${BUILD_ENVIRONMENT}" == conda* ]]; then
96107 PROTOBUF_INCDIR=/opt/conda/include pip install -b /tmp/pip_install_onnx "file://${ROOT_DIR} / third_party/ onnx#egg= onnx"
97108 report_compile_cache_stats
98109 exit 0
110+ elif [[ $BUILD_ENVIRONMENT == *setup* ]]; then
111+ rm -rf $INSTALL_PREFIX && mkdir $INSTALL_PREFIX
112+ PYTHONPATH=$INSTALL_PREFIX $PYTHON setup_caffe2 .py develop --install-dir $INSTALL_PREFIX
113+ exit 0
99114fi
100115
101- # Run cmake from ./build_caffe2 directory so it doesn't conflict with
102- # standard PyTorch build directory. Eventually these won't need to
103- # be separate.
104- rm -rf build_caffe2
105- mkdir build_caffe2
106- cd ./build_caffe2
107116
108- INSTALL_PREFIX=" /usr/local/caffe2"
117+ ###############################################################################
118+ # Set cmake args
119+ ###############################################################################
120+ CMAKE_ARGS+=("-DBUILD_BINARY=ON")
121+ CMAKE_ARGS+=("-DUSE_OBSERVERS=ON")
122+ CMAKE_ARGS+=("-DUSE_ZSTD=ON")
109123CMAKE_ARGS+=("-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ")
110124
111- # Explicitly set Python executable.
112- # On Ubuntu 16.04 the default Python is still 2.7.
113- PYTHON=" $( which python) "
114- if [[ " ${BUILD_ENVIRONMENT} " =~ py(( 2 | 3 )\.? [0 - 9 ]? \.? [0 - 9 ]? ) ]]; then
115- PYTHON=$(which "python${BASH_REMATCH[1]} ")
116- CMAKE_ARGS+=("-DPYTHON_EXECUTABLE=${PYTHON} ")
125+ if [[ $BUILD_ENVIRONMENT == *-aten-* ]]; then
126+ if [[ CMAKE_ARGS != *USE_ATEN* ]] && [[ CMAKE_ARGS != *BUILD_ATEN* ]]; then
127+ CMAKE_ARGS+=("-DBUILD_ATEN=ON")
128+ fi
117129fi
130+ if [[ $BUILD_ENVIRONMENT == *mkl* ]]; then
131+ CMAKE_ARGS+=("-DBLAS=MKL")
132+ fi
133+ if [[ $BUILD_ENVIRONMENT == *cuda* ]]; then
134+ CMAKE_ARGS+=("-DUSE_CUDA=ON")
135+ CMAKE_ARGS+=("-DCUDA_ARCH_NAME=Maxwell")
136+ CMAKE_ARGS+=("-DUSE_NNPACK=OFF")
137+
138+ # Explicitly set path to NVCC such that the symlink to ccache or sccache is used
139+ CMAKE_ARGS+=("-DCUDA_NVCC_EXECUTABLE=${CACHE_WRAPPER_DIR} / nvcc")
118140
119- case "${BUILD_ENVIRONMENT} " in
120- *-mkl*)
121- CMAKE_ARGS+=("-DBLAS=MKL")
122- ;;
123- *-cuda*)
124- CMAKE_ARGS+=("-DUSE_CUDA=ON")
125- CMAKE_ARGS+=("-DCUDA_ARCH_NAME=Maxwell")
126- CMAKE_ARGS+=("-DUSE_NNPACK=OFF")
127-
128- # Explicitly set path to NVCC such that the symlink to ccache or sccache is used
129- CMAKE_ARGS+=("-DCUDA_NVCC_EXECUTABLE=${CACHE_WRAPPER_DIR} / nvcc")
130-
131- # Ensure FindCUDA.cmake can infer the right path to the CUDA toolkit.
132- # Setting PATH to resolve to the right nvcc alone isn't enough.
133- # See /usr/share/cmake-3 .5 /Modules/FindCUDA.cmake, block at line 589 .
134- export CUDA_PATH="/usr/local/cuda"
135-
136- # Ensure the ccache symlink can still find the real nvcc binary.
137- export PATH="/usr/local/cuda/bin:$PATH "
138- ;;
139- *-rocm*)
140- export LANG=C.UTF-8
141- export LC_ALL=C.UTF-8
142- export HCC_AMDGPU_TARGET=gfx900
143- esac
141+ # Ensure FindCUDA.cmake can infer the right path to the CUDA toolkit.
142+ # Setting PATH to resolve to the right nvcc alone isn't enough.
143+ # See /usr/share/cmake-3 .5 /Modules/FindCUDA.cmake, block at line 589 .
144+ export CUDA_PATH="/usr/local/cuda"
145+
146+ # Ensure the ccache symlink can still find the real nvcc binary.
147+ export PATH="/usr/local/cuda/bin:$PATH "
148+ fi
149+ if [[ $BUILD_ENVIRONMENT == *rocm* ]]; then
150+ export LANG=C.UTF-8
151+ export LC_ALL=C.UTF-8
152+ export HCC_AMDGPU_TARGET=gfx900
153+ fi
144154
145155# Try to include Redis support for Linux builds
146156if [ "$(uname)" == "Linux" ]; then
@@ -154,14 +164,6 @@ if [ "$(uname)" == "Darwin" ]; then
154164 CMAKE_ARGS+=("-DBUILD_CUSTOM_PROTOBUF=ON")
155165fi
156166
157- # We test the presence of cmake3 (for platforms like Centos and Ubuntu 14 .04 )
158- # and use that if so.
159- if [[ -x "$(command -v cmake3 )" ]]; then
160- CMAKE_BINARY=cmake3
161- else
162- CMAKE_BINARY=cmake
163- fi
164-
165167# Use a speciallized onnx namespace in CI to catch hardcoded onnx namespace
166168CMAKE_ARGS+=("-DONNX_NAMESPACE=ONNX_NAMESPACE_FOR_C2 _CI")
167169
@@ -173,17 +175,35 @@ if [[ -n "$INTEGRATED" ]]; then
173175 CMAKE_ARGS+=("-DCAFFE2 _LINK_LOCAL_PROTOBUF=OFF")
174176fi
175177
176- # Configure
177- ${CMAKE_BINARY} "${ROOT_DIR} " ${CMAKE_ARGS[*]} "$@ "
178-
179- # Build
178+ # We test the presence of cmake3 (for platforms like Centos and Ubuntu 14 .04 )
179+ # and use that if so.
180+ if [[ -x "$(command -v cmake3 )" ]]; then
181+ CMAKE_BINARY=cmake3
182+ else
183+ CMAKE_BINARY=cmake
184+ fi
180185# sccache will fail for CUDA builds if all cores are used for compiling
181186if [[ "${BUILD_ENVIRONMENT} " == *- cuda* ]] && [ - n "${SCCACHE} " ]; then
182187 MAX_JOBS=`expr $(nproc) - 1 `
183188else
184189 MAX_JOBS=$(nproc)
185190fi
186191
192+
193+ ###############################################################################
194+ # Configure and make
195+ ###############################################################################
196+ # Run cmake from ./build_caffe2 directory so it doesn't conflict with
197+ # standard PyTorch build directory. Eventually these won't need to
198+ # be separate.
199+ rm -rf build_caffe2
200+ mkdir build_caffe2
201+ cd ./build_caffe2
202+
203+ # Configure
204+ ${CMAKE_BINARY} "${ROOT_DIR} " ${CMAKE_ARGS[*]} "$@ "
205+
206+ # Build
187207if [ "$(uname)" == "Linux" ]; then
188208 make "-j${MAX_JOBS} " install
189209else
193213
194214report_compile_cache_stats
195215
216+
217+ ###############################################################################
218+ # Install ONNX
219+ ###############################################################################
220+
196221# Install ONNX into a local directory
197222pip install --user -b /tmp/pip_install_onnx "file://${ROOT_DIR} / third_party/ onnx#egg= onnx"
198223
0 commit comments