Tensorflow with GPU Install using Docker
Installing Tensorflow with GPU Support using Docker
- Cuda installation.
- Install nvidia-docker.
- Check if a GPU is available.
lspci | grep -i nvidia
- Verify your
nvidia-docker
installation.docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
Sun Mar 3 13:20:01 2019 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 418.39 Driver Version: 418.39 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 940MX On | 00000000:01:00.0 Off | N/A | | N/A 49C P8 N/A / N/A | 380MiB / 4046MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| +-----------------------------------------------------------------------------+
Note:
nvidia-docker
v1 uses thenvidia-docker
alias, where v2 usesdocker --runtime=nvidia
.
Build from source
The following example downloads the TensorFlow :nightly-devel-gpu-py3
image and uses nvidia-docker
to run the GPU-enabled container. This development image is configured to build a Python 3 pip package with GPU support:
docker pull tensorflow/tensorflow:nightly-devel-gpu-py3
docker run --runtime=nvidia -it -w /tensorflow -v $PWD:/mnt -e HOST_PERMS="$(id -u):$(id -g)" \
tensorflow/tensorflow:nightly-devel-gpu-py3 bash
Then, within the container’s virtual environment, build the TensorFlow package with GPU support:
./configure # answer prompts or use defaults
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt # create package
chown $HOST_PERMS /mnt/tensorflow-version-tags.whl
Install and verify the package within the container and check for a GPU:
pip uninstall tensorflow # remove current version
pip install /mnt/tensorflow-version-tags.whl
cd /tmp # don't import from source directory
python -c "import tensorflow as tf; print(tf.contrib.eager.num_gpus())"
Common Issues
- CUDA 9.0 unsupported gcc versions later than 6 #731 Closed
sudo apt-get install gcc-6 g++-6 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 10 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 10