mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Create device nodes in JIT-CDI mode
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
54ea4a24a7
commit
90b76ace37
@ -18,6 +18,7 @@ package modifier
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"tags.cncf.io/container-device-interface/pkg/parser"
|
||||
@ -28,6 +29,7 @@ import (
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/modifier/cdi"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/system/nvdevices"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec"
|
||||
)
|
||||
@ -204,6 +206,8 @@ func generateAutomaticCDISpec(logger logger.Interface, cfg *config.Config, drive
|
||||
identifiers = append(identifiers, id)
|
||||
}
|
||||
|
||||
tryCreateDeviceNodes(logger, driver, identifiers...)
|
||||
|
||||
deviceSpecs, err := cdilib.GetDeviceSpecsByID(identifiers...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get CDI device specs: %w", err)
|
||||
@ -221,3 +225,22 @@ func generateAutomaticCDISpec(logger logger.Interface, cfg *config.Config, drive
|
||||
spec.WithClass("gpu"),
|
||||
)
|
||||
}
|
||||
|
||||
func tryCreateDeviceNodes(logger logger.Interface, driver *root.Driver, identifiers ...string) {
|
||||
devices, err := nvdevices.New(
|
||||
nvdevices.WithLogger(logger),
|
||||
nvdevices.WithDevRoot(driver.Root),
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := devices.CreateNVIDIAControlDevices(); err != nil {
|
||||
logger.Warningf("Failed to create control devices: %v", err)
|
||||
}
|
||||
|
||||
// We run nvidia-smi -L to force the creation of the device nodes.
|
||||
nvidiaSMI := exec.Command("nvidia-smi", "-L")
|
||||
if err := nvidiaSMI.Run(); err != nil {
|
||||
logger.Warningf("Failed to run nvidia-smi: %v", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user