Skip to content

Commit

Permalink
docs: how to enable nvidia gpu 2.0 in Pouch
Browse files Browse the repository at this point in the history
Signed-off-by: codejuan <xh@decbug.com>
  • Loading branch information
CodeJuan committed Nov 9, 2018
1 parent a52c6f3 commit 727f079
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
18 changes: 13 additions & 5 deletions daemon/mgr/spec_nvidia_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package mgr

import (
"os/exec"
"path"

"github.com/alibaba/pouch/pkg/utils"

"github.com/opencontainers/runtime-spec/specs-go"
)

var (
// nvidiaHookName is a custom OCI prestart hook binary to runc in order to enable GPU containers.
nvidiaHookName = "nvidia-container-runtime-hook"
)

Expand All @@ -25,13 +27,19 @@ func setNvidiaHook(c *Container, spec *SpecWrapper) error {
return nil
}

path, err := exec.LookPath(nvidiaHookName)
if err != nil {
return err
hookPath := ""
if !path.IsAbs(nvidiaHookName) {
var err error
hookPath, err = exec.LookPath(nvidiaHookName)
if err != nil {
return err
}
} else {
hookPath = nvidiaHookName
}
args := []string{path}
args := []string{hookPath}
nvidiaPrestart := specs.Hook{
Path: path,
Path: hookPath,
Args: append(args, "prestart"),
}
spec.s.Hooks.Prestart = append(spec.s.Hooks.Prestart, nvidiaPrestart)
Expand Down
44 changes: 38 additions & 6 deletions daemon/mgr/spec_nvidia_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ import (

func Test_setNvidiaHook(t *testing.T) {
nvidiaHookName = "test-nvidia-container-runtime-hook"
installDir := "/usr/local/bin/"
installDir := "/usr/local/bin"
fullname := path.Join(installDir, nvidiaHookName)
nvidiaHookName = fullname
os.Remove(fullname)
os.Create(fullname)
os.Chmod(fullname, 0755)
path, _ := exec.LookPath(nvidiaHookName)
hookPath := ""
if !path.IsAbs(nvidiaHookName) {
hookPath, _ = exec.LookPath(nvidiaHookName)
} else {
hookPath = nvidiaHookName
}
defer func() {
os.Remove(fullname)
}()
Expand Down Expand Up @@ -69,10 +75,36 @@ func Test_setNvidiaHook(t *testing.T) {
},
},
},
// exec.LookPath("nvidia-container-runtime-hook") return error,
[]specs.Hook{specs.Hook{
Path: path,
Args: append([]string{path}, "prestart"),
[]specs.Hook{{
Path: hookPath,
Args: append([]string{hookPath}, "prestart"),
}},
},
{
"NvidiaConfig not nil, NvidiaEnv is null",
&Container{
HostConfig: &types.HostConfig{
Resources: types.Resources{
NvidiaConfig: &types.NvidiaConfig{
NvidiaDriverCapabilities: "all",
NvidiaVisibleDevices: "all",
},
},
},
Config: &types.ContainerConfig{
Env: []string{},
},
},
&SpecWrapper{
s: &specs.Spec{
Hooks: &specs.Hooks{
Prestart: []specs.Hook{},
},
},
},
[]specs.Hook{{
Path: hookPath,
Args: append([]string{hookPath}, "prestart"),
}},
},
}
Expand Down
38 changes: 38 additions & 0 deletions docs/features/pouch_with_gpu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# PouchContainer with GPU

NVIDIA uses containers to develop, test, benchmark, and deploy deep learning (DL) frameworks and HPC applications. A variety of customers used NVIDIA-Container-Runtime to containerize and run GPU accelerated workloads. The NVIDIA-Container-Runtime is the next-generation GPU-aware container runtime. It is compatible with the Open Containers Initiative (OCI) specification used by Pouch and other popular container technologies.

## nvidia gpu runtime

![pouch_with_pouch](../static_files/pouch_with_gpu.png)

The figure shows how the NVIDIA-Container-Runtime integrates into Pouch. We set a custom OCI prestart hook called nvidia-container-runtime-hook to runc in order to enable GPU containers.

## Prerequisites Installation

Make sure you have installed the NVIDIA driver

1. GNU/Linux x86_64 with kernel version > 3.10
2. NVIDIA GPU with Architecture > Fermi (2.1)
3. NVIDIA drivers ~= 361.93 (untested on older versions)

## Start GPU container

Pouch support 2 method to start GPU container

1. Via nvidia config API, [nvidiaconfig](https://github.com/alibaba/pouch/blob/master/docs/api/HTTP_API.md#nvidiaconfig)
2. Via Environment variables, [nvidia-container-runtime-env](https://github.com/NVIDIA/nvidia-container-runtime#environment-variables-oci-spec)

### Via API

```shell
pouch run -it --nvidia-capabilities=all --nvidia-visible-devs=all centos:7 bash
```

### Via Environment variables

The NVIDIA Container Runtime uses environment variables in container images to specify a GPU accelerated container.

```shell
pouch run -it -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all centos:7 bash
```
Binary file added docs/static_files/pouch_with_gpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 727f079

Please sign in to comment.