-
Notifications
You must be signed in to change notification settings - Fork 353
Make CDI device requests consistent with other methods #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elezar
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
elezar:make-cdi-device-extraction-consistent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -66,57 +66,66 @@ func NewCDIModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spe | |||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
func getDevicesFromSpec(logger logger.Interface, ociSpec oci.Spec, cfg *config.Config) ([]string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
cdiModifier := &cdiModifier{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
logger: logger, | ||||||||||||||||||||||||||||||||||||||||||||||||||
acceptDeviceListAsVolumeMounts: cfg.AcceptDeviceListAsVolumeMounts, | ||||||||||||||||||||||||||||||||||||||||||||||||||
acceptEnvvarUnprivileged: cfg.AcceptEnvvarUnprivileged, | ||||||||||||||||||||||||||||||||||||||||||||||||||
annotationPrefixes: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.AnnotationPrefixes, | ||||||||||||||||||||||||||||||||||||||||||||||||||
defaultKind: cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.DefaultKind, | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
return cdiModifier.getDevicesFromSpec(ociSpec) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: We should rename this type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
type cdiModifier struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+69
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||
logger logger.Interface | ||||||||||||||||||||||||||||||||||||||||||||||||||
acceptDeviceListAsVolumeMounts bool | ||||||||||||||||||||||||||||||||||||||||||||||||||
acceptEnvvarUnprivileged bool | ||||||||||||||||||||||||||||||||||||||||||||||||||
annotationPrefixes []string | ||||||||||||||||||||||||||||||||||||||||||||||||||
defaultKind string | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
func (c *cdiModifier) getDevicesFromSpec(ociSpec oci.Spec) ([]string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
rawSpec, err := ociSpec.Load() | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
annotationDevices, err := getAnnotationDevices(cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.AnnotationPrefixes, rawSpec.Annotations) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("failed to parse container annotations: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
if len(annotationDevices) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return annotationDevices, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
if rawSpec != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
annotationDevices, err := getAnnotationDevices(c.annotationPrefixes, rawSpec.Annotations) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("failed to parse container annotations: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
if len(annotationDevices) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return annotationDevices, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
container, err := image.NewCUDAImageFromSpec( | ||||||||||||||||||||||||||||||||||||||||||||||||||
rawSpec, | ||||||||||||||||||||||||||||||||||||||||||||||||||
image.WithLogger(logger), | ||||||||||||||||||||||||||||||||||||||||||||||||||
image.WithLogger(c.logger), | ||||||||||||||||||||||||||||||||||||||||||||||||||
image.WithAcceptDeviceListAsVolumeMounts(c.acceptDeviceListAsVolumeMounts), | ||||||||||||||||||||||||||||||||||||||||||||||||||
image.WithAcceptEnvvarUnprivileged(c.acceptEnvvarUnprivileged), | ||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
if cfg.AcceptDeviceListAsVolumeMounts { | ||||||||||||||||||||||||||||||||||||||||||||||||||
mountDevices := container.CDIDevicesFromMounts() | ||||||||||||||||||||||||||||||||||||||||||||||||||
if len(mountDevices) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return mountDevices, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
var devices []string | ||||||||||||||||||||||||||||||||||||||||||||||||||
seen := make(map[string]bool) | ||||||||||||||||||||||||||||||||||||||||||||||||||
for _, name := range container.VisibleDevicesFromEnvVar() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
for _, name := range container.VisibleDevices() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
if !parser.IsQualifiedName(name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
name = fmt.Sprintf("%s=%s", cfg.NVIDIAContainerRuntimeConfig.Modes.CDI.DefaultKind, name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
name = fmt.Sprintf("%s=%s", c.defaultKind, name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
if seen[name] { | ||||||||||||||||||||||||||||||||||||||||||||||||||
logger.Debugf("Ignoring duplicate device %q", name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
c.logger.Debugf("Ignoring duplicate device %q", name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
seen[name] = true | ||||||||||||||||||||||||||||||||||||||||||||||||||
devices = append(devices, name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
if len(devices) == 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
if cfg.AcceptEnvvarUnprivileged || image.IsPrivileged((*image.OCISpec)(rawSpec)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return devices, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
logger.Warningf("Ignoring devices specified in NVIDIA_VISIBLE_DEVICES: %v", devices) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
return devices, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// getAnnotationDevices returns a list of devices specified in the annotations. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed this function since we're returning all requests including:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: DevicesFromMounts has been renamed and turned private to the config pkg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It was not used outside this package.