1#!/bin/bash 2 3# This script installs CCache with CUDA support. 4# Example usage: 5# ./ccache_setup.sh --path /installed/folder 6 7set -e 8shopt -s expand_aliases 9 10# Setup the proxy 11alias with_proxy="HTTPS_PROXY=http://fwdproxy:8080 HTTP_PROXY=http://fwdproxy:8080 FTP_PROXY=http://fwdproxy:8080 https_proxy=http://fwdproxy:8080 http_proxy=http://fwdproxy:8080 ftp_proxy=http://fwdproxy:8080 http_no_proxy='*.facebook.com|*.tfbnw.net|*.fb.com'" 12 13# Parse options 14path="$HOME/ccache" 15force=false 16 17while [[ $# -gt 0 ]]; do 18 case "$1" in 19 --path) 20 shift 21 path="$1" 22 path=$(realpath "$path") 23 ;; 24 --force) # Force install 25 force=true 26 ;; 27 --help) 28 echo 'usage: ./ccache_setup.py --path /installed/folder [--force]' 29 exit 0 30 ;; 31 *) 32 echo "Invalid option: $1" 33 exit 1 34 ;; 35 esac 36 shift 37done 38 39# Check whether you put nvcc in PATH 40set +e 41nvcc_path=$(which nvcc) 42if [[ -z "$nvcc_path" ]]; then 43 nvcc_path="/usr/local/cuda/bin/nvcc" 44 export PATH="/usr/local/cuda/bin:$PATH" 45fi 46set -e 47if [ ! -f "$nvcc_path" ] && ! $force; then 48 # shellcheck disable=SC2016 49 echo 'nvcc is not detected in $PATH' 50 exit 1 51fi 52echo "nvcc is detected at $nvcc_path" 53 54if [ -f "$CUDA_NVCC_EXECUTABLE" ] && [[ "$CUDA_NVCC_EXECUTABLE" == *"ccache"* ]]; then # Heuristic rule 55 if $CUDA_NVCC_EXECUTABLE --version; then 56 if ! $force; then 57 echo "CCache with nvcc support is already installed at $CUDA_NVCC_EXECUTABLE, please add --force" 58 exit 0 59 fi 60 fi 61fi 62 63# Installing CCache 64echo "CCache will be installed at $path" 65if [ -e "$path" ]; then 66 mv --backup=t -T "$path" "${path}.old" 67fi 68 69with_proxy git clone https://github.com/colesbury/ccache.git "$path" -b ccbin 70cd "$path" 71./autogen.sh 72./configure 73make install prefix="$path" 74 75mkdir -p "$path/lib" 76mkdir -p "$path/cuda" 77ln -sf "$path/bin/ccache" "$path/lib/cc" 78ln -sf "$path/bin/ccache" "$path/lib/c++" 79ln -sf "$path/bin/ccache" "$path/lib/gcc" 80ln -sf "$path/bin/ccache" "$path/lib/g++" 81ln -sf "$path/bin/ccache" "$path/cuda/nvcc" 82"$path/bin/ccache" -M 25Gi 83 84# Make sure the nvcc wrapped in CCache is runnable 85"$path/cuda/nvcc" --version 86echo 'Congrats! The CCache with nvcc support is installed!' 87echo -e "Please add the following lines to your bash init script:\\n" 88echo "################ Env Var for CCache with CUDA support ################" 89# shellcheck disable=SC2016 90echo 'export PATH="'"$path"'/lib:$PATH"' 91echo 'export CUDA_NVCC_EXECUTABLE="'"$path"'/cuda/nvcc"' 92echo '######################################################################' 93