From 5eb3e851342e2b511270c1b9777df6ccf0b3a1d0 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Sun, 29 Sep 2024 22:41:09 +0200 Subject: [PATCH] pkg/nvidia: Clean up NVIDIA Management Library when no longer in use The NVIDIA Management Library API expects nvmlShutdown() to be called once it's no longer in use [1]. Fallout from 8dd2f8e80aad1b76659b44f20c346f75e647d65d [1] https://docs.nvidia.com/deploy/nvml-api/group__nvmlInitializationAndCleanup.html https://github.com/containers/toolbox/pull/1555 --- src/pkg/nvidia/nvidia.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pkg/nvidia/nvidia.go b/src/pkg/nvidia/nvidia.go index fdb924063..b38e073bc 100644 --- a/src/pkg/nvidia/nvidia.go +++ b/src/pkg/nvidia/nvidia.go @@ -74,6 +74,13 @@ func GenerateCDISpec() (*specs.Spec, error) { return nil, errors.New("failed to initialize NVIDIA Management Library") } } + + defer func() { + if err := nvmLib.Shutdown(); err != nvml.SUCCESS { + logrus.Debugf("Generating Container Device Interface for NVIDIA: failed to shutdown NVML: %s", + err) + } + }() } else { logrus.Debugf("Generating Container Device Interface for NVIDIA: Management Library not found: %s", reason)