Add nvidia gpu support via libnvidia-container
This adds nvidia gpu support via the libnvidia-container project and `nvidia-container-cli`. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -31,7 +31,7 @@ import (
|
||||
|
||||
var ociHook = cli.Command{
|
||||
Name: "oci-hook",
|
||||
Usage: "provides a base for OCI runtime hooks that allow arguements to be templated.",
|
||||
Usage: "provides a base for OCI runtime hooks to allow arguments to be injected.",
|
||||
Action: func(context *cli.Context) error {
|
||||
state, err := loadHookState(os.Stdin)
|
||||
if err != nil {
|
||||
@@ -70,6 +70,7 @@ func newTemplateContext(state *specs.State) *templateContext {
|
||||
"rootfs": t.rootfs,
|
||||
"pid": t.pid,
|
||||
"annotation": t.annotation,
|
||||
"status": t.status,
|
||||
}
|
||||
return t
|
||||
}
|
||||
@@ -99,6 +100,10 @@ func (t *templateContext) annotation(k string) string {
|
||||
return t.state.Annotations[k]
|
||||
}
|
||||
|
||||
func (t *templateContext) status() string {
|
||||
return t.state.Status
|
||||
}
|
||||
|
||||
func render(ctx *templateContext, source string, out io.Writer) error {
|
||||
t, err := template.New("oci-hook").Funcs(ctx.funcs).Parse(source)
|
||||
if err != nil {
|
||||
|
||||
@@ -93,6 +93,10 @@ var ContainerFlags = []cli.Flag{
|
||||
Name: "pid-file",
|
||||
Usage: "file path to write the task's pid",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "gpus",
|
||||
Usage: "add gpus to the container",
|
||||
},
|
||||
}
|
||||
|
||||
func loadSpec(path string, s *specs.Spec) error {
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/contrib/nvidia"
|
||||
"github.com/containerd/containerd/oci"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
@@ -123,6 +124,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
Path: parts[1],
|
||||
}))
|
||||
}
|
||||
if context.IsSet("gpus") {
|
||||
opts = append(opts, nvidia.WithGPUs(nvidia.WithDevices(context.Int("gpus")), nvidia.WithAllCapabilities))
|
||||
}
|
||||
if context.IsSet("config") {
|
||||
var s specs.Spec
|
||||
if err := loadSpec(context.String("config"), &s); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user