From 9f64ece55e9e55b03c50e10425c85201c5404f94 Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Mon, 21 Oct 2024 16:09:34 +0200 Subject: [PATCH] snapcraft/wrappers/nvidia-container-cli: support kernel-gpu-2404 When mesa-2404 snap is used in conjunction with kernel-gpu-2404 interface: snap connect mesa-2404:kernel-gpu-2404 pc-kernel and pc-kernel snap nvidia component is installed we can use it to get a required NVIDIA libraries instead of looking for them on the host which enables a support for LXD on Ubuntu Core scenario. Signed-off-by: Alexander Mikhalitsyn --- snapcraft/wrappers/nvidia-container-cli | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/snapcraft/wrappers/nvidia-container-cli b/snapcraft/wrappers/nvidia-container-cli index c7c2d6461..a40be9929 100755 --- a/snapcraft/wrappers/nvidia-container-cli +++ b/snapcraft/wrappers/nvidia-container-cli @@ -1,4 +1,18 @@ #!/bin/sh -# Set the root path -exec nvidia-container-cli.real -r /var/lib/snapd/hostfs/ "$@" +# +# This is a bit hacky, as we rely on a library names but at the moment, +# we don't have any way to distinguish generic mesa-2404 snap from +# mesa-2404 snap with NVIDIA drivers connected to it. (At least, I don't know one.) +# Let's do this like that for now at least for PoC purpose. +# +if snapctl is-connected gpu-2404 && + [ -f "${SNAP}/gpu-2404-2/usr/lib/x86_64-linux-gnu/libnvidia-ml.so" ] && + [ -f "${SNAP}/gpu-2404-2/usr/lib/x86_64-linux-gnu/libcuda.so" ]; +then + # We have NVIDIA drivers snap connected, let's use it + exec nvidia-container-cli.real "$@" +else + # Set the root path to use NVIDIA libraries from the host + exec nvidia-container-cli.real -r /var/lib/snapd/hostfs/ "$@" +fi