Skip to content
Open
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
41 changes: 40 additions & 1 deletion vgpu-manager/rhel8/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DRIVER_VERSION=${DRIVER_VERSION:?"Missing driver version"}
DRIVER_RESET_RETRIES=10
DELAY_BEFORE_VF_CREATION=${DELAY_BEFORE_VF_CREATION:-15}
RUN_DIR=/run/nvidia
NVIDIA_MODULE_PARAMS=()

# Mount the driver rootfs into the run directory with the exception of sysfs.
_mount_rootfs() {
Expand Down Expand Up @@ -52,14 +53,52 @@ _set_fw_search_path() {
echo -n "$nv_fw_search_path" > $fw_path_config_file
}

# For each kernel module configuration file mounted into the container,
# parse the file contents and extract the custom module parameters that
# are to be passed as input to 'modprobe'.
#
# Assumptions:
# - Configuration file is named nvidia.conf
# - Configuration file is mounted inside the container at /drivers.
# - Each line in the file contains at least one parameter, where parameters on the same line
# are space delimited. It is up to the user to properly format the file to ensure
# the correct set of parameters are passed to 'modprobe'.
_get_module_params() {
local base_path="/drivers"
# nvidia
if [ -f "${base_path}/nvidia.conf" ]; then
while IFS="" read -r param || [ -n "$param" ]; do
NVIDIA_MODULE_PARAMS+=("$param")
done <"${base_path}/nvidia.conf"
echo "Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]}"
fi
}

_install_driver() {
local tmp_dir=$(mktemp -d)

sh NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}-vgpu-kvm.run --ui=none --no-questions --tmpdir ${tmp_dir} --no-systemd
}

# Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
# Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
_load_driver() {
# Unload modules if they're already loaded so we can reload with custom parameters
if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
echo "NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
rmmod nvidia_vgpu_vfio 2>/dev/null || true
rmmod nvidia 2>/dev/null || true
fi

echo "Parsing kernel module parameters..."
_get_module_params

echo "Loading NVIDIA driver kernel modules..."
set -o xtrace +o nounset
modprobe nvidia "${NVIDIA_MODULE_PARAMS[@]}"
modprobe nvidia_vgpu_vfio
set +o xtrace -o nounset

# Start vGPU daemons
/usr/bin/nvidia-vgpud
/usr/bin/nvidia-vgpu-mgr &

Expand Down
41 changes: 40 additions & 1 deletion vgpu-manager/rhel9/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DRIVER_VERSION=${DRIVER_VERSION:?"Missing driver version"}
DRIVER_RESET_RETRIES=10
DELAY_BEFORE_VF_CREATION=${DELAY_BEFORE_VF_CREATION:-15}
RUN_DIR=/run/nvidia
NVIDIA_MODULE_PARAMS=()

# Mount the driver rootfs into the run directory with the exception of sysfs.
_mount_rootfs() {
Expand Down Expand Up @@ -64,14 +65,52 @@ _set_fw_search_path() {
echo -n "$nv_fw_search_path" > $fw_path_config_file
}

# For each kernel module configuration file mounted into the container,
# parse the file contents and extract the custom module parameters that
# are to be passed as input to 'modprobe'.
#
# Assumptions:
# - Configuration file is named nvidia.conf
# - Configuration file is mounted inside the container at /drivers.
# - Each line in the file contains at least one parameter, where parameters on the same line
# are space delimited. It is up to the user to properly format the file to ensure
# the correct set of parameters are passed to 'modprobe'.
_get_module_params() {
local base_path="/drivers"
# nvidia
if [ -f "${base_path}/nvidia.conf" ]; then
while IFS="" read -r param || [ -n "$param" ]; do
NVIDIA_MODULE_PARAMS+=("$param")
done <"${base_path}/nvidia.conf"
echo "Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]}"
fi
}

_install_driver() {
local tmp_dir=$(mktemp -d)

sh NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}-vgpu-kvm.run --ui=none --no-questions --tmpdir ${tmp_dir} --no-systemd
}

# Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
# Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
_load_driver() {
# Unload modules if they're already loaded so we can reload with custom parameters
if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
echo "NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
rmmod nvidia_vgpu_vfio 2>/dev/null || true
rmmod nvidia 2>/dev/null || true
fi

echo "Parsing kernel module parameters..."
_get_module_params

echo "Loading NVIDIA driver kernel modules..."
set -o xtrace +o nounset
modprobe nvidia "${NVIDIA_MODULE_PARAMS[@]}"
modprobe nvidia_vgpu_vfio
set +o xtrace -o nounset

# Start vGPU daemons
/usr/bin/nvidia-vgpud
/usr/bin/nvidia-vgpu-mgr &

Expand Down
41 changes: 40 additions & 1 deletion vgpu-manager/ubuntu22.04/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DRIVER_RESET_RETRIES=10
DELAY_BEFORE_VF_CREATION=${DELAY_BEFORE_VF_CREATION:-15}
KERNEL_VERSION=$(uname -r)
RUN_DIR=/run/nvidia
NVIDIA_MODULE_PARAMS=()

export DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -133,8 +134,46 @@ _set_fw_search_path() {
echo -n "$nv_fw_search_path" > $fw_path_config_file
}

# Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
# For each kernel module configuration file mounted into the container,
# parse the file contents and extract the custom module parameters that
# are to be passed as input to 'modprobe'.
#
# Assumptions:
# - Configuration file is named nvidia.conf
# - Configuration file is mounted inside the container at /drivers.
# - Each line in the file contains at least one parameter, where parameters on the same line
# are space delimited. It is up to the user to properly format the file to ensure
# the correct set of parameters are passed to 'modprobe'.
_get_module_params() {
local base_path="/drivers"
# nvidia
if [ -f "${base_path}/nvidia.conf" ]; then
while IFS="" read -r param || [ -n "$param" ]; do
NVIDIA_MODULE_PARAMS+=("$param")
done <"${base_path}/nvidia.conf"
echo "Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]}"
fi
}

# Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
_load_driver() {
# Unload modules if they're already loaded so we can reload with custom parameters
if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
echo "NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
rmmod nvidia_vgpu_vfio 2>/dev/null || true
rmmod nvidia 2>/dev/null || true
fi

echo "Parsing kernel module parameters..."
_get_module_params

echo "Loading NVIDIA driver kernel modules..."
set -o xtrace +o nounset
modprobe nvidia "${NVIDIA_MODULE_PARAMS[@]}"
modprobe nvidia_vgpu_vfio
set +o xtrace -o nounset

# Start vGPU daemons
/usr/bin/nvidia-vgpud
/usr/bin/nvidia-vgpu-mgr &

Expand Down
41 changes: 40 additions & 1 deletion vgpu-manager/ubuntu24.04/nvidia-driver
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DRIVER_RESET_RETRIES=10
DELAY_BEFORE_VF_CREATION=${DELAY_BEFORE_VF_CREATION:-15}
KERNEL_VERSION=$(uname -r)
RUN_DIR=/run/nvidia
NVIDIA_MODULE_PARAMS=()

export DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -133,8 +134,46 @@ _install_driver() {
sh NVIDIA-Linux-${DRIVER_ARCH}-${DRIVER_VERSION}-vgpu-kvm.run --ui=none --no-questions --tmpdir ${tmp_dir} --no-systemd
}

# Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
# For each kernel module configuration file mounted into the container,
# parse the file contents and extract the custom module parameters that
# are to be passed as input to 'modprobe'.
#
# Assumptions:
# - Configuration file is named nvidia.conf
# - Configuration file is mounted inside the container at /drivers.
# - Each line in the file contains at least one parameter, where parameters on the same line
# are space delimited. It is up to the user to properly format the file to ensure
# the correct set of parameters are passed to 'modprobe'.
_get_module_params() {
local base_path="/drivers"
# nvidia
if [ -f "${base_path}/nvidia.conf" ]; then
while IFS="" read -r param || [ -n "$param" ]; do
NVIDIA_MODULE_PARAMS+=("$param")
done <"${base_path}/nvidia.conf"
echo "Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]}"
fi
}

# Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
_load_driver() {
# Unload modules if they're already loaded so we can reload with custom parameters
if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
echo "NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
rmmod nvidia_vgpu_vfio 2>/dev/null || true
rmmod nvidia 2>/dev/null || true
fi

echo "Parsing kernel module parameters..."
_get_module_params

echo "Loading NVIDIA driver kernel modules..."
set -o xtrace +o nounset
modprobe nvidia "${NVIDIA_MODULE_PARAMS[@]}"
modprobe nvidia_vgpu_vfio
set +o xtrace -o nounset

# Start vGPU daemons
/usr/bin/nvidia-vgpud
/usr/bin/nvidia-vgpu-mgr &

Expand Down