|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright 2022 The TensorFlow Authors. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# ============================================================================== |
| 17 | +# |
| 18 | +# setup.rocm.sh: Prepare the ROCM installation on the container. |
| 19 | +# Usage: setup.rocm.sh <ROCM_VERSION> <DISTRO> |
| 20 | +# Supported Distros: |
| 21 | +# - focal |
| 22 | +# - jammy |
| 23 | +# - el7 |
| 24 | +# - el8 |
| 25 | +set -x |
| 26 | + |
| 27 | +# Get arguments (or defaults) |
| 28 | +ROCM_VERSION=6.2.0 |
| 29 | +DISTRO=focal |
| 30 | +if [[ -n $1 ]]; then |
| 31 | + ROCM_VERSION=$1 |
| 32 | +fi |
| 33 | +if [[ -n $2 ]]; then |
| 34 | + if [[ "$2" == "focal" ]] || [[ "$2" == "jammy" ]] || [[ "$2" == "noble" ]] || [[ "$2" == "el7" ]] || [[ "$2" == "el8" ]]; then |
| 35 | + DISTRO=$2 |
| 36 | + else |
| 37 | + echo "Distro not supported" |
| 38 | + echo "Supported distros are:\n focal\n jammy\n noble\n el7\n el8" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +fi |
| 42 | + |
| 43 | +ROCM_PATH=${ROCM_PATH:-/opt/rocm-${ROCM_VERSION}} |
| 44 | +# Intial release don't have the trialing '.0' |
| 45 | +# For example ROCM 5.4.0 is at https://repo.radeon.com/rocm/apt/5.4/ |
| 46 | +if [ ${ROCM_VERSION##*[^0-9]} -eq '0' ]; then |
| 47 | + ROCM_VERS=${ROCM_VERSION%.*} |
| 48 | +else |
| 49 | + ROCM_VERS=$ROCM_VERSION |
| 50 | +fi |
| 51 | + |
| 52 | +if [[ "$DISTRO" == "focal" ]] || [[ "$DISTRO" == "jammy" ]] || [[ "$DISTRO" == "noble" ]]; then |
| 53 | + ROCM_DEB_REPO_HOME=https://repo.radeon.com/rocm/apt/ |
| 54 | + AMDGPU_DEB_REPO_HOME=https://repo.radeon.com/amdgpu/ |
| 55 | + ROCM_BUILD_NAME=${DISTRO} |
| 56 | + ROCM_BUILD_NUM=main |
| 57 | + |
| 58 | + # Adjust the ROCM repo location |
| 59 | + ROCM_DEB_REPO=${ROCM_DEB_REPO_HOME}${ROCM_VERS}/ |
| 60 | + AMDGPU_DEB_REPO=${AMDGPU_DEB_REPO_HOME}${ROCM_VERS}/ |
| 61 | + |
| 62 | + DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated update |
| 63 | + DEBIAN_FRONTEND=noninteractive apt install -y wget software-properties-common |
| 64 | + DEBIAN_FRONTEND=noninteractive apt-get clean all |
| 65 | + |
| 66 | + if [ ! -f "/${CUSTOM_INSTALL}" ]; then |
| 67 | + # Add rocm repository |
| 68 | + #chmod 1777 /tmp |
| 69 | + #wget -qO - https://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -; |
| 70 | + |
| 71 | + # Make the directory if it doesn't exist yet. |
| 72 | + # This location is recommended by the distribution maintainers. |
| 73 | + mkdir --parents --mode=0755 /etc/apt/keyrings |
| 74 | + |
| 75 | + # Download the key, convert the signing-key to a full |
| 76 | + # keyring required by apt and store in the keyring directory |
| 77 | + wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \ |
| 78 | + gpg --dearmor | tee /etc/apt/keyrings/rocm.gpg > /dev/null |
| 79 | + |
| 80 | + echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] $AMDGPU_DEB_REPO/ubuntu $ROCM_BUILD_NAME $ROCM_BUILD_NUM" | tee --append /etc/apt/sources.list.d/amdgpu.list |
| 81 | + echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] $ROCM_DEB_REPO $ROCM_BUILD_NAME $ROCM_BUILD_NUM" | tee /etc/apt/sources.list.d/rocm.list |
| 82 | + echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' \ |
| 83 | + | tee /etc/apt/preferences.d/rocm-pin-600 |
| 84 | + else |
| 85 | + bash "/${CUSTOM_INSTALL}" |
| 86 | + fi |
| 87 | + apt-get update --allow-insecure-repositories |
| 88 | + |
| 89 | + |
| 90 | + # install rocm |
| 91 | + /setup.packages.sh /devel.packages.rocm.txt |
| 92 | + |
| 93 | + MIOPENKERNELS=$( \ |
| 94 | + apt-cache search --names-only miopen-hip-gfx | \ |
| 95 | + awk '{print $1}' | \ |
| 96 | + grep -F -v . || \ |
| 97 | + true ) |
| 98 | + DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated ${MIOPENKERNELS} |
| 99 | + |
| 100 | + #install hipblasLT if available |
| 101 | + DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated hipblaslt-dev || true |
| 102 | + |
| 103 | +elif [[ "$DISTRO" == "el7" ]]; then |
| 104 | + if [ ! -f "/${CUSTOM_INSTALL}" ]; then |
| 105 | + RPM_ROCM_REPO=http://repo.radeon.com/rocm/yum/${ROCM_VERS}/main |
| 106 | + echo -e "[ROCm]\nname=ROCm\nbaseurl=$RPM_ROCM_REPO\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/rocm.repo |
| 107 | + echo -e "[amdgpu]\nname=amdgpu\nbaseurl=https://repo.radeon.com/amdgpu/${ROCM_VERS}/rhel/7/main/x86_64/\nenabled=1\ngpgcheck=0" >>/etc/yum.repos.d/amdgpu.repo |
| 108 | + else |
| 109 | + bash "/${CUSTOM_INSTALL}" |
| 110 | + fi |
| 111 | + yum clean all |
| 112 | + |
| 113 | + # install rocm |
| 114 | + /setup.packages.rocm.cs7.sh /devel.packages.rocm.cs7.txt |
| 115 | + |
| 116 | + # install hipblasLT if available |
| 117 | + yum --enablerepo=extras install -y hipblaslt-devel || true |
| 118 | + |
| 119 | +elif [[ "$DISTRO" == "el8" ]]; then |
| 120 | + if [ ! -f "/${CUSTOM_INSTALL}" ]; then |
| 121 | + RPM_ROCM_REPO=http://repo.radeon.com/rocm/rhel8/${ROCM_VERS}/main |
| 122 | + echo -e "[ROCm]\nname=ROCm\nbaseurl=$RPM_ROCM_REPO\nenabled=1\ngpgcheck=1\ngpgkey=https://repo.radeon.com/rocm/rocm.gpg.key" >>/etc/yum.repos.d/rocm.repo |
| 123 | + echo -e "[amdgpu]\nname=amdgpu\nbaseurl=https://repo.radeon.com/amdgpu/${ROCM_VERS}/rhel/8.10/main/x86_64/\nenabled=1\ngpgcheck=1\ngpgkey=https://repo.radeon.com/rocm/rocm.gpg.key" >>/etc/yum.repos.d/amdgpu.repo |
| 124 | + else |
| 125 | + bash "/${CUSTOM_INSTALL}" |
| 126 | + fi |
| 127 | + dnf clean all |
| 128 | + |
| 129 | + # install rocm |
| 130 | + /setup.packages.rocm.el8.sh /devel.packages.rocm.el8.txt |
| 131 | + |
| 132 | + # install hipblasLT if available |
| 133 | + dnf --enablerepo=extras,epel,elrepo,build_system install -y hipblaslt-devel || true |
| 134 | +fi |
| 135 | + |
| 136 | +function ver { printf "%03d%03d%03d" $(echo "$1" | tr '.' ' '); } |
| 137 | +# If hipcc uses llvm-17, in case of ROCM 6.0.x and 6.1.x and |
| 138 | +# host compiler is llvm-18 leads to mismatch in name mangling resulting |
| 139 | +# in faliure to link compiled gpu kernels. This linker option circumvents that issue. |
| 140 | +if [ $(ver "$ROCM_VERSION") -lt $(ver "6.2.0") ] |
| 141 | +then |
| 142 | + echo "build:rocm_base --copt=-fclang-abi-compat=17" >> /etc/bazel.bazelrc |
| 143 | +fi |
| 144 | + |
| 145 | +echo $ROCM_VERSION |
| 146 | +echo $ROCM_REPO |
| 147 | +echo $ROCM_PATH |
| 148 | +echo $GPU_DEVICE_TARGETS |
| 149 | + |
| 150 | +# Ensure the ROCm target list is set up |
| 151 | +printf '%s\n' ${GPU_DEVICE_TARGETS} | tr ',' ' ' | tee -a "$ROCM_PATH/bin/target.lst" |
| 152 | +touch "${ROCM_PATH}/.info/version" |
0 commit comments