-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuild_packages_local.sh
More file actions
executable file
·263 lines (235 loc) · 9.82 KB
/
build_packages_local.sh
File metadata and controls
executable file
·263 lines (235 loc) · 9.82 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env bash
#
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
#
# build_packages_local.sh — single source of truth for building relocatable
# TransferBench packages (DEB / RPM / TGZ) against TheRock ROCm SDK.
# Used by both local developers and the GitHub Actions workflow.
#
# Usage:
# sudo ./build_packages_local.sh
# sudo -E ROCM_VERSION=7.11.0a20260121 GPU_FAMILY=gfx94X-dcgpu ./build_packages_local.sh
#
# Requires root (installs system packages).
set -euo pipefail
# -------- pretty output --------
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log() { echo -e "${BLUE}[INFO]${NC} $*"; }
ok() { echo -e "${GREEN}[ OK ]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[FAIL]${NC} $*" >&2; }
trap 'err "Build failed at line $LINENO"' ERR
# -------- root check --------
if [[ ${EUID} -ne 0 ]]; then
err "This script installs system packages and must run as root. Re-run with: sudo -E $0"
exit 1
fi
# -------- inputs --------
ROCM_VERSION="${ROCM_VERSION:-}" # empty => auto-fetch latest
GPU_FAMILY="${GPU_FAMILY:-gfx94X-dcgpu}"
BUILD_TYPE="${BUILD_TYPE:-Release}"
GITHUB_RUN_NUMBER="${GITHUB_RUN_NUMBER:-1}"
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${REPO_ROOT}/build"
SDK_DIR="${HOME}/rocm-sdk"
ROCM_PATH="${SDK_DIR}/install"
# Containerized builds (e.g. manylinux on a host-mounted workspace) hit git's
# "dubious ownership" guard because the checkout is host-UID-owned but we run
# as root. Without this, `git describe` in CMakeLists.txt silently fails and
# TRANSFERBENCH_VERSION_PATCH falls back to its hard-coded default.
#
# Use GIT_CONFIG_* env vars (git >= 2.31) so the scoped safe.directory entry
# is inherited by CMake's `execute_process(git …)` children without touching
# the user's persistent ~/.gitconfig (especially harmful under sudo, where
# the modification would land in root's global config).
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0="safe.directory"
export GIT_CONFIG_VALUE_0="${REPO_ROOT}"
# Default GPU targets baked into every package, regardless of GPU_FAMILY tarball.
DEFAULT_GPU_TARGETS="gfx906;gfx908;gfx90a;gfx942;gfx950;gfx1030;gfx1100;gfx1101;gfx1102;gfx1150;gfx1151;gfx1200;gfx1201"
GPU_TARGETS="${GPU_TARGETS:-$DEFAULT_GPU_TARGETS}"
# -------- detect OS --------
if [[ -f /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
OS_ID="${ID:-unknown}"
OS_LIKE="${ID_LIKE:-}"
else
err "/etc/os-release not found; cannot detect distro"; exit 1
fi
case "${OS_ID}:${OS_LIKE}" in
ubuntu:*|debian:*|*:*debian*) DISTRO="ubuntu" ;;
almalinux:*|rocky:*|rhel:*|centos:*|*:*rhel*|*:*fedora*) DISTRO="almalinux" ;;
*)
if command -v apt-get >/dev/null 2>&1; then DISTRO="ubuntu"
elif command -v yum >/dev/null 2>&1 || command -v dnf >/dev/null 2>&1; then DISTRO="almalinux"
else err "Unsupported distro: ${OS_ID}"; exit 1
fi
;;
esac
log "Detected distro: ${DISTRO} (${OS_ID})"
# -------- install dependencies --------
log "Installing build dependencies..."
if [[ "${DISTRO}" == "ubuntu" ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y --no-install-recommends \
build-essential cmake git curl tar xz-utils ca-certificates pkg-config \
python3 python3-pip \
libnuma-dev \
dpkg-dev rpm file apt-utils
CMAKE_BIN="cmake"
CMAKE_CXX_COMPILER_OVERRIDE=""
else
# AlmaLinux / Rocky / RHEL / manylinux_2_28
if command -v dnf >/dev/null 2>&1; then PKG="dnf"; else PKG="yum"; fi
${PKG} install -y epel-release || true
# Enable PowerTools/CRB for createrepo_c, etc.
${PKG} config-manager --set-enabled powertools 2>/dev/null \
|| ${PKG} config-manager --set-enabled crb 2>/dev/null || true
${PKG} install -y \
gcc gcc-c++ make cmake3 git curl tar xz ca-certificates pkgconfig \
python3 python3-pip \
numactl-devel \
rpm-build dpkg createrepo_c file
CMAKE_BIN="cmake3"
command -v cmake3 >/dev/null 2>&1 || CMAKE_BIN="cmake"
CMAKE_CXX_COMPILER_OVERRIDE="${ROCM_PATH}/bin/hipcc"
fi
ok "Dependencies installed"
# -------- fetch ROCm SDK from TheRock --------
TARBALL_BASE="https://therock-nightly-tarball.s3.amazonaws.com"
TAR_PREFIX="therock-dist-linux-${GPU_FAMILY}-"
if [[ -z "${ROCM_VERSION}" ]]; then
log "ROCM_VERSION not set; auto-fetching latest for ${GPU_FAMILY}..."
# No LATEST.txt is published; list the bucket and pick the highest version key.
LIST_URL="${TARBALL_BASE}/?list-type=2&max-keys=1000&prefix=${TAR_PREFIX}"
# Filter to versioned tarballs only (skip ADHOCBUILD-* and other non-release keys);
# match: <prefix><MAJOR>.<MINOR>.<...>.tar.gz
LATEST_KEY="$(curl -fsSL "${LIST_URL}" 2>/dev/null \
| tr '<' '\n' \
| sed -n 's|^Key>||p' \
| grep -E "^${TAR_PREFIX}[0-9]+\.[0-9]+\.[0-9a-z]+\.tar\.gz$" \
| sort -V \
| tail -1 || true)"
if [[ -n "${LATEST_KEY}" ]]; then
ROCM_VERSION="${LATEST_KEY#${TAR_PREFIX}}"
ROCM_VERSION="${ROCM_VERSION%.tar.gz}"
ok "Latest ROCm version for ${GPU_FAMILY}: ${ROCM_VERSION}"
else
warn "Could not list ${LIST_URL}; falling back to pinned default"
ROCM_VERSION="7.13.0a20260423"
fi
fi
TARBALL_NAME="${TAR_PREFIX}${ROCM_VERSION}.tar.gz"
TARBALL_URL="${TARBALL_BASE}/${TARBALL_NAME}"
mkdir -p "${SDK_DIR}"
if [[ ! -d "${ROCM_PATH}" ]] || [[ ! -f "${SDK_DIR}/.installed-${ROCM_VERSION}-${GPU_FAMILY}" ]]; then
log "Downloading ${TARBALL_URL}..."
curl -fSL "${TARBALL_URL}" -o "${SDK_DIR}/${TARBALL_NAME}"
log "Extracting to ${SDK_DIR}..."
rm -rf "${ROCM_PATH}"
mkdir -p "${ROCM_PATH}"
tar -xzf "${SDK_DIR}/${TARBALL_NAME}" -C "${ROCM_PATH}" --strip-components=1 \
|| tar -xzf "${SDK_DIR}/${TARBALL_NAME}" -C "${ROCM_PATH}"
rm -f "${SDK_DIR}/${TARBALL_NAME}"
touch "${SDK_DIR}/.installed-${ROCM_VERSION}-${GPU_FAMILY}"
ok "ROCm SDK installed at ${ROCM_PATH}"
else
log "Reusing cached ROCm SDK at ${ROCM_PATH}"
fi
export ROCM_PATH
export PATH="${ROCM_PATH}/bin:${PATH}"
export LD_LIBRARY_PATH="${ROCM_PATH}/lib:${LD_LIBRARY_PATH:-}"
export CMAKE_PREFIX_PATH="${ROCM_PATH}:${CMAKE_PREFIX_PATH:-}"
# Locate HIP device libraries (amdgcn bitcode)
for candidate in \
"${ROCM_PATH}/amdgcn/bitcode" \
"${ROCM_PATH}/lib/llvm/amdgcn/bitcode" \
"${ROCM_PATH}/lib/clang/amdgcn/bitcode"; do
if [[ -d "${candidate}" ]]; then export HIP_DEVICE_LIB_PATH="${candidate}"; break; fi
done
if [[ -n "${HIP_DEVICE_LIB_PATH:-}" ]]; then
ok "HIP_DEVICE_LIB_PATH=${HIP_DEVICE_LIB_PATH}"
else
warn "amdgcn bitcode directory not found under ${ROCM_PATH}; build may fail"
fi
# -------- compute version helpers --------
# ROCM_MAJOR / MINOR / patch helpers (e.g. 7.11.0a20260121 -> major=7 minor=11)
ROCM_MAJOR="$(echo "${ROCM_VERSION}" | sed -E 's/^([0-9]+)\..*/\1/')"
ROCM_MINOR="$(echo "${ROCM_VERSION}" | sed -E 's/^[0-9]+\.([0-9]+).*/\1/')"
printf -v ROCM_LIBPATCH_VERSION '%02d%02d' "${ROCM_MAJOR}" "${ROCM_MINOR}"
export ROCM_MAJOR ROCM_MINOR ROCM_LIBPATCH_VERSION
log "ROCm major=${ROCM_MAJOR} minor=${ROCM_MINOR} libpatch=${ROCM_LIBPATCH_VERSION}"
# Package release string. Format mirrors the RVS reference flow:
# default (push/schedule/dispatch/local): r<libpatch>.<yyyymmdd>
# pull request: r<libpatch>.<yyyymmdd>.<src-branch>.<commit>
# release/* branch (non-PR): ${GITHUB_RUN_NUMBER} (fallback 1)
GIT_BRANCH="${GITHUB_REF_NAME:-$(git -C "${REPO_ROOT}" rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)}"
GIT_COMMIT="$(git -C "${REPO_ROOT}" rev-parse --short HEAD 2>/dev/null || echo unknown)"
BUILD_DATE_UTC="$(date -u +%Y%m%d)"
# Collapse non-alphanumerics into single dots and trim — DEB/RPM release
# fields reject most punctuation.
sanitize_release() {
local s
s="$(printf '%s' "$1" | sed -E 's/[^[:alnum:]]+/./g; s/^\.+//; s/\.+$//')"
printf '%s' "${s:-unknown}"
}
if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
PR_BRANCH="$(sanitize_release "${GITHUB_HEAD_REF:-${GIT_BRANCH}}")"
PKG_RELEASE="r${ROCM_LIBPATCH_VERSION}.${BUILD_DATE_UTC}.${PR_BRANCH}.${GIT_COMMIT}"
elif [[ "${GIT_BRANCH}" == release/* ]]; then
PKG_RELEASE="${GITHUB_RUN_NUMBER:-1}"
else
PKG_RELEASE="r${ROCM_LIBPATCH_VERSION}.${BUILD_DATE_UTC}"
fi
export CPACK_DEBIAN_PACKAGE_RELEASE="${CPACK_DEBIAN_PACKAGE_RELEASE:-$PKG_RELEASE}"
export CPACK_RPM_PACKAGE_RELEASE="${CPACK_RPM_PACKAGE_RELEASE:-$PKG_RELEASE}"
log "Package release tag: ${PKG_RELEASE}"
# -------- configure --------
INSTALL_PREFIX="/opt/rocm/extras-${ROCM_MAJOR}"
# Relocatable RPATH defaults live in CMakeLists.txt under
# if(BUILD_RELOCATABLE_PACKAGE); enabling that option below activates them.
log "Configuring CMake..."
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
CMAKE_ARGS=(
-B "${BUILD_DIR}"
-S "${REPO_ROOT}"
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
-DROCM_PATH="${ROCM_PATH}"
-DROCM_MAJOR_VERSION="${ROCM_MAJOR}"
-DHIP_PLATFORM=amd
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}"
-DCPACK_PACKAGING_INSTALL_PREFIX="${INSTALL_PREFIX}"
-DCMAKE_VERBOSE_MAKEFILE=ON
-DBUILD_RELOCATABLE_PACKAGE=ON
-DBUILD_LOCAL_GPU_TARGET_ONLY=OFF
-DENABLE_NIC_EXEC=OFF
-DENABLE_MPI_COMM=OFF
-DDISABLE_DMABUF=OFF
-DGPU_TARGETS="${GPU_TARGETS}"
-DTRANSFERBENCH_PACKAGE_RELEASE="${PKG_RELEASE}"
)
if [[ -n "${CMAKE_CXX_COMPILER_OVERRIDE}" ]]; then
CMAKE_ARGS+=(-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER_OVERRIDE}")
fi
"${CMAKE_BIN}" "${CMAKE_ARGS[@]}"
ok "CMake configured"
# -------- build --------
log "Building TransferBench (-j$(nproc))..."
"${CMAKE_BIN}" --build "${BUILD_DIR}" -- -j"$(nproc)"
ok "Build complete"
# -------- package --------
log "Packaging (DEB / RPM / TGZ via CPack)..."
pushd "${BUILD_DIR}" >/dev/null
if [[ "${DISTRO}" == "ubuntu" ]]; then
cpack -G DEB
cpack -G TGZ
else
cpack -G RPM
cpack -G TGZ
fi
popd >/dev/null
ok "Packages written under ${BUILD_DIR}:"
ls -lh "${BUILD_DIR}"/amdrocm*-transferbench* 2>/dev/null || ls -lh "${BUILD_DIR}"/*.deb "${BUILD_DIR}"/*.rpm "${BUILD_DIR}"/*.tar.gz 2>/dev/null || true