Merge pull request #21180 from rhatdan/nvidia

Make --gpus work with nvidia gpus
This commit is contained in:
openshift-merge-bot[bot] 2024-01-30 14:59:02 +00:00 committed by GitHub
commit c41c30bedd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 27 additions and 12 deletions

View File

@ -700,6 +700,10 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
)
_ = cmd.RegisterFlagCompletionFunc(gidmapFlagName, completion.AutocompleteNone)
gpuFlagName := "gpus"
createFlags.StringSliceVar(&cf.GPUs, gpuFlagName, []string{}, "GPU devices to add to the container ('all' to pass all GPUs)")
_ = cmd.RegisterFlagCompletionFunc(gpuFlagName, completion.AutocompleteNone)
uidmapFlagName := "uidmap"
createFlags.StringSliceVar(
&cf.UIDMap,

View File

@ -80,11 +80,6 @@ func runFlags(cmd *cobra.Command) {
flags.StringVar(&runOpts.DetachKeys, detachKeysFlagName, containerConfig.DetachKeys(), "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-cf`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`")
_ = cmd.RegisterFlagCompletionFunc(detachKeysFlagName, common.AutocompleteDetachKeys)
gpuFlagName := "gpus"
flags.String(gpuFlagName, "", "This is a Docker specific option and is a NOOP")
_ = cmd.RegisterFlagCompletionFunc(gpuFlagName, completion.AutocompleteNone)
_ = flags.MarkHidden("gpus")
passwdFlagName := "passwd"
flags.BoolVar(&runOpts.Passwd, passwdFlagName, true, "add entries to /etc/passwd and /etc/group")

View File

@ -0,0 +1,8 @@
####> This option file is used in:
####> podman create, pod clone, pod create, run
####> If file is edited, make sure the changes
####> are applicable to all of those.
#### **--gpus**=*ENTRY*
GPU devices to add to the container ('all' to pass all GPUs) Currently only
Nvidia devices are supported.

View File

@ -159,6 +159,8 @@ See [**Environment**](#environment) note below for precedence and examples.
@@option gidmap.container
@@option gpus
@@option group-add
@@option group-entry

View File

@ -41,6 +41,8 @@ Note: the pod implements devices by storing the initial configuration passed by
@@option gidmap.pod
@@option gpus
#### **--help**, **-h**
Print usage statement.

View File

@ -80,6 +80,8 @@ Set the exit policy of the pod when the last container exits. Supported policie
@@option gidmap.pod
@@option gpus
#### **--help**, **-h**
Print usage statement.

View File

@ -193,6 +193,8 @@ See [**Environment**](#environment) note below for precedence and examples.
@@option gidmap.container
@@option gpus
@@option group-add
@@option group-entry

View File

@ -167,6 +167,7 @@ type ContainerCreateOptions struct {
EnvFile []string
Expose []string
GIDMap []string
GPUs []string
GroupAdd []string
HealthCmd string
HealthInterval string

View File

@ -784,7 +784,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
s.ImageVolumes = imageVolumes
}
for _, dev := range c.Devices {
devices := c.Devices
for _, gpu := range c.GPUs {
devices = append(devices, "nvidia.com/gpu="+gpu)
}
for _, dev := range devices {
s.Devices = append(s.Devices, specs.LinuxDevice{Path: dev})
}

View File

@ -119,12 +119,6 @@ var _ = Describe("Podman run device", func() {
Expect(session).Should(ExitCleanly())
})
It("podman run --gpus noop", func() {
session := podmanTest.Podman([]string{"run", "--gpus", "all", ALPINE, "true"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
})
It("podman run cannot access non default devices", func() {
session := podmanTest.Podman([]string{"run", "-v /dev:/dev-host", ALPINE, "head", "-1", "/dev-host/kmsg"})
session.WaitWithDefaultTimeout()