@@ -55,6 +55,40 @@ UTILS=/utils
5555COMMON_UTILS=/common_utils
5656PYTORCH_FINAL_PACKAGE_DIR=/artifacts
5757
58+ # Enable ccache support by default; disable via env var or command line flag
59+ # NOTE: The intention is to have a project-specific cache directory that we cache build artefacts
60+ # inside and can be easily wiped. These build artefacts are specific to the manylinux builder
61+ # container (and thus compilers) that we use to build the torch wheel. As such, you may not want
62+ # to populate the global ccache cache with them. However, if you wish to do so, simply set
63+ # CCACHE_HOST_DIR to that directory.
64+ USE_CCACHE=${USE_CCACHE:- 1}
65+ if [[ " $* " == * --enable-ccache* ]]; then USE_CCACHE=1; fi
66+ if [[ " $* " == * --disable-ccache* ]]; then USE_CCACHE=0; fi
67+ CCACHE_HOST_DIR=${CCACHE_HOST_DIR:- " ${PWD} /.ccache" }
68+ CCACHE_ROOT=/.ccache
69+ CCACHE_MAXSIZE=${CCACHE_MAXSIZE:- }
70+
71+ # If the user wants to use ccache for build caching
72+ ccache_args=(-e USE_CCACHE=" ${USE_CCACHE} " )
73+ if [ " ${USE_CCACHE} " == " 1" ]; then
74+ echo " Using ccache for build caching"
75+ if [ -d " ${CCACHE_HOST_DIR} " ]; then
76+ echo " ccache directory exists at ${CCACHE_HOST_DIR} "
77+ else
78+ echo " Creating ccache directory at ${CCACHE_HOST_DIR} "
79+ mkdir -p " ${CCACHE_HOST_DIR} "
80+ fi
81+
82+ # ccache-specific docker run args
83+ ccache_args+=(
84+ -e CCACHE_DIR=" ${CCACHE_ROOT} "
85+ -v " ${CCACHE_HOST_DIR} :${CCACHE_ROOT} "
86+ )
87+ if [ -n " ${CCACHE_MAXSIZE} " ]; then
88+ ccache_args+=(-e CCACHE_MAXSIZE=" ${CCACHE_MAXSIZE} " )
89+ fi
90+ fi
91+
5892# Want a CPU build
5993DESIRED_CUDA=cpu
6094GPU_ARCH_TYPE=cpu-aarch64
@@ -89,13 +123,26 @@ if ! docker container inspect $TORCH_BUILD_CONTAINER >/dev/null 2>&1 ; then
89123 -e SKIP_ALL_TESTS=1 \
90124 -e OPENSSL_ROOT_DIR=" ${OPENSSL_HOST_DIR} " \
91125 -e CMAKE_INCLUDE_PATH=" ${OPENSSL_HOST_DIR} /include" \
126+ " ${ccache_args[@]} " \
92127 -v " ${PYTORCH_HOST_DIR} :${PYTORCH_ROOT} " \
93128 -v " ${PYTORCH_FINAL_PACKAGE_HOST_DIR} :${PYTORCH_FINAL_PACKAGE_DIR} " \
94129 -v " ${PWD} /utils:${UTILS} " \
95130 -v " ${PWD} /../utils:${COMMON_UTILS} " \
96131 -w / \
97132 " ${IMAGE_NAME} " )
98133
134+ # Provide ccache support
135+ if [ " ${USE_CCACHE} " == " 1" ]; then
136+ docker exec " $TORCH_BUILD_CONTAINER " yum install -y ccache || true
137+ if [ -n " ${CCACHE_MAXSIZE} " ]; then
138+ docker exec " $TORCH_BUILD_CONTAINER " ccache --max-size=" $CCACHE_MAXSIZE " || true
139+ fi
140+ docker exec " $TORCH_BUILD_CONTAINER " ccache -z || true
141+ docker exec " $TORCH_BUILD_CONTAINER " ccache -o compression=true || true
142+ docker exec " $TORCH_BUILD_CONTAINER " ccache -o compression_level=6 || true
143+ docker exec " $TORCH_BUILD_CONTAINER " ccache -s || true
144+ fi
145+
99146 # Currently changes in these scripts will not be applied without a clean
100147 # build, which is not ideal for dev work. But we have to balance this with
101148 # extra time/network traffic when rebuilding many times.
@@ -131,12 +178,25 @@ build_date=$(cd $PYTORCH_HOST_DIR && git log --pretty=format:%cs -1 | tr -d '-')
131178version=$( cat $PYTORCH_HOST_DIR /version.txt| tr -d " [:space:]" )
132179OVERRIDE_PACKAGE_VERSION=" ${version% ??} .dev${build_date}${TORCH_RELEASE_ID: +" +$TORCH_RELEASE_ID " } "
133180
181+ if [ " ${USE_CCACHE} " == " 1" ]; then
182+ echo " Zero-ing ccache stats."
183+ docker exec " $TORCH_BUILD_CONTAINER " ccache -z || true
184+ fi
185+
134186docker exec $TORCH_BUILD_CONTAINER bash -lc "
135187 source /tmp/env &&
136188 BUILD_TEST=0 \
189+ DO_SETUP_PY_CLEAN_BEFORE_BUILD=0 \
190+ WIPE_RH_CUDA_AFTER_BUILD=0 \
137191 OVERRIDE_PACKAGE_VERSION=$OVERRIDE_PACKAGE_VERSION \
138192 bash ${PYTORCH_ROOT} /.ci/manywheel/build.sh
139193"
140194
195+ if [ " ${USE_CCACHE} " == " 1" ]; then
196+ echo " Final ccache stats:"
197+ docker exec " $TORCH_BUILD_CONTAINER " ccache -s || true
198+ fi
199+
141200# directories generated by the docker container are owned by root, so transfer ownership to user
142- docker exec $TORCH_BUILD_CONTAINER chown -R " $( id -u) " :" $( id -g) " " ${PYTORCH_ROOT} " /artifacts
201+ docker exec " $TORCH_BUILD_CONTAINER " chown -R " $( id -u) " :" $( id -g) " \
202+ " ${PYTORCH_ROOT} " " ${PYTORCH_FINAL_PACKAGE_DIR} " " ${CCACHE_ROOT} "
0 commit comments