diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 65a47771f5..dd004a5a02 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -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, diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index 3ce6ada180..78fd275231 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -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-`, where `` 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") diff --git a/docs/source/markdown/options/gpus.md b/docs/source/markdown/options/gpus.md new file mode 100644 index 0000000000..4c279e3880 --- /dev/null +++ b/docs/source/markdown/options/gpus.md @@ -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. diff --git a/docs/source/markdown/podman-create.1.md.in b/docs/source/markdown/podman-create.1.md.in index 0c0b325b85..7c84072926 100644 --- a/docs/source/markdown/podman-create.1.md.in +++ b/docs/source/markdown/podman-create.1.md.in @@ -159,6 +159,8 @@ See [**Environment**](#environment) note below for precedence and examples. @@option gidmap.container +@@option gpus + @@option group-add @@option group-entry diff --git a/docs/source/markdown/podman-pod-clone.1.md.in b/docs/source/markdown/podman-pod-clone.1.md.in index 1ab91908ca..316e5e6194 100644 --- a/docs/source/markdown/podman-pod-clone.1.md.in +++ b/docs/source/markdown/podman-pod-clone.1.md.in @@ -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. diff --git a/docs/source/markdown/podman-pod-create.1.md.in b/docs/source/markdown/podman-pod-create.1.md.in index 46f52d3966..d47429fe85 100644 --- a/docs/source/markdown/podman-pod-create.1.md.in +++ b/docs/source/markdown/podman-pod-create.1.md.in @@ -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. diff --git a/docs/source/markdown/podman-run.1.md.in b/docs/source/markdown/podman-run.1.md.in index 54ad0dbf6a..4635e2cf9e 100644 --- a/docs/source/markdown/podman-run.1.md.in +++ b/docs/source/markdown/podman-run.1.md.in @@ -193,6 +193,8 @@ See [**Environment**](#environment) note below for precedence and examples. @@option gidmap.container +@@option gpus + @@option group-add @@option group-entry diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index d57dedee40..328d3ff94f 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -211,6 +211,7 @@ type ContainerCreateOptions struct { EnvFile []string Expose []string GIDMap []string + GPUs []string GroupAdd []string HealthCmd string HealthInterval string diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go index e9e90cae43..d166eef8e0 100644 --- a/pkg/specgenutil/specgen.go +++ b/pkg/specgenutil/specgen.go @@ -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}) } diff --git a/test/e2e/run_device_test.go b/test/e2e/run_device_test.go index f856a41a35..c8c0654875 100644 --- a/test/e2e/run_device_test.go +++ b/test/e2e/run_device_test.go @@ -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()