mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Resolve auto mode as cdi for fully-qualified names
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									84c7bf8b18
								
							
						
					
					
						commit
						82347eb9bc
					
				| @ -45,7 +45,7 @@ type nvidiaConfig struct { | |||||||
| type containerConfig struct { | type containerConfig struct { | ||||||
| 	Pid    int | 	Pid    int | ||||||
| 	Rootfs string | 	Rootfs string | ||||||
| 	Env    map[string]string | 	Image  image.CUDA | ||||||
| 	Nvidia *nvidiaConfig | 	Nvidia *nvidiaConfig | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -362,7 +362,7 @@ func getContainerConfig(hook HookConfig) (config containerConfig) { | |||||||
| 	return containerConfig{ | 	return containerConfig{ | ||||||
| 		Pid:    h.Pid, | 		Pid:    h.Pid, | ||||||
| 		Rootfs: s.Root.Path, | 		Rootfs: s.Root.Path, | ||||||
| 		Env:    image, | 		Image:  image, | ||||||
| 		Nvidia: getNvidiaConfig(&hook, image, s.Mounts, privileged), | 		Nvidia: getNvidiaConfig(&hook, image, s.Mounts, privileged), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -78,10 +78,6 @@ func doPrestart() { | |||||||
| 	} | 	} | ||||||
| 	cli := hook.NvidiaContainerCLI | 	cli := hook.NvidiaContainerCLI | ||||||
| 
 | 
 | ||||||
| 	if !hook.NVIDIAContainerRuntimeHook.SkipModeDetection && info.ResolveAutoMode(&logInterceptor{}, hook.NVIDIAContainerRuntime.Mode) != "legacy" { |  | ||||||
| 		log.Panicln("invoking the NVIDIA Container Runtime Hook directly (e.g. specifying the docker --gpus flag) is not supported. Please use the NVIDIA Container Runtime (e.g. specify the --runtime=nvidia flag) instead.") |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	container := getContainerConfig(*hook) | 	container := getContainerConfig(*hook) | ||||||
| 	nvidia := container.Nvidia | 	nvidia := container.Nvidia | ||||||
| 	if nvidia == nil { | 	if nvidia == nil { | ||||||
| @ -89,6 +85,10 @@ func doPrestart() { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if !hook.NVIDIAContainerRuntimeHook.SkipModeDetection && info.ResolveAutoMode(&logInterceptor{}, hook.NVIDIAContainerRuntime.Mode, container.Image) != "legacy" { | ||||||
|  | 		log.Panicln("invoking the NVIDIA Container Runtime Hook directly (e.g. specifying the docker --gpus flag) is not supported. Please use the NVIDIA Container Runtime (e.g. specify the --runtime=nvidia flag) instead.") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	rootfs := getRootfsPath(container) | 	rootfs := getRootfsPath(container) | ||||||
| 
 | 
 | ||||||
| 	args := []string{getCLIPath(cli)} | 	args := []string{getCLIPath(cli)} | ||||||
|  | |||||||
| @ -17,7 +17,9 @@ | |||||||
| package info | package info | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" | ||||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||||||
|  | 	"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" | ||||||
| 	"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info" | 	"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -32,17 +34,17 @@ type resolver struct { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ResolveAutoMode determines the correct mode for the platform if set to "auto"
 | // ResolveAutoMode determines the correct mode for the platform if set to "auto"
 | ||||||
| func ResolveAutoMode(logger logger.Interface, mode string) (rmode string) { | func ResolveAutoMode(logger logger.Interface, mode string, image image.CUDA) (rmode string) { | ||||||
| 	nvinfo := info.New() | 	nvinfo := info.New() | ||||||
| 	r := resolver{ | 	r := resolver{ | ||||||
| 		logger: logger, | 		logger: logger, | ||||||
| 		info:   nvinfo, | 		info:   nvinfo, | ||||||
| 	} | 	} | ||||||
| 	return r.resolveMode(mode) | 	return r.resolveMode(mode, image) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // resolveMode determines the correct mode for the platform if set to "auto"
 | // resolveMode determines the correct mode for the platform if set to "auto"
 | ||||||
| func (r resolver) resolveMode(mode string) (rmode string) { | func (r resolver) resolveMode(mode string, image image.CUDA) (rmode string) { | ||||||
| 	if mode != "auto" { | 	if mode != "auto" { | ||||||
| 		return mode | 		return mode | ||||||
| 	} | 	} | ||||||
| @ -50,6 +52,10 @@ func (r resolver) resolveMode(mode string) (rmode string) { | |||||||
| 		r.logger.Infof("Auto-detected mode as '%v'", rmode) | 		r.logger.Infof("Auto-detected mode as '%v'", rmode) | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
|  | 	if onlyFullyQualifiedCDIDevices(image) { | ||||||
|  | 		return "cdi" | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	isTegra, reason := r.info.IsTegraSystem() | 	isTegra, reason := r.info.IsTegraSystem() | ||||||
| 	r.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason) | 	r.logger.Debugf("Is Tegra-based system? %v: %v", isTegra, reason) | ||||||
| 
 | 
 | ||||||
| @ -62,3 +68,14 @@ func (r resolver) resolveMode(mode string) (rmode string) { | |||||||
| 
 | 
 | ||||||
| 	return "legacy" | 	return "legacy" | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func onlyFullyQualifiedCDIDevices(image image.CUDA) bool { | ||||||
|  | 	var hasCDIdevice bool | ||||||
|  | 	for _, device := range image.DevicesFromEnvvars("NVIDIA_VISIBLE_DEVICES").List() { | ||||||
|  | 		if !cdi.IsQualifiedName(device) { | ||||||
|  | 			return false | ||||||
|  | 		} | ||||||
|  | 		hasCDIdevice = true | ||||||
|  | 	} | ||||||
|  | 	return hasCDIdevice | ||||||
|  | } | ||||||
|  | |||||||
| @ -72,7 +72,7 @@ func newSpecModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Sp | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	mode := info.ResolveAutoMode(logger, cfg.NVIDIAContainerRuntimeConfig.Mode) | 	mode := info.ResolveAutoMode(logger, cfg.NVIDIAContainerRuntimeConfig.Mode, image) | ||||||
| 	modeModifier, err := newModeModifier(logger, mode, cfg, ociSpec, argv) | 	modeModifier, err := newModeModifier(logger, mode, cfg, ociSpec, argv) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user