File: ccache_setup.sh

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (92 lines) | stat: -rwxr-xr-x 2,559 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

# This script installs CCache with CUDA support.
# Example usage:
#     ./ccache_setup.sh --path /installed/folder

set -e
shopt -s expand_aliases

# Setup the proxy
alias 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'"

# Parse options
path="$HOME/ccache"
force=false

while [[ $# -gt 0 ]]; do
  case "$1" in
    --path)
      shift
      path="$1"
      path=$(realpath "$path")
      ;;
    --force)  # Force install
      force=true
      ;;
    --help)
      echo 'usage: ./ccache_setup.py --path /installed/folder [--force]'
      exit 0
      ;;
    *)
      echo "Invalid option: $1"
      exit 1
      ;;
  esac
  shift
done

# Check whether you put nvcc in PATH
set +e
nvcc_path=$(which nvcc)
if [[ -z "$nvcc_path" ]]; then
  nvcc_path="/usr/local/cuda/bin/nvcc"
  export PATH="/usr/local/cuda/bin:$PATH"
fi
set -e
if [ ! -f "$nvcc_path" ] && ! $force; then
  # shellcheck disable=SC2016
  echo 'nvcc is not detected in $PATH'
  exit 1
fi
echo "nvcc is detected at $nvcc_path"

if [ -f "$CUDA_NVCC_EXECUTABLE" ] && [[ "$CUDA_NVCC_EXECUTABLE" == *"ccache"* ]]; then  # Heuristic rule
  if $CUDA_NVCC_EXECUTABLE --version; then
    if ! $force; then
      echo "CCache with nvcc support is already installed at $CUDA_NVCC_EXECUTABLE, please add --force"
      exit 0
    fi
  fi
fi

# Installing CCache
echo "CCache will be installed at $path"
if [ -e "$path" ]; then
  mv --backup=t -T "$path" "${path}.old"
fi

with_proxy git clone https://github.com/colesbury/ccache.git "$path" -b ccbin
cd "$path"
./autogen.sh
./configure
make install prefix="$path"

mkdir -p "$path/lib"
mkdir -p "$path/cuda"
ln -sf "$path/bin/ccache" "$path/lib/cc"
ln -sf "$path/bin/ccache" "$path/lib/c++"
ln -sf "$path/bin/ccache" "$path/lib/gcc"
ln -sf "$path/bin/ccache" "$path/lib/g++"
ln -sf "$path/bin/ccache" "$path/cuda/nvcc"
"$path/bin/ccache" -M 25Gi

# Make sure the nvcc wrapped in CCache is runnable
"$path/cuda/nvcc" --version
echo 'Congrats! The CCache with nvcc support is installed!'
echo -e "Please add the following lines to your bash init script:\\n"
echo "################ Env Var for CCache with CUDA support ################"
# shellcheck disable=SC2016
echo 'export PATH="'"$path"'/lib:$PATH"'
echo 'export CUDA_NVCC_EXECUTABLE="'"$path"'/cuda/nvcc"'
echo '######################################################################'