mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Add enable-cuda-compat hook if required
This change adds the enable-cuda-compat hook to the incomming OCI runtime spec if the allow-cuda-compat-libs-from-container feature flag is not enabled. An update-ldcache hook is also injected to ensure that the required folders are processed. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
		
							parent
							
								
									fc65d3a784
								
							
						
					
					
						commit
						bd87c009ba
					
				| @ -73,6 +73,15 @@ func TestCompatLibs(t *testing.T) { | |||||||
| 			hostDriverVersion:                 "222.55.66", | 			hostDriverVersion:                 "222.55.66", | ||||||
| 			expectedContainerForwardCompatDir: "", | 			expectedContainerForwardCompatDir: "", | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			description: "numeric comparison is used; ldcache", | ||||||
|  | 			contents: map[string]string{ | ||||||
|  | 				"/etc/ld.so.cache": "", | ||||||
|  | 				"/usr/local/cuda/compat/libcuda.so.222.88.99": "", | ||||||
|  | 			}, | ||||||
|  | 			hostDriverVersion:                 "99.55.66", | ||||||
|  | 			expectedContainerForwardCompatDir: "/usr/local/cuda/compat", | ||||||
|  | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			description: "driver version empty; ldcache", | 			description: "driver version empty; ldcache", | ||||||
| 			contents: map[string]string{ | 			contents: map[string]string{ | ||||||
|  | |||||||
							
								
								
									
										24
									
								
								internal/discover/compat_libs.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								internal/discover/compat_libs.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | package discover | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"strings" | ||||||
|  | 
 | ||||||
|  | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||||||
|  | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | // NewCUDACompatHookDiscoverer creates a discoverer for a enable-cuda-compat hook.
 | ||||||
|  | // This hook is responsible for setting up CUDA compatibility in the container and depends on the host driver version.
 | ||||||
|  | func NewCUDACompatHookDiscoverer(logger logger.Interface, nvidiaCDIHookPath string, driver *root.Driver) Discover { | ||||||
|  | 	_, cudaVersionPattern := getCUDALibRootAndVersionPattern(logger, driver) | ||||||
|  | 	var args []string | ||||||
|  | 	if !strings.Contains(cudaVersionPattern, "*") { | ||||||
|  | 		args = append(args, "--host-driver-version="+cudaVersionPattern) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return CreateNvidiaCDIHook( | ||||||
|  | 		nvidiaCDIHookPath, | ||||||
|  | 		"enable-cuda-compat", | ||||||
|  | 		args..., | ||||||
|  | 	) | ||||||
|  | } | ||||||
| @ -23,6 +23,7 @@ import ( | |||||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" | ||||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/discover" | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/discover" | ||||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||||||
|  | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root" | ||||||
| 	"github.com/NVIDIA/nvidia-container-toolkit/internal/oci" | 	"github.com/NVIDIA/nvidia-container-toolkit/internal/oci" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -35,7 +36,7 @@ import ( | |||||||
| //	NVIDIA_GDRCOPY=enabled
 | //	NVIDIA_GDRCOPY=enabled
 | ||||||
| //
 | //
 | ||||||
| // If not devices are selected, no changes are made.
 | // If not devices are selected, no changes are made.
 | ||||||
| func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image image.CUDA) (oci.SpecModifier, error) { | func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image image.CUDA, driver *root.Driver) (oci.SpecModifier, error) { | ||||||
| 	if devices := image.VisibleDevicesFromEnvVar(); len(devices) == 0 { | 	if devices := image.VisibleDevicesFromEnvVar(); len(devices) == 0 { | ||||||
| 		logger.Infof("No modification required; no devices requested") | 		logger.Infof("No modification required; no devices requested") | ||||||
| 		return nil, nil | 		return nil, nil | ||||||
| @ -78,5 +79,10 @@ func NewFeatureGatedModifier(logger logger.Interface, cfg *config.Config, image | |||||||
| 		discoverers = append(discoverers, d) | 		discoverers = append(discoverers, d) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if !cfg.Features.AllowCUDACompatLibsFromContainer.IsEnabled() { | ||||||
|  | 		compatLibHookDiscoverer := discover.NewCUDACompatHookDiscoverer(logger, cfg.NVIDIACTKConfig.Path, driver) | ||||||
|  | 		discoverers = append(discoverers, compatLibHookDiscoverer) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return NewModifierFromDiscoverer(logger, discover.Merge(discoverers...)) | 	return NewModifierFromDiscoverer(logger, discover.Merge(discoverers...)) | ||||||
| } | } | ||||||
|  | |||||||
| @ -94,7 +94,7 @@ func newSpecModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Sp | |||||||
| 			} | 			} | ||||||
| 			modifiers = append(modifiers, graphicsModifier) | 			modifiers = append(modifiers, graphicsModifier) | ||||||
| 		case "feature-gated": | 		case "feature-gated": | ||||||
| 			featureGatedModifier, err := modifier.NewFeatureGatedModifier(logger, cfg, image) | 			featureGatedModifier, err := modifier.NewFeatureGatedModifier(logger, cfg, image, driver) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user