Skip to content

Commit 8af4ff8

Browse files
gustcolmeta-codesync[bot]
authored andcommitted
Add GB200 aarch64 support improvements to CUDA installation script (#104) (#173)
Summary: - Add `--arch` flag to explicitly specify target architecture (`x86_64`, `aarch64`, `arm64`), enabling cross-compilation and container builds targeting GB200/Grace Hopper from x86_64 hosts - Add `--help` / `-h` flag with comprehensive usage documentation, examples for both x86_64 and aarch64, and environment variable reference - Add `CUDA_RUNFILE_SBSA` associative array for architecture-specific runfile overrides, allowing different driver versions when NVIDIA ships distinct runfiles for sbsa platforms - Add `validate_download_url()` pre-flight check to verify CUDA runfile availability before starting multi-GB downloads, with clear error messages for missing sbsa runfiles - Refactor architecture detection into reusable `resolve_arch()` function that validates supported architectures and can be re-invoked after `--arch` override - Display architecture information (`TARGETARCH` + `ARCH_PATH`) in the installation summary output Pull Request resolved: #173 Test Plan: - [ ] Verify `--help` flag prints usage information and exits cleanly - [ ] Verify `--arch aarch64` sets `ARCH_PATH` to `sbsa` and selects the correct sbsa runfile - [ ] Verify `--arch x86_64` works as expected on an x86_64 host - [ ] Verify `--arch invalid_arch` produces a clear error message - [ ] Verify `TARGETARCH=aarch64 ./install_cuda.sh 12.8` still works (env var path) - [ ] Verify URL pre-validation catches unavailable runfiles before downloading - [ ] Verify the installation summary includes architecture information - [ ] Test full installation on an aarch64/sbsa system (GB200 or Grace Hopper) Reviewed By: peiying779 Differential Revision: D97562180 Pulled By: FindHao fbshipit-source-id: a0ddf2286ceea620dafd1f89df74e711dde018b7
1 parent 2323987 commit 8af4ff8

1 file changed

Lines changed: 65 additions & 14 deletions

File tree

scripts/install_cuda.sh

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#!/bin/bash
22
# Copyright (c) Meta Platforms, Inc. and affiliates.
33
# Usage: CUDA_INSTALL_PREFIX=/home/yhao/opt ./install_cuda.sh 12.8
4+
# TARGETARCH=aarch64 CUDA_INSTALL_PREFIX=/opt ./install_cuda.sh 12.8
5+
#
46
# Notice: Part of this script is synced with https://github.com/pytorch/pytorch/blob/main/.ci/docker/common/install_cuda.sh
7+
#
8+
# Architecture support:
9+
# - x86_64: Standard x86-64 systems
10+
# - aarch64 (sbsa): ARM64 server platforms including NVIDIA GB200 / Grace Hopper
11+
#
12+
# Architecture is auto-detected from `uname -m` but can be overridden via:
13+
# TARGETARCH=<arch> Set target architecture (x86_64|aarch64|arm64)
14+
# Useful for cross-compilation or container builds targeting
15+
# GB200 (aarch64) from an x86_64 host.
16+
#
517
set -ex
618

719
# Debug settings - log all execution steps
@@ -121,14 +133,24 @@ trap cleanup_on_exit EXIT
121133
trap 'error_exit "Script interrupted"' INT TERM
122134

123135
# Detect architecture
136+
# TARGETARCH can be set via environment variable to override auto-detection.
137+
# On GB200 / Grace Hopper systems, uname -m returns 'aarch64' and the NVIDIA
138+
# download paths use the 'sbsa' (Server Base System Architecture) identifier.
124139
export TARGETARCH=${TARGETARCH:-$(uname -m)}
125-
if [ "${TARGETARCH}" = 'aarch64' ] || [ "${TARGETARCH}" = 'arm64' ]; then
126-
ARCH_PATH='sbsa'
127-
else
128-
ARCH_PATH='x86_64'
129-
fi
130140

131-
echo "🏗️ Architecture: ${ARCH_PATH}"
141+
# resolve_arch: normalize architecture names and set ARCH_PATH
142+
function resolve_arch {
143+
if [ "${TARGETARCH}" = 'aarch64' ] || [ "${TARGETARCH}" = 'arm64' ]; then
144+
ARCH_PATH='sbsa'
145+
elif [ "${TARGETARCH}" = 'x86_64' ]; then
146+
ARCH_PATH='x86_64'
147+
else
148+
error_exit "Unsupported architecture: ${TARGETARCH}. Supported: x86_64, aarch64, arm64"
149+
fi
150+
}
151+
152+
resolve_arch
153+
echo "🏗️ Architecture: ${TARGETARCH} (download path: ${ARCH_PATH})"
132154

133155
# Check if command exists
134156
function command_exists {
@@ -238,6 +260,21 @@ check_disk_space "${REQUIRED_DISK_SPACE_GB}"
238260
# Check network connectivity
239261
check_network
240262

263+
# Validate that a remote URL is reachable (HTTP HEAD check)
264+
# Returns 0 if the URL returns HTTP 2xx/3xx, 1 otherwise.
265+
function validate_download_url {
266+
local url=$1
267+
local http_code
268+
269+
http_code=$(curl -s -o /dev/null -w "%{http_code}" --head --connect-timeout 10 "${url}" 2>/dev/null || echo "000")
270+
271+
if [[ "${http_code}" =~ ^(2|3)[0-9][0-9]$ ]]; then
272+
return 0
273+
else
274+
return 1
275+
fi
276+
}
277+
241278
# Real CUDA installation function
242279
function install_cuda {
243280
local version=$1
@@ -247,14 +284,28 @@ function install_cuda {
247284
echo "Installing CUDA ${version}..."
248285
rm -rf "${CUDA_INSTALL_PREFIX}/cuda-${major_minor}" "${CUDA_INSTALL_PREFIX}/cuda"
249286

287+
# Append the _sbsa suffix for aarch64 platforms (GB200, Grace Hopper, etc.)
250288
if [[ ${ARCH_PATH} == 'sbsa' ]]; then
251289
runfile="${runfile}_sbsa"
252290
fi
253291
runfile="${runfile}.run"
254292

293+
local download_url="https://developer.download.nvidia.com/compute/cuda/${version}/local_installers/${runfile}"
294+
295+
# Pre-validate the download URL to provide a clear error message before
296+
# attempting a large download, especially useful for aarch64/sbsa where
297+
# some CUDA versions may not have runfiles available.
298+
echo "Validating CUDA download URL for ${ARCH_PATH}..."
299+
if ! validate_download_url "${download_url}"; then
300+
error_exit "CUDA runfile not available at: ${download_url}
301+
This may indicate that CUDA ${version} does not have a runfile for ${ARCH_PATH}.
302+
If running on GB200/aarch64, verify the CUDA version supports sbsa."
303+
fi
304+
echo "✅ Download URL validated"
305+
255306
echo "Downloading CUDA installation file: ${runfile}"
256307
# Use -c for resume support, -t 3 for retry, -q for quiet mode
257-
if ! wget -c -t 3 -q "https://developer.download.nvidia.com/compute/cuda/${version}/local_installers/${runfile}" -O "${runfile}"; then
308+
if ! wget -c -t 3 -q "${download_url}" -O "${runfile}"; then
258309
error_exit "CUDA installation file download failed: ${runfile}"
259310
fi
260311

@@ -474,10 +525,11 @@ function install_cuda_version {
474525

475526
# Get configuration for this version
476527
local cuda_full=${CUDA_FULL_VERSION[$version]}
477-
local runfile=${CUDA_RUNFILE[$version]}
478528
local cudnn_ver=${CUDNN_VERSIONS[$version]}
479529
local cuda_major=${CUDA_MAJOR[$version]}
480530

531+
local runfile=${CUDA_RUNFILE[$version]}
532+
481533
if [[ -z "$cuda_full" ]]; then
482534
error_exit "No configuration found for CUDA version: $version"
483535
fi
@@ -541,17 +593,15 @@ VALID_VERSIONS=("${!CUDA_FULL_VERSION[@]}")
541593
# Sort the versions for consistent ordering
542594
mapfile -t VALID_VERSIONS < <(printf '%s\n' "${VALID_VERSIONS[@]}" | sort -V)
543595

544-
# Parse command line arguments
545-
while test $# -gt 0; do
546-
echo "Processing argument: $1"
596+
# Parse positional CUDA version argument
597+
if [ $# -gt 0 ]; then
547598
if [[ " ${VALID_VERSIONS[*]} " =~ " $1 " ]]; then
548599
CUDA_VERSION=$1
549600
echo "Setting CUDA version to: $CUDA_VERSION"
550601
else
551-
error_exit "Invalid argument: $1, CUDA version must be one of: ${VALID_VERSIONS[*]}"
602+
error_exit "Invalid CUDA version: $1. Must be one of: ${VALID_VERSIONS[*]}"
552603
fi
553-
shift
554-
done
604+
fi
555605

556606
# Note: Version validation is already done in the while loop above
557607
# No need for redundant validation here
@@ -611,6 +661,7 @@ echo "⏱️ Total installation time: ${INSTALL_MINUTES}m ${INSTALL_SECONDS}s"
611661
echo "📊 ========================================="
612662
echo " 📋 CUDA & Related Libraries Installation Summary"
613663
echo "📊 ========================================="
664+
echo " Architecture: ${TARGETARCH} (${ARCH_PATH})"
614665
echo " CUDA : ${CUDA_VERSION}"
615666
echo " cuDNN : ${INSTALLED_CUDNN_VERSION:-(not available)}"
616667
if [ "$INSTALL_NCCL" -eq 1 ]; then

0 commit comments

Comments
 (0)