diff --git a/.jenkins/caffe2/build.sh b/.jenkins/caffe2/build.sh index 30108031f72308..cc3fc211e0f789 100755 --- a/.jenkins/caffe2/build.sh +++ b/.jenkins/caffe2/build.sh @@ -7,57 +7,7 @@ INSTALL_PREFIX="/usr/local/caffe2" LOCAL_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) ROOT_DIR=$(cd "$LOCAL_DIR"/../.. && pwd) CMAKE_ARGS=() - - -# Setup SCCACHE -############################################################################### -# Setup sccache if SCCACHE_BUCKET is set -if [ -n "${SCCACHE_BUCKET}" ]; then - mkdir -p ./sccache - - SCCACHE="$(which sccache)" - if [ -z "${SCCACHE}" ]; then - echo "Unable to find sccache..." - exit 1 - fi - - # Setup wrapper scripts - for compiler in cc c++ gcc g++ x86_64-linux-gnu-gcc; do - ( - echo "#!/bin/sh" - echo "exec $SCCACHE $(which $compiler) \"\$@\"" - ) > "./sccache/$compiler" - chmod +x "./sccache/$compiler" - done - - if [[ "${BUILD_ENVIRONMENT}" == *-cuda* ]]; then - ( - echo "#!/bin/sh" - echo "exec $SCCACHE $(which nvcc) \"\$@\"" - ) > "./sccache/nvcc" - chmod +x "./sccache/nvcc" - fi - - export CACHE_WRAPPER_DIR="$PWD/sccache" - - # CMake must find these wrapper scripts - export PATH="$CACHE_WRAPPER_DIR:$PATH" -fi - -# Setup ccache if configured to use it (and not sccache) -if [ -z "${SCCACHE}" ] && which ccache > /dev/null; then - mkdir -p ./ccache - ln -sf "$(which ccache)" ./ccache/cc - ln -sf "$(which ccache)" ./ccache/c++ - ln -sf "$(which ccache)" ./ccache/gcc - ln -sf "$(which ccache)" ./ccache/g++ - ln -sf "$(which ccache)" ./ccache/x86_64-linux-gnu-gcc - if [[ "${BUILD_ENVIRONMENT}" == *-cuda* ]]; then - ln -sf "$(which ccache)" ./ccache/nvcc - fi - export CACHE_WRAPPER_DIR="$PWD/ccache" - export PATH="$CACHE_WRAPPER_DIR:$PATH" -fi +SCCACHE="$(which sccache)" report_compile_cache_stats() { if [[ -n "${SCCACHE}" ]]; then diff --git a/docker/caffe2/jenkins/common/install_ccache.sh b/docker/caffe2/jenkins/common/install_ccache.sh index 7c959884f113c3..0fea37807390b2 100755 --- a/docker/caffe2/jenkins/common/install_ccache.sh +++ b/docker/caffe2/jenkins/common/install_ccache.sh @@ -18,3 +18,40 @@ popd # Install sccache from pre-compiled binary. curl https://s3.amazonaws.com/ossci-linux/sccache -o /usr/local/bin/sccache chmod a+x /usr/local/bin/sccache + +# Setup SCCACHE +############################################################################### +mkdir -p ./sccache + +SCCACHE="$(which sccache)" +if [ -z "${SCCACHE}" ]; then + echo "Unable to find sccache..." + exit 1 +fi + +# List of compilers to use sccache on. +declare -a compilers=("cc" "c++" "gcc" "g++" "x86_64-linux-gnu-gcc") + +# If cuda build, add nvcc to sccache. +if [[ "${BUILD_ENVIRONMENT}" == *-cuda* ]]; then + compilers+=("nvcc") +fi + +# If rocm build, add hcc to sccache. +if [[ "${BUILD_ENVIRONMENT}" == *-rocm* ]]; then + compilers+=("hcc") +fi + +# Setup wrapper scripts +for compiler in "${compilers[@]}"; do + ( + echo "#!/bin/sh" + echo "exec $SCCACHE $(which $compiler) \"\$@\"" + ) > "./sccache/$compiler" + chmod +x "./sccache/$compiler" +done + +export CACHE_WRAPPER_DIR="$PWD/sccache" + +# CMake must find these wrapper scripts +export PATH="$CACHE_WRAPPER_DIR:$PATH"