Q: Can Nvidia GPU be used in Docker daemon inside another Docker daemon?
A: Untested according to nvidia-docker wiki.
- Ubuntu 14.04.1 LTS (Kernel: 3.13.0-170-generic)
- Docker CE 18.06.1-ce
- nvidia-docker2 2.0.3
- Nvidia driver 430.34
- i7-3930K CPU @ 3.20GHz
- GTX 680
docker run --runtime=nvidia --rm nvidia/cuda:10.1-base nvidia-smi
Looks good:
Fri Jul 12 09:30:46 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 430.34 Driver Version: 430.34 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 680 Off | 00000000:01:00.0 N/A | N/A |
| 30% 37C P0 N/A / N/A | 0MiB / 4035MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+
docker build -t docker:cuda .
docker save nvidia/cuda:10.1-base > cuda_10.1-base.tar
docker run -it --rm --runtime=nvidia --privileged -v $PWD:/workdir -w /workdir docker:cuda bash
docker load < cuda_10.1-base.tar
docker run --runtime=nvidia --rm nvidia/cuda:10.1-base nvidia-smi
GTX680 is pretty old and has compute capability of 3.0, which is not supported by current builds of Tensorflow. Following the instructions of official documentation, a wheel package is built with the image tensorflow/tensorflow:devel-gpu-py3
to include compute capability of 3.0.
docker run -it --runtime=nvidia --rm -v $PWD:/workdir -w /workdir tensorflow/tensorflow:1.14.0-gpu-py3 bash
pip install tensorflow-1.14.0-cp36-cp36m-linux_x86_64.whl
python matmul.py gpu 10000
# 1st: Time taken: 0:00:02.589672
# 2nd: Time taken: 0:00:02.506626
# 3rd: Time taken: 0:00:02.570411
# Average: 2.56s
python matmul.py cpu 10000
# 1st: Time taken: 0:00:12.053325
# 2nd: Time taken: 0:00:12.104460
# 3rd: Time taken: 0:00:12.023136
# Average: 12.06s
# CPU:GPU ~ 4.71
docker save tensorflow/tensorflow:1.14.0-gpu-py3 > tensorflow_1.14.0-gpu-py3.tar
docker run -it --rm --runtime=nvidia --privileged -v $PWD:/workdir -w /workdir docker:cuda bash
docker load < tensorflow_1.14.0-gpu-py3.tar
docker run -it --runtime=nvidia --rm -v $PWD:/workdir -w /workdir tensorflow/tensorflow:1.14.0-gpu-py3 bash
pip install tensorflow-1.14.0-cp36-cp36m-linux_x86_64.whl
python matmul.py gpu 10000
# 1st: Time taken: 0:00:02.594973
# 2nd: Time taken: 0:00:02.574000
# 3rd: Time taken: 0:00:02.540780
# Average: 2.57s
# 0.39% increase
python matmul.py cpu 10000
# 1st: Time taken: 0:00:12.861318
# 2nd: Time taken: 0:00:12.685900
# 3rd: Time taken: 0:00:12.373268
# Average: 12.64s
# 4.81% increase
# CPU:GPU ~ 4.92
# 4.46% increase
Native GPU is supported since Docker CE 19.03: https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)
However, Docker has drop support of Ubuntu 14.04 from version 18.09, i.e. you cannot install newer version using official approach.