docker中使用gpu需要安装相关的插件环境。

系统环境:

操作系统:Ubuntu 16.04 64位 

gpu: nvidia p100

需要的软件:

cuda driver

nvidia-docker

安装步骤:

cuda driver

cuda driver包括了cuda工具包和nvidia driver

 

安装方式

1.Package安装 
2.Runfile安装

https://developer.nvidia.com/cuda-downloads下载安装,安装方式参看官网

 

cuda driver验证:

cat /proc/driver/nvidia/version

安装成功显示:

NVRM version: NVIDIA UNIX x86_64 Kernel Module  410.66  Wed Oct 10 12:01:53 CDT 2018
GCC version:  gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 

 

nvidia-docker

nvidia-docker是一个可以使用gpu的docker,是在docker上做了一层封装,实现了container和host之间cuda连接

 

安装方式

# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker

# Add the package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update

# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

参考:https://github.com/NVIDIA/nvidia-docker

 

验证:

# Test nvidia-smi with the latest official CUDA image
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi

 

runtime也可以配置默认

 cat /etc/docker/daemon.json

{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}

docker container运行:

项目中通过ffmpeg调用gpu的编解码功能。需要基于包含有nvidia cuda的Ubuntu系统镜像(nvidai/cuda  tensorflow/tensorflow)加入编解码程序编译镜像,然后运行container

 

运行tensorflow模型

docker run --runtime=nvidia --rm --name tensorflow -ti tensorflow/tensorflow:r0.9-devel-gpu

 

Kubernetes nvidia gpu使用

部署docker容器gpu环境的基础上,Kubernetes 集群中使用gpu需要插件 NVIDIA/k8s-device-plugin插件实现gpu数量统计,状态监测以及负载均衡等参考https://github.com/NVIDIA/k8s-device-plugin

 

参考文章:

https://blog.csdn.net/a632189007/article/details/78801166/

https://segmentfault.com/a/1190000016805400?utm_source=tag-newest

https://blog.csdn.net/yunqiinsight/article/details/88389913

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐