mirror of https://github.com/containers/podman.git
Merge pull request #21180 from rhatdan/nvidia
Make --gpus work with nvidia gpus
This commit is contained in:
commit
c41c30bedd
|
@ -700,6 +700,10 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(gidmapFlagName, completion.AutocompleteNone)
|
_ = 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"
|
uidmapFlagName := "uidmap"
|
||||||
createFlags.StringSliceVar(
|
createFlags.StringSliceVar(
|
||||||
&cf.UIDMap,
|
&cf.UIDMap,
|
||||||
|
|
|
@ -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 `_`")
|
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)
|
_ = 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"
|
passwdFlagName := "passwd"
|
||||||
flags.BoolVar(&runOpts.Passwd, passwdFlagName, true, "add entries to /etc/passwd and /etc/group")
|
flags.BoolVar(&runOpts.Passwd, passwdFlagName, true, "add entries to /etc/passwd and /etc/group")
|
||||||
|
|
||||||
|
|
|
@ -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.
|
|
@ -159,6 +159,8 @@ See [**Environment**](#environment) note below for precedence and examples.
|
||||||
|
|
||||||
@@option gidmap.container
|
@@option gidmap.container
|
||||||
|
|
||||||
|
@@option gpus
|
||||||
|
|
||||||
@@option group-add
|
@@option group-add
|
||||||
|
|
||||||
@@option group-entry
|
@@option group-entry
|
||||||
|
|
|
@ -41,6 +41,8 @@ Note: the pod implements devices by storing the initial configuration passed by
|
||||||
|
|
||||||
@@option gidmap.pod
|
@@option gidmap.pod
|
||||||
|
|
||||||
|
@@option gpus
|
||||||
|
|
||||||
#### **--help**, **-h**
|
#### **--help**, **-h**
|
||||||
|
|
||||||
Print usage statement.
|
Print usage statement.
|
||||||
|
|
|
@ -80,6 +80,8 @@ Set the exit policy of the pod when the last container exits. Supported policie
|
||||||
|
|
||||||
@@option gidmap.pod
|
@@option gidmap.pod
|
||||||
|
|
||||||
|
@@option gpus
|
||||||
|
|
||||||
#### **--help**, **-h**
|
#### **--help**, **-h**
|
||||||
|
|
||||||
Print usage statement.
|
Print usage statement.
|
||||||
|
|
|
@ -193,6 +193,8 @@ See [**Environment**](#environment) note below for precedence and examples.
|
||||||
|
|
||||||
@@option gidmap.container
|
@@option gidmap.container
|
||||||
|
|
||||||
|
@@option gpus
|
||||||
|
|
||||||
@@option group-add
|
@@option group-add
|
||||||
|
|
||||||
@@option group-entry
|
@@option group-entry
|
||||||
|
|
|
@ -167,6 +167,7 @@ type ContainerCreateOptions struct {
|
||||||
EnvFile []string
|
EnvFile []string
|
||||||
Expose []string
|
Expose []string
|
||||||
GIDMap []string
|
GIDMap []string
|
||||||
|
GPUs []string
|
||||||
GroupAdd []string
|
GroupAdd []string
|
||||||
HealthCmd string
|
HealthCmd string
|
||||||
HealthInterval string
|
HealthInterval string
|
||||||
|
|
|
@ -784,7 +784,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
|
||||||
s.ImageVolumes = imageVolumes
|
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})
|
s.Devices = append(s.Devices, specs.LinuxDevice{Path: dev})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,12 +119,6 @@ var _ = Describe("Podman run device", func() {
|
||||||
Expect(session).Should(ExitCleanly())
|
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() {
|
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 := podmanTest.Podman([]string{"run", "-v /dev:/dev-host", ALPINE, "head", "-1", "/dev-host/kmsg"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
|
Loading…
Reference in New Issue