mirror of
https://github.com/moby/moby.git
synced 2026-06-24 08:48:23 +00:00
daemon/devices: Turn RegisterGPUDeviceDrivers into func
Change GPU device driver registration from init-time function assignment to direct function exports. This removes the init() function and global function variable pattern in favor of a more explicit approach. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -10,13 +10,10 @@ import (
|
||||
"github.com/moby/moby/v2/daemon/config"
|
||||
"github.com/moby/moby/v2/daemon/internal/capabilities"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"tags.cncf.io/container-device-interface/pkg/cdi"
|
||||
)
|
||||
|
||||
var deviceDrivers = map[string]*deviceDriver{}
|
||||
|
||||
var RegisterGPUDeviceDrivers = func(_ *cdi.Cache) {}
|
||||
|
||||
type deviceListing struct {
|
||||
Devices []system.DeviceInfo
|
||||
Warnings []string
|
||||
|
||||
@@ -2,14 +2,10 @@ package daemon
|
||||
|
||||
import "tags.cncf.io/container-device-interface/pkg/cdi"
|
||||
|
||||
func init() {
|
||||
RegisterGPUDeviceDrivers = registerGPUDeviceDrivers
|
||||
}
|
||||
|
||||
// registerGPUDeviceDrivers registers GPU device drivers.
|
||||
// RegisterGPUDeviceDrivers registers GPU device drivers.
|
||||
// If the cdiCache is provided, it is used to detect presence of CDI specs for AMD GPUs.
|
||||
// For NVIDIA GPUs, presence of CDI specs is detected by checking for the nvidia-cdi-hook binary.
|
||||
func registerGPUDeviceDrivers(cdiCache *cdi.Cache) {
|
||||
func RegisterGPUDeviceDrivers(cdiCache *cdi.Cache) {
|
||||
// Register NVIDIA device drivers.
|
||||
if nvidiaDrivers := getNVIDIADeviceDrivers(); len(nvidiaDrivers) > 0 {
|
||||
for name, driver := range nvidiaDrivers {
|
||||
|
||||
8
daemon/devices_nonlinux.go
Normal file
8
daemon/devices_nonlinux.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build !linux
|
||||
|
||||
package daemon
|
||||
|
||||
import "tags.cncf.io/container-device-interface/pkg/cdi"
|
||||
|
||||
// RegisterGPUDeviceDrivers is a no-op on non-Linux platforms.
|
||||
func RegisterGPUDeviceDrivers(_ *cdi.Cache) {}
|
||||
Reference in New Issue
Block a user