Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Created August 6, 2018 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzamecnik/c3547050825632808f5e13b692e07971 to your computer and use it in GitHub Desktop.
Save bzamecnik/c3547050825632808f5e13b692e07971 to your computer and use it in GitHub Desktop.
NVIDIA in docker-compose
# based on https://github.com/NVIDIA/nvidia-docker/wiki/Frequently-Asked-Questions#do-you-support-docker-compose
# it indeed works :)
# minimum syntax version to support the "runtime" keyword
version: "2.3"
services:
# show the system information about GPUs
smi:
image: "nvidia/cuda:9.1-base"
command: ["nvidia-smi"]
runtime: nvidia
# run tensorflow session and allocate a device
tf:
image: "tensorflow/tensorflow:1.8.0-gpu"
command: ["python", "-c", "import tensorflow as tf; hello = tf.constant('Hello, TensorFlow!'); sess = tf.Session(); print(sess.run(hello))"]
runtime: nvidia # <-- the magic :)
environment:
# allow specifying a subset of GPUs to be used
- CUDA_VISIBLE_DEVICES
smi_1 | Mon Aug 6 15:00:47 2018
smi_1 | +-----------------------------------------------------------------------------+
smi_1 | | NVIDIA-SMI 390.30 Driver Version: 390.30 |
smi_1 | |-------------------------------+----------------------+----------------------+
smi_1 | | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
smi_1 | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
smi_1 | |===============================+======================+======================|
smi_1 | | 0 GeForce GTX 1070 On | 00000000:01:00.0 Off | N/A |
smi_1 | | 29% 55C P0 37W / 140W | 8MiB / 8119MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 1 GeForce GTX 108... On | 00000000:02:00.0 Off | N/A |
smi_1 | | 47% 80C P2 187W / 240W | 10761MiB / 11178MiB | 100% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 2 GeForce GTX 108... On | 00000000:03:00.0 Off | N/A |
smi_1 | | 38% 66C P0 68W / 240W | 8MiB / 11178MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 3 GeForce GTX 1070 On | 00000000:07:00.0 Off | N/A |
smi_1 | | 28% 52C P2 34W / 140W | 7723MiB / 8119MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 4 GeForce GTX 1070 On | 00000000:82:00.0 Off | N/A |
smi_1 | | 28% 54C P0 37W / 140W | 8MiB / 8119MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 5 GeForce GTX 108... On | 00000000:83:00.0 Off | N/A |
smi_1 | | 34% 59C P0 66W / 240W | 8MiB / 11178MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 | | 6 GeForce GTX 108... On | 00000000:84:00.0 Off | N/A |
smi_1 | | 36% 61C P0 64W / 240W | 8MiB / 11178MiB | 0% Default |
smi_1 | +-------------------------------+----------------------+----------------------+
smi_1 |
smi_1 | +-----------------------------------------------------------------------------+
smi_1 | | Processes: GPU Memory |
smi_1 | | GPU PID Type Process name Usage |
smi_1 | |=============================================================================|
smi_1 | +-----------------------------------------------------------------------------+
nv_smi_1 exited with code 0
tf_1 | /usr/local/lib/python2.7/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
tf_1 | from ._conv import register_converters as _register_converters
tf_1 | 2018-08-06 15:00:48.314116: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
tf_1 | 2018-08-06 15:00:48.735887: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
tf_1 | name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.582
tf_1 | pciBusID: 0000:03:00.0
tf_1 | totalMemory: 10.92GiB freeMemory: 10.75GiB
tf_1 | 2018-08-06 15:00:49.091156: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 1 with properties:
tf_1 | name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.683
tf_1 | pciBusID: 0000:82:00.0
tf_1 | totalMemory: 7.93GiB freeMemory: 7.83GiB
tf_1 | 2018-08-06 15:00:49.091233: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0, 1
tf_1 | 2018-08-06 15:00:49.710009: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
tf_1 | 2018-08-06 15:00:49.710087: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 1
tf_1 | 2018-08-06 15:00:49.710100: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N N
tf_1 | 2018-08-06 15:00:49.710108: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 1: N N
tf_1 | 2018-08-06 15:00:49.710603: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10405 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:03:00.0, compute capability: 6.1)
tf_1 | 2018-08-06 15:00:49.908516: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 7560 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1070, pci bus id: 0000:82:00.0, compute capability: 6.1)
tf_1 | Hello, TensorFlow!
nv_tf_1 exited with code 0
# run on all GPUs
docker-compose -f docker-compose.yml up
# run on GPU 2
CUDA_VISIBLE_DEVICES=2 docker-compose -f docker-compose.yml up
# run on GPU 2 and 4
CUDA_VISIBLE_DEVICES=2,4 docker-compose -f docker-compose.yml up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment