1#!/bin/bash 2 3set -ex 4 5install_ubuntu() { 6 # NVIDIA dockers for RC releases use tag names like `11.0-cudnn9-devel-ubuntu18.04-rc`, 7 # for this case we will set UBUNTU_VERSION to `18.04-rc` so that the Dockerfile could 8 # find the correct image. As a result, here we have to check for 9 # "$UBUNTU_VERSION" == "18.04"* 10 # instead of 11 # "$UBUNTU_VERSION" == "18.04" 12 if [[ "$UBUNTU_VERSION" == "20.04"* ]]; then 13 cmake3="cmake=3.16*" 14 maybe_libiomp_dev="" 15 elif [[ "$UBUNTU_VERSION" == "22.04"* ]]; then 16 cmake3="cmake=3.22*" 17 maybe_libiomp_dev="" 18 else 19 cmake3="cmake=3.5*" 20 maybe_libiomp_dev="libiomp-dev" 21 fi 22 23 if [[ "$CLANG_VERSION" == 15 ]]; then 24 maybe_libomp_dev="libomp-15-dev" 25 elif [[ "$CLANG_VERSION" == 12 ]]; then 26 maybe_libomp_dev="libomp-12-dev" 27 elif [[ "$CLANG_VERSION" == 10 ]]; then 28 maybe_libomp_dev="libomp-10-dev" 29 else 30 maybe_libomp_dev="" 31 fi 32 33 # HACK: UCC testing relies on libnccl library from NVIDIA repo, and version 2.16 crashes 34 # See https://github.com/pytorch/pytorch/pull/105260#issuecomment-1673399729 35 if [[ "$UBUNTU_VERSION" == "20.04"* && "$CUDA_VERSION" == "11.8"* ]]; then 36 maybe_libnccl_dev="libnccl2=2.15.5-1+cuda11.8 libnccl-dev=2.15.5-1+cuda11.8 --allow-downgrades --allow-change-held-packages" 37 else 38 maybe_libnccl_dev="" 39 fi 40 41 # Install common dependencies 42 apt-get update 43 # TODO: Some of these may not be necessary 44 ccache_deps="asciidoc docbook-xml docbook-xsl xsltproc" 45 deploy_deps="libffi-dev libbz2-dev libreadline-dev libncurses5-dev libncursesw5-dev libgdbm-dev libsqlite3-dev uuid-dev tk-dev" 46 numpy_deps="gfortran" 47 apt-get install -y --no-install-recommends \ 48 $ccache_deps \ 49 $numpy_deps \ 50 ${deploy_deps} \ 51 ${cmake3} \ 52 apt-transport-https \ 53 autoconf \ 54 automake \ 55 build-essential \ 56 ca-certificates \ 57 curl \ 58 git \ 59 libatlas-base-dev \ 60 libc6-dbg \ 61 ${maybe_libiomp_dev} \ 62 libyaml-dev \ 63 libz-dev \ 64 libjemalloc2 \ 65 libjpeg-dev \ 66 libasound2-dev \ 67 libsndfile-dev \ 68 ${maybe_libomp_dev} \ 69 ${maybe_libnccl_dev} \ 70 software-properties-common \ 71 wget \ 72 sudo \ 73 vim \ 74 jq \ 75 libtool \ 76 vim \ 77 unzip \ 78 gpg-agent \ 79 gdb 80 81 # Should resolve issues related to various apt package repository cert issues 82 # see: https://github.com/pytorch/pytorch/issues/65931 83 apt-get install -y libgnutls30 84 85 # Cleanup package manager 86 apt-get autoclean && apt-get clean 87 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 88} 89 90install_centos() { 91 # Need EPEL for many packages we depend on. 92 # See http://fedoraproject.org/wiki/EPEL 93 yum --enablerepo=extras install -y epel-release 94 95 ccache_deps="asciidoc docbook-dtds docbook-style-xsl libxslt" 96 numpy_deps="gcc-gfortran" 97 # Note: protobuf-c-{compiler,devel} on CentOS are too old to be used 98 # for Caffe2. That said, we still install them to make sure the build 99 # system opts to build/use protoc and libprotobuf from third-party. 100 yum install -y \ 101 $ccache_deps \ 102 $numpy_deps \ 103 autoconf \ 104 automake \ 105 bzip2 \ 106 cmake \ 107 cmake3 \ 108 curl \ 109 gcc \ 110 gcc-c++ \ 111 gflags-devel \ 112 git \ 113 glibc-devel \ 114 glibc-headers \ 115 glog-devel \ 116 libstdc++-devel \ 117 libsndfile-devel \ 118 make \ 119 opencv-devel \ 120 sudo \ 121 wget \ 122 vim \ 123 unzip \ 124 gdb 125 126 # Cleanup 127 yum clean all 128 rm -rf /var/cache/yum 129 rm -rf /var/lib/yum/yumdb 130 rm -rf /var/lib/yum/history 131} 132 133# Install base packages depending on the base OS 134ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') 135case "$ID" in 136 ubuntu) 137 install_ubuntu 138 ;; 139 centos) 140 install_centos 141 ;; 142 *) 143 echo "Unable to determine OS..." 144 exit 1 145 ;; 146esac 147 148# Install Valgrind separately since the apt-get version is too old. 149mkdir valgrind_build && cd valgrind_build 150VALGRIND_VERSION=3.20.0 151wget https://ossci-linux.s3.amazonaws.com/valgrind-${VALGRIND_VERSION}.tar.bz2 152tar -xjf valgrind-${VALGRIND_VERSION}.tar.bz2 153cd valgrind-${VALGRIND_VERSION} 154./configure --prefix=/usr/local 155make -j$[$(nproc) - 2] 156sudo make install 157cd ../../ 158rm -rf valgrind_build 159alias valgrind="/usr/local/bin/valgrind" 160