20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker で CUDA を使う.

Posted at

漢なら docker コンテナで CUDA を使いたいですね!
CUDA を使えるようにしましょう.

セットアップ

ホスト OS に CUDA とドライバ一式をいれておきます.
今回は

  • Centos6.5
  • CUDA 6.0(driver 331.67)
  • /usr/local/cuda に nvcc やら toolkit をインストール

にしました.

コンテナ内で CUDA プログラムを動かす.

privileded つきで, libcuda.so と /usr/local/cuda を container に expose(volume mount)します.

サンプルコードを /media にマウントします.

$ docker run --privileged -v /usr/lib64/libcuda.so:/usr/lib64/libcuda.so -v /usr/lib64/libcuda.so.1:/usr/lib64/libcuda.so.1 -v /usr/local/cuda:/usr/local/cuda -v /home/syoyo/NVIDIA_CUDA-6.0_Samples:/media -i -t syoyo/centos-gcc48 /bin/bash

Container 内で サンプルを実行してみます.

# cd /media/0_Simple/vectorAdd
# ./vectorAdd 
[Vector addition of 50000 elements]
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
Copy output data from the CUDA device to the host memory
Test PASSED

# cd /media/0_Simple/vectorAddDrv
# ./vectorAddDrv 
Vector Addition (Driver API)
> Using Device 0: "GeForce GTX 680" with Compute 3.0 capability
> findModulePath found file at <./vectorAdd_kernel64.ptx>
> initCUDA loading module: <./vectorAdd_kernel64.ptx>
> PTX JIT log:

Result = PASS

Cool!

HPC 仮想化みたいなことに一歩近づきましたね!

Todo

  • libcuda.so のマウントをより簡略化する.
  • CUDA リソース(GPU)をコンテナ間でうまく共有できるかな?
  • OpenGL との連携
20
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?