Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spark-rapids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ profile id or the name (ie 3g.20gb) can be specified. For example:
--metadata=^:^MIG_CGI='3g.20gb,9'
```
Create cluster with MIG enabled:

The MIG startup script runs only on worker nodes. It skips the master node
so that the required MIG reboot does not interrupt Dataproc master service
initialization.

```bash
REGION=<region>
Expand Down
167 changes: 141 additions & 26 deletions spark-rapids/mig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

set -euxo pipefail

readonly ROLE="$(/usr/share/google/get_metadata_value attributes/dataproc-role)"

function os_id() {
grep '^ID=' /etc/os-release | cut -d= -f2 | xargs
}
Expand All @@ -50,6 +52,10 @@ function is_debian12() {
is_debian && [[ "$(os_version)" == '12'* ]]
}

function is_debian13() {
is_debian && [[ "$(os_version)" == '13'* ]]
}

function is_ubuntu() {
[[ "$(os_id)" == 'ubuntu' ]]
}
Expand All @@ -66,6 +72,10 @@ function is_ubuntu22() {
is_ubuntu && [[ "$(os_version)" == '22.04'* ]]
}

function is_ubuntu24() {
is_ubuntu && [[ "$(os_version)" == '24.04'* ]]
}

function is_rocky() {
[[ "$(os_id)" == 'rocky' ]]
}
Expand Down Expand Up @@ -94,6 +104,26 @@ function get_metadata_attribute() {
/usr/share/google/get_metadata_value "attributes/${attribute_name}" || echo -n "${default_value}"
}

REBOOT_FOR_CGROUP_V1=0

function configure_cgroup_v1_for_yarn_gpu_isolation() {
if ! is_debian13 || [[ ! -f /sys/fs/cgroup/cgroup.controllers ]]; then
return
fi

# YARN's GPU isolation requires the cgroup v1 devices controller. Debian 13
# defaults to cgroup v2, and systemd 257 requires both kernel parameters to
# temporarily enable its legacy hierarchy.
local -r cgroup_v1_params="systemd.unified_cgroup_hierarchy=0 SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE=1"
if ! grep -q 'SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE=1' /etc/default/grub; then
sed -i \
"s|^GRUB_CMDLINE_LINUX_DEFAULT=\"\\(.*\\)\"|GRUB_CMDLINE_LINUX_DEFAULT=\"\\1 ${cgroup_v1_params}\"|" \
/etc/default/grub
update-grub
fi
REBOOT_FOR_CGROUP_V1=1
}

CA_TMPDIR="$(mktemp -u -d -p /run/tmp -t ca_dir-XXXX)"
PSN="$(get_metadata_attribute private_secret_name)"
readonly PSN
Expand Down Expand Up @@ -172,19 +202,19 @@ function configure_dkms_certs() {

function clear_dkms_key {
if [[ -z "${PSN}" ]]; then
echo "No signing secret provided. skipping" >2
echo "No signing secret provided. skipping" >&2
return 0
fi
echo "WARN -- PURGING SIGNING MATERIAL -- WARN" >2
echo "future dkms runs will not use correct signing key" >2
echo "WARN -- PURGING SIGNING MATERIAL -- WARN" >&2
echo "future dkms runs will not use correct signing key" >&2
rm -rf "${CA_TMPDIR}" /var/lib/dkms/mok.key /var/lib/shim-signed/mok/MOK.priv
}

function add_contrib_components() {
if ! is_debian ; then
return
fi
if is_debian12 ; then
if is_debian12 || is_debian13 ; then
# Include in sources file components on which nvidia-open-kernel-dkms depends
local -r debian_sources="/etc/apt/sources.list.d/debian.sources"
local components="main contrib"
Expand Down Expand Up @@ -217,12 +247,38 @@ NVIDIA_DRIVER_VERSION=$(get_metadata_attribute 'driver-version' '550.54.15') #53
CUDA_VERSION_MAJOR="${CUDA_VERSION%.*}" #12.2

# EXCEPTIONS
# Change CUDA version for Ubuntu 18 (Cuda 12.1.1 - Driver v530.30.02 is the latest version supported by Ubuntu 18)
# Debian 12 security kernels use the four-argument pci_resize_resource API,
# which is incompatible with NVIDIA 550 open modules.
if is_debian12 ; then
NVIDIA_DRIVER_VERSION=$(get_metadata_attribute 'driver-version' '580.95.05')
if [[ "${NVIDIA_DRIVER_VERSION%%.*}" == "550" ]]; then
echo "WARNING: Driver version 550 is incompatible with Debian 12 kernel. Overriding to 580.95.05" >&2
NVIDIA_DRIVER_VERSION='580.95.05'
fi
USE_REPO_INSTALL="true"
elif is_debian13 ; then
# The Debian 13 repository starts at driver 590 and CUDA 13.
CUDA_VERSION=$(get_metadata_attribute 'cuda-version' '13.0')
NVIDIA_DRIVER_VERSION=$(get_metadata_attribute 'driver-version' '590')
CUDA_VERSION_MAJOR="${CUDA_VERSION%.*}"
if [[ "${NVIDIA_DRIVER_VERSION%%.*}" -lt 590 ]]; then
echo "WARNING: Driver version ${NVIDIA_DRIVER_VERSION} is unavailable for Debian 13. Overriding to 590" >&2
NVIDIA_DRIVER_VERSION='590'
fi
USE_REPO_INSTALL="true"
fi

# Change CUDA and driver versions for Ubuntu-specific repository availability.
if [[ "${OS_NAME}" == "ubuntu" ]]; then
if is_ubuntu18 ; then
CUDA_VERSION=$(get_metadata_attribute 'cuda-version' '12.1.1') #12.1.1
NVIDIA_DRIVER_VERSION=$(get_metadata_attribute 'driver-version' '530.30.02') #530.30.02
CUDA_VERSION_MAJOR="${CUDA_VERSION%.*}" #12.1
elif is_ubuntu24 ; then
CUDA_VERSION=$(get_metadata_attribute 'cuda-version' '12.6.0')
NVIDIA_DRIVER_VERSION=$(get_metadata_attribute 'driver-version' '580.95.05')
CUDA_VERSION_MAJOR="${CUDA_VERSION%.*}"
USE_REPO_INSTALL="true"
fi
fi

Expand Down Expand Up @@ -296,30 +352,51 @@ function install_nvidia_gpu_driver() {

execute_with_retries "apt-get install -y -q 'linux-headers-$(uname -r)'"

curl -fsSL --retry-connrefused --retry 3 --retry-max-time 5 \
"${LOCAL_DEB_URL}" -o /tmp/local-installer.deb
if [[ "${USE_REPO_INSTALL:-false}" == "true" ]]; then
execute_with_retries \
"curl -fsSL --retry-connrefused --retry 3 --retry-max-time 5 https://developer.download.nvidia.com/compute/cuda/repos/${shortname}/x86_64/cuda-keyring_1.1-1_all.deb -o /tmp/cuda-keyring_1.1-1_all.deb"
execute_with_retries "dpkg -i /tmp/cuda-keyring_1.1-1_all.deb"
rm -f /tmp/cuda-keyring_1.1-1_all.deb
add_contrib_components
execute_with_retries "apt-get update"
Comment thread
nvliyuan marked this conversation as resolved.
Resolved

dpkg -i /tmp/local-installer.deb
rm /tmp/local-installer.deb
cp ${DIST_KEYRING_DIR}/cuda-*-keyring.gpg /usr/share/keyrings/
execute_with_retries "apt-get install -y -q --no-install-recommends dkms"
execute_with_retries \
"apt-get install -y -q --no-install-recommends nvidia-driver-pinning-${NVIDIA_DRIVER_VERSION_PREFIX}"

add_contrib_components
configure_dkms_certs
execute_with_retries \
"apt-get install -y -q --no-install-recommends nvidia-kernel-open-dkms nvidia-driver-cuda"
clear_dkms_key
Comment thread
nvliyuan marked this conversation as resolved.
Resolved

execute_with_retries "apt-get update"
execute_with_retries \
"apt-get install -y -q --no-install-recommends cuda-toolkit-${CUDA_VERSION_MAJOR//./-}"
else
curl -fsSL --retry-connrefused --retry 3 --retry-max-time 5 \
"${LOCAL_DEB_URL}" -o /tmp/local-installer.deb

## EXCEPTION
if is_debian10 ; then
apt-get remove -y libglvnd0
apt-get install -y ca-certificates-java
fi
dpkg -i /tmp/local-installer.deb
rm /tmp/local-installer.deb
cp ${DIST_KEYRING_DIR}/cuda-*-keyring.gpg /usr/share/keyrings/

configure_dkms_certs
execute_with_retries "apt-get install -y -q nvidia-kernel-open-dkms"
clear_dkms_key
execute_with_retries \
"apt-get install -y -q --no-install-recommends cuda-drivers-${NVIDIA_DRIVER_VERSION_PREFIX}"
execute_with_retries \
"apt-get install -y -q --no-install-recommends cuda-toolkit-${CUDA_VERSION_MAJOR//./-}"
add_contrib_components

execute_with_retries "apt-get update"

## EXCEPTION
if is_debian10 ; then
apt-get remove -y libglvnd0
apt-get install -y ca-certificates-java
fi

configure_dkms_certs
execute_with_retries "apt-get install -y -q nvidia-kernel-open-dkms"
clear_dkms_key
execute_with_retries \
"apt-get install -y -q --no-install-recommends cuda-drivers-${NVIDIA_DRIVER_VERSION_PREFIX}"
execute_with_retries \
"apt-get install -y -q --no-install-recommends cuda-toolkit-${CUDA_VERSION_MAJOR//./-}"
fi

modprobe nvidia

Expand Down Expand Up @@ -381,6 +458,20 @@ function install_nvidia_gpu_driver() {
-o cuda.run
bash cuda.run --silent --toolkit --no-opengl-libs
rm cuda.run
elif [[ "${USE_REPO_INSTALL:-false}" == "true" ]]; then
execute_with_retries \
"curl -fsSL --retry-connrefused --retry 3 --retry-max-time 5 https://developer.download.nvidia.com/compute/cuda/repos/${shortname}/x86_64/cuda-keyring_1.1-1_all.deb -o /tmp/cuda-keyring_1.1-1_all.deb"
execute_with_retries "dpkg -i /tmp/cuda-keyring_1.1-1_all.deb"
rm -f /tmp/cuda-keyring_1.1-1_all.deb
execute_with_retries "apt-get update"

execute_with_retries "apt-get install -y -q --no-install-recommends dkms"
configure_dkms_certs
for pkg in "nvidia-driver-${NVIDIA_DRIVER_VERSION_PREFIX}-open" \
"cuda-toolkit-${CUDA_VERSION_MAJOR//./-}" ; do
execute_with_retries "apt-get install -y -q --no-install-recommends ${pkg}"
done
clear_dkms_key
else
# Install from repo provided by NV
readonly UBUNTU_REPO_CUDA_PIN="${NVIDIA_REPO_URL}/cuda-${shortname}.pin"
Expand Down Expand Up @@ -454,12 +545,12 @@ function configure_mig_cgi() {
# Verify if compatible linux distros and secure boot options are used
function check_os_and_secure_boot() {
if is_debian ; then
if ! is_debian10 && ! is_debian11 && ! is_debian12 ; then
if ! is_debian10 && ! is_debian11 && ! is_debian12 && ! is_debian13 ; then
echo "Error: The Debian version ($(os_version)) is not supported. Please use a compatible Debian version."
exit 1
fi
elif is_ubuntu ; then
if ! is_ubuntu18 && ! is_ubuntu20 && ! is_ubuntu22 ; then
if ! is_ubuntu18 && ! is_ubuntu20 && ! is_ubuntu22 && ! is_ubuntu24 ; then
echo "Error: The Ubuntu version ($(os_version)) is not supported. Please use a compatible Ubuntu version."
exit 1
fi
Expand Down Expand Up @@ -503,6 +594,15 @@ function remove_old_backports {
}

function main() {
# Rebooting a master before Dataproc initialization completes causes its
# master-only services to be initialized twice. MIG is only needed on workers.
# Note: Single-node clusters (where ROLE=Master and primary workers=0) will
# skip MIG configuration by design.
if [[ "${ROLE}" == "Master" ]]; then
echo "Skipping MIG setup and reboot on Dataproc master"
return
fi

if [[ ${OS_NAME} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then
remove_old_backports
fi
Expand All @@ -527,6 +627,7 @@ function main() {
fi

if (lspci | grep -q NVIDIA); then
configure_cgroup_v1_for_yarn_gpu_isolation
if [[ $META_MIG_VALUE -ne 0 ]]; then
# if the first invocation, the NVIDIA drivers and tools are not installed
if [[ -f "/usr/bin/nvidia-smi" ]]; then
Expand All @@ -535,6 +636,11 @@ function main() {
NUM_GPUS_WITH_DIFF_MIG_MODES=`/usr/bin/nvidia-smi --query-gpu=mig.mode.current --format=csv,noheader | uniq | wc -l`
if [[ $NUM_GPUS_WITH_DIFF_MIG_MODES -eq 1 ]]; then
if (/usr/bin/nvidia-smi --query-gpu=mig.mode.current --format=csv,noheader | grep Enabled); then
if [[ $REBOOT_FOR_CGROUP_V1 -ne 0 ]]; then
echo "Rebooting to enable the cgroup v1 devices controller"
reboot
exit 0
fi
echo "MIG is enabled on all GPUs, configuring instances"
configure_mig_cgi
exit 0
Expand All @@ -560,6 +666,11 @@ function main() {

if [[ ${META_MIG_VALUE} -ne 0 ]]; then
enable_mig
if [[ $REBOOT_FOR_CGROUP_V1 -ne 0 ]]; then
echo "Rebooting to enable MIG and the cgroup v1 devices controller"
reboot
exit 0
fi
NUM_GPUS_WITH_DIFF_MIG_MODES=`/usr/bin/nvidia-smi --query-gpu=mig.mode.current --format=csv,noheader | uniq | wc -l`
if [[ NUM_GPUS_WITH_DIFF_MIG_MODES -eq 1 ]]; then
if (/usr/bin/nvidia-smi --query-gpu=mig.mode.current --format=csv,noheader | grep Enabled); then
Expand All @@ -575,6 +686,10 @@ function main() {
fi
else
echo "Not enabling MIG"
if [[ $REBOOT_FOR_CGROUP_V1 -ne 0 ]]; then
echo "Rebooting to enable the cgroup v1 devices controller"
reboot
fi
fi
fi
}
Expand Down
Loading
Loading