使用码头集装箱的GPU? [英] Using GPU from a docker container?

查看:267
本文介绍了使用码头集装箱的GPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从Docker容器中使用GPU的方法。

I'm searching for a way to use the GPU from inside a docker container.

容器将执行任意代码,所以我不想使用特权模式。

The container will execute arbitrary code so i don't want to use the privileged mode.

任何提示?

从以前的研究中,我了解到运行-v 和/或LXC cgroup 是要走的路,但是我不知道如何把它完全放在那里

From previous research i understood that run -v and/or LXC cgroup was the way to go but i'm not sure how to pull that off exactly

推荐答案

我没有使用--privileged模式来管理它。

Ok i finally managed to do it without using the --privileged mode.

我在ubuntu服务器14.04上运行,我正在使用最新的cuda(6.0.37的linux 13.04 64位)。

I'm running on ubuntu server 14.04 and i'm using the latest cuda (6.0.37 for linux 13.04 64 bits).

安装nvidia驱动程序cuda在你的主机上。 (这可能有点棘手,所以我建议您遵循本指南 https ://askubuntu.com/questions/451672/installing-and-testing-cuda-in-ubuntu-14-04

Install nvidia driver and cuda on your host. (it can be a little tricky so i will suggest you follow this guide https://askubuntu.com/questions/451672/installing-and-testing-cuda-in-ubuntu-14-04)

注意:保存您用于主机cuda安装的文件非常重要

ATTENTION : It's really important that you keep the files you used for the host cuda installation

我们需要使用lxc驱动程序运行docker守护程序,以便能够修改配置,并允许容器访问设备。

We need to run docker daemon using lxc driver to be able to modify the configuration and give the container access to the device.

一次性利用:

sudo service docker stop
sudo docker -d -e lxc

永久配置
修改位于/ etc / default / docker中的docker配置文件
通过添加'-e lxc'来更改行DOCKER_OPTS
这是修改后的行$ /

Permanent configuration Modify your docker configuration file located in /etc/default/docker Change the line DOCKER_OPTS by adding '-e lxc' Here is my line after modification

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 -e lxc"

然后使用

sudo service docker restart

如何检查守护程序是否有效地使用lxc驱动程序?

docker info

执行司机行应该如下所示:

The Execution Driver line should look like that :

Execution Driver: lxc-1.0.5






使用NVIDIA和CUDA驱动程序构建您的图像



这是一个基本的Docker文件来构建一个CUDA兼容映像。


Build your image with the NVIDIA and CUDA driver.

Here is a basic Dockerfile to build a CUDA compatible image.

FROM ubuntu:14.04
MAINTAINER Regan <http://stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container>

RUN apt-get update && apt-get install -y build-essential
RUN apt-get --purge remove -y nvidia*

ADD ./Downloads/nvidia_installers /tmp/nvidia                             > Get the install files you used to install CUDA and the NVIDIA drivers on your host
RUN /tmp/nvidia/NVIDIA-Linux-x86_64-331.62.run -s -N --no-kernel-module   > Install the driver.
RUN rm -rf /tmp/selfgz7                                                   > For some reason the driver installer left temp files when used during a docker build (i don't have any explanation why) and the CUDA installer will fail if there still there so we delete them.
RUN /tmp/nvidia/cuda-linux64-rel-6.0.37-18176142.run -noprompt            > CUDA driver installer.
RUN /tmp/nvidia/cuda-samples-linux-6.0.37-18176142.run -noprompt -cudaprefix=/usr/local/cuda-6.0   > CUDA samples comment if you don't want them.
RUN export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64         > Add CUDA library into your PATH
RUN touch /etc/ld.so.conf.d/cuda.conf                                     > Update the ld.so.conf.d directory
RUN rm -rf /temp/*  > Delete installer files.






运行您的图片



首先,您需要确定与您的设备相关联的主要号码。
最简单的方法是执行以下命令:


Run your image.

First you need to identify your the major number associated with your device. Easiest way is to do the following command :

ls -la /dev | grep nvidia

如果结果为空白,使用启动主机上的一个示例应该做的技巧。
结果应该像

当你可以看到组和日期之间有一组2个数字。
这两个数字称为主要和次要编号(按该顺序编写)并设计一个设备。
为方便起见,我们将使用主要号码。

If the result is blank, use launching one of the samples on the host should do the trick. The result should look like that As you can see there is a set of 2 numbers between the group and the date. These 2 numbers are called major and minor numbers (wrote in that order) and design a device. We will just use the major numbers for convenience.

为什么我们激活了lxc驱动程序?
要使用lxc conf选项,允许我们允许我们的容器访问这些设备。
选项是:(我建议使用*作为次要号码,因为它减少运行命令的长度)

Why do we activated lxc driver? To use the lxc conf option that allow us to permit our container to access those devices. The option is : (i recommend using * for the minor number cause it reduce the length of the run command)


- -lxc-conf ='lxc.cgroup.devices.allow = c [major number]:[minor number or *] rwm'

--lxc-conf='lxc.cgroup.devices.allow = c [major number]:[minor number or *] rwm'

所以如果我想启动一个容器(假设你的图像名称是cuda)。

So if i want to launch a container (Supposing your image name is cuda).

docker run -ti --lxc-conf='lxc.cgroup.devices.allow = c 195:* rwm' --lxc-conf='lxc.cgroup.devices.allow = c 243:* rwm' cuda

这篇关于使用码头集装箱的GPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆