Install Tensorflow with GPU support on Debian Sid

  1. I run Debian, which only provides CUDA 8.0, 9.1 and 9.2. However, Tensorflow requires CUDA 9.0 to operate.

1. Install the NVIDIA drivers and bumblebee

In this section, all the necessary packages should be available in the official debian repositories.

$ sudo apt install nvidia-driver bumblebee-nvidia primus libgl1-nvidia-glx
$ glxinfo | grep OpenGL
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.3.2
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 18.3.2
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 18.3.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
optirun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 940MX/PCIe/SSE2
OpenGL core profile version string: 4.6.0 NVIDIA 390.87
OpenGL core profile shading language version string: 4.60 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6.0 NVIDIA 390.87
OpenGL shading language version string: 4.60 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

2. Installing CUDA 9.0 and cuDNN

Installing CUDA 9.0 on Debian can get fairly ugly. NVIDIA provides two methods for installation: using a *.run, or adding a Ubuntu repository to APT. I do not like to mix Ubuntu and Debian repositories on my system. However, after miserably failing at installing CUDA 9.0 with the *.run, and time running short, I had to move to the second solution. In this section, I will show how to install CUDA 9.0 on Debian without messing up your system.

$ sudo dpkg -i cuda-repo-ubuntu1704_9.0.176-1_amd64.deb
$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1704/x86_64/7fa2af80.pub
$ sudo apt update
$ sudo apt install cuda-libraries-9-0
$ sudo apt install libcuda1
$ sudo dpkg -i libcudnn7_7.4.2.24-1+cuda9.0_amd64.deb

3. Install Tensorflow

Now that we installed CUDA, Tensorflow should be a piece of cake, right? Well, almost. It turns out that on top of requiring an older version of CUDA, Tensorflow only agrees to run with Python 3.5. Due to this issue, it is cleaner to run tensorflow in a virtual environment.

$ sudo apt install python3.5 virtualenv
$ virtualenv --system-site-packages -p python3.5 ./venv
$ source ./venv/bin/activate
$ pip install --upgrade pip
$ pip install --upgrade tensorflow-gpu
$ pip install --upgrade keras
$ optirun python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
2019-02-03 14:41:16.681594: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-02-03 14:41:16.761628: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:964] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-02-03 14:41:16.762209: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce 940MX major: 5 minor: 0 memoryClockRate(GHz): 1.189
pciBusID: 0000:02:00.0
totalMemory: 1.96GiB freeMemory: 1.92GiB
2019-02-03 14:41:16.762224: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2019-02-03 14:41:17.310796: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-02-03 14:41:17.310821: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2019-02-03 14:41:17.310826: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2019-02-03 14:41:17.310959: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1682 MB memory) -> physical GPU (device: 0, name: GeForce 940MX, pci bus id: 0000:02:00.0, compute capability: 5.0)
tf.Tensor(-1959.8584, shape=(), dtype=float32)

References

[1] Debian Wiki. Bumblebee. https://wiki.debian.org/Bumblebee. Accessed 2019–02–03.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store