#!/bin/sh # nvidia-module-options - derive NVIDIA kernel module options from the GPU # topology this guest was actually given. # # The image is shared by every deployment shape, so the options cannot be # baked in. The two that matter are mutually exclusive in practice and both # follow from what is visible on the guest PCI bus: # # RmEnableProtectedPcie=0x1 # Protected PCIe is the Hopper multi-GPU confidential mode, and it is the # only mode in which the VMM hands NVSwitches to the guest (vmm-cli # --ppcie attaches all GPUs *and* NVSwitches). So an NVSwitch visible in # the guest is exactly the PPCIe topology. Blackwell multi-GPU instead # uses MPT CC, where Fabric Manager stays on the host and the tenant only # ever sees GPUs -- enabling PPCIe there contradicts the ppcie-mode=off # that the CC provisioning flow sets on the GPUs. # # NVreg_NvLinkDisable=1 # A lone GPU with no fabric behind it would otherwise arm the NVLink # fabric-probe state machine and block on a Fabric Manager that is never # going to route anything, surfacing as NV_ERR_NVLINK_FABRIC_NOT_READY # (802). Only correct when the tenant has a single GPU: setting it on a # multi-GPU tenant would disable the very NVLink the workload needs. # # Deriving both from the live topology rather than a device-ID table means new # GPU generations need no change here. # # The result goes to /run/modprobe.d rather than /etc/modprobe.d: the rootfs is # dm-verity protected and read-only, and modprobe reads both. Nothing else in # this image ships an `options nvidia` line, so there is a single source. set -eu # Both are overridable only so this can be exercised end to end against a # synthetic PCI tree; the systemd unit sets neither. detect=${NVIDIA_GPU_DETECT:-/usr/bin/nvidia-gpu-detect} out_dir=${NVIDIA_MODPROBE_DIR:-/run/modprobe.d} out="$out_dir/nvidia-dstack.conf" gpus=$("$detect" count-gpus) if "$detect" nvswitch; then nvswitch=yes else nvswitch=no fi mkdir -p "$out_dir" { echo "# Generated by nvidia-module-options at boot. Do not edit." echo "# Detected topology: gpus=$gpus nvswitch=$nvswitch" if [ "$nvswitch" = yes ]; then echo 'options nvidia NVreg_RegistryDwords="RmEnableProtectedPcie=0x1"' elif [ "$gpus" -eq 1 ]; then echo 'options nvidia NVreg_NvLinkDisable=1' fi } >"$out" echo "nvidia-module-options: gpus=$gpus nvswitch=$nvswitch -> $out"