<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Nvidia | Cyrille Froehlich</title>
    <link>https://cyrille.hazeliris.com/tag/nvidia/</link>
      <atom:link href="https://cyrille.hazeliris.com/tag/nvidia/index.xml" rel="self" type="application/rss+xml" />
    <description>Nvidia</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Fri, 01 Jan 2021 03:52:55 +0000</lastBuildDate>
    <image>
      <url>https://cyrille.hazeliris.com/media/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_2.png</url>
      <title>Nvidia</title>
      <link>https://cyrille.hazeliris.com/tag/nvidia/</link>
    </image>
    
    <item>
      <title>GPU Support With Docker Compose</title>
      <link>https://cyrille.hazeliris.com/post/2021/01/01/gpu-support-with-docker-compose/</link>
      <pubDate>Fri, 01 Jan 2021 03:52:55 +0000</pubDate>
      <guid>https://cyrille.hazeliris.com/post/2021/01/01/gpu-support-with-docker-compose/</guid>
      <description>&lt;p&gt;I use Docker quite a lot as it allows me to install, test, remove libraries or components without
any risk to break my main system. VM is another option but even if a linux install is now just
a few clicks in &lt;em&gt;virt-manager&lt;/em&gt; GUI, it takes time and I don&amp;rsquo;t need the full isolation provided
for this use-case. One thing that is quite difficult to setup in docker is the host GPU sharing.
Same issue with the VM, unless having 2 cards installed in the host, giving access to the guest
system either have an heavy performance impact, either require unlinking the card from the host
to bind it to the guest system (and the host is now headless in the meantime, so hope the switch
works without fail or you&amp;rsquo;ll be blind-fixing the issue in front of a dark screen).&lt;/p&gt;
&lt;p&gt;It is usually not a problem as most of the containers are running services, and my emacs can
easily be displayed on the host Xserver even when running inside a container. A Jupyter notebook
with Tensorflow and GPU support or an instance of Leela to review a Go game is another story&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;nvidia-docker&lt;/em&gt;, &lt;em&gt;nvidia-docker2&lt;/em&gt; or &lt;em&gt;nvidia-container&lt;/em&gt; provided somewhat working solutions but
replacing the default docker runtime broke some of my other containers, some were ok with nvidia-docker
while others only with nvidia-container, and docker-compose was not usable with them at all. Of course,
switching between the different approach required to uninstall/install the correct set of packages
with matching versions. I had to rely to wrapper scripts to run the correct docker commands, which
is basically the job of docker-compose&amp;hellip; Somewhat working, but quite a messy solution.&lt;/p&gt;
&lt;p&gt;GPU support was discussed for a long time and it seems we&amp;rsquo;re near fixing all of this
&lt;em&gt;docker-compose&lt;/em&gt; 1.28.0-rc1 is announcing &amp;ldquo;Support for Nvidia GPUs via device requests&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I&amp;rsquo;ll update this with a more detailled setup when 1.28 is released, as things may change.
The first part is the setup described &lt;a href=&#34;https://cyrille.hazeliris.com/post/2019/12/18/tensorflow-gpu-on-debian-buster/&#34;&gt;here&lt;/a&gt;,
moved to a container. The rest is a few lines to add to the compose yaml&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;My docker daemon config only move docker files out of /var and define a local registry:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; cat /etc/docker/daemon.json
{
  &amp;quot;data-root&amp;quot;: &amp;quot;/home/docker&amp;quot;,
  &amp;quot;registry-mirrors&amp;quot;: [ &amp;quot;https://192.168.1.178:5000&amp;quot; ]
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On the host the buster-backports nvidia-driver and nvidia-container-runtime are installed.
In the Dockerfile, install &lt;em&gt;nvidia-cuda-dev&lt;/em&gt; from buster-backports (thus we match the host driver version).&lt;/p&gt;
&lt;p&gt;Tensorflow require cuDNN, so install the matching &lt;em&gt;libcudnn8&lt;/em&gt; too. I have a copy of this in a local
debian repository: adding a source.list file to the image then apt-get install is faster than pushing
it from the docker context (these libraries are huge).&lt;/p&gt;
&lt;p&gt;In the docker-compose yaml, add:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;jupyter:
  ...
  deploy:
    resources:
      reservations:
        devices:
        - &#39;driver&#39;: &#39;nvidia&#39;
          &#39;count&#39;: 1
          &#39;capabilities&#39;: [&#39;gpu&#39;, &#39;utility&#39;]
  devices:
    - /dev/nvidia-uvm:/dev/nvidia-uvm
    - /dev/nvidia-uvm-tools:/dev/nvidia-uvm-tools
  ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The deploy parameters will act as the &amp;ndash;gpus option. The &lt;em&gt;nvidia-uvm&lt;/em&gt; module is not always loaded, running
modprobe beforehand (or force loading the module at boottime) may be required. Cuda will fail to initialize
if these &lt;a href=&#34;https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#runfile-verifications&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;devices are not present&lt;/a&gt;.
Once the devices are available on the host, &lt;em&gt;nvidia-container&lt;/em&gt; doesn&amp;rsquo;t map them into the container, so we
manually add them in the compose yaml.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Tensorflow with GPU acceleration on Debian Buster</title>
      <link>https://cyrille.hazeliris.com/post/2019/12/18/tensorflow-gpu-on-debian-buster/</link>
      <pubDate>Wed, 18 Dec 2019 04:23:17 +0000</pubDate>
      <guid>https://cyrille.hazeliris.com/post/2019/12/18/tensorflow-gpu-on-debian-buster/</guid>
      <description>&lt;p&gt;A bit early for christmas presents, but I got myself a new machine (AMD Ryzen 3900X / 32G / RTX2060 Super,
by the way Ryzen CPUs are real monsters). Now, let&amp;rsquo;s try to make use of this.&lt;/p&gt;
&lt;h1 id=&#34;nvidia-drivers-and-tools&#34;&gt;Nvidia drivers and tools&lt;/h1&gt;
&lt;p&gt;Assuming the Debian backports are configured, we can choose to use a more up to date driver version.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; cat /etc/apt/sources.list.d/backports.list
deb http://deb.debian.org/debian buster-backports main contrib non-free
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install the &lt;em&gt;nvidia-driver&lt;/em&gt; (currently 450.80) and the &lt;em&gt;nvidia-cuda-toolkit&lt;/em&gt; (currently 11.1)&lt;/p&gt;
&lt;h1 id=&#34;cudnn-packages&#34;&gt;cuDNN packages&lt;/h1&gt;
&lt;p&gt;Tensorflow require the cuDNN components but they are not available in the usual repository so we have to
download the packages from &lt;a href=&#34;https://developer.nvidia.com/cudnn-download-survey&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Nvidia&lt;/a&gt;. cuDNN is not available
for the Debian distribution but Ubuntu ones are compatible enough. The packages we need are :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;libcudnn8_8.0.5.39-1+cuda11.1_amd64.deb&lt;/li&gt;
&lt;li&gt;libcudnn8-dev_8.0.5.39-1+cuda11.1_amd64.deb&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We&amp;rsquo;ll install them manually with a &lt;em&gt;dpkg -i&lt;/em&gt; as configuring the Nvidia repository will probably fetch
conflicting packages too.&lt;/p&gt;
&lt;h1 id=&#34;jupyter-notebook&#34;&gt;Jupyter notebook&lt;/h1&gt;
&lt;p&gt;Most of the documentation on the internet related to machine learning is using the python API,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; python3 -mvenv jupyter-env
&amp;gt; cd jupyter-env
&amp;gt; . ./bin/activate
&amp;gt; pip install -U pip setuptools wheel
&amp;gt; pip install jupyterlab tensorflow-gpu
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then check if the GPU is available to Tensorflow :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; python3
&amp;gt;&amp;gt;&amp;gt; import tensorflow as tf
2020-12-26 11:19:12.763644: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
&amp;gt;&amp;gt;&amp;gt; tf.config.list_physical_devices()
2020-12-26 11:19:50.377149: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2020-12-26 11:19:50.382895: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2020-12-26 11:19:50.471910: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-12-26 11:19:50.472295: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:0a:00.0 name: GeForce RTX 2060 SUPER computeCapability: 7.5
coreClock: 1.695GHz coreCount: 34 deviceMemorySize: 7.79GiB deviceMemoryBandwidth: 417.29GiB/s
2020-12-26 11:19:50.472310: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2020-12-26 11:19:50.485168: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2020-12-26 11:19:50.485199: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2020-12-26 11:19:50.491058: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2020-12-26 11:19:50.494631: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2020-12-26 11:19:50.494706: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library &#39;libcusolver.so.10&#39;; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory
2020-12-26 11:19:50.498531: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2020-12-26 11:19:50.498616: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2020-12-26 11:19:50.498625: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1757] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
[PhysicalDevice(name=&#39;/physical_device:CPU:0&#39;, device_type=&#39;CPU&#39;)]
&amp;gt;&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And, we failed ! cuDNN was loaded, GPU is detected but Tensorflow wants an older version of libcusolver:
nvidia-cuda-toolkit installed the version 11 but we need the version 10 (no idea why as other libraries use cuda11,
which is the &lt;a href=&#34;https://www.tensorflow.org/install/source#gpu_support_2&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;correct version for tensorflow 2.4&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;del&gt;Not a big issue as a &lt;em&gt;libcusolver10&lt;/em&gt; package is available in the backports. Let&amp;rsquo;s install that then give it another try:&lt;/del&gt;&lt;/p&gt;
&lt;p&gt;Update: Now, libcusolver11 is no longer available in the buster-backports and tensorflow-gpu keep requesting the v10, it will
probably be fixed in next tensorflow or nvidia drivers release but in the meantime, it seems the &lt;a href=&#34;https://github.com/tensorflow/tensorflow/issues/43947&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;workaround&lt;/a&gt;
is to use the cuda11 library through a symlink:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cd /usr/lib/x86_64-linux-gnu
ln -sf libcusolver.so.11 libcusolver.so.10
ldconfig


...
2020-12-26 11:21:28.182053: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
[PhysicalDevice(name=&#39;/physical_device:CPU:0&#39;, device_type=&#39;CPU&#39;), PhysicalDevice(name=&#39;/physical_device:GPU:0&#39;, device_type=&#39;GPU&#39;)]
&amp;gt;&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now launch a notebook with &lt;em&gt;jupyter lab&lt;/em&gt;, and run some tutorial code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...
2020-12-26 11:27:51.811618: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6736 MB memory) -&amp;gt; physical GPU (device: 0, name: GeForce RTX 2060 SUPER, pci bus id: 0000:0a:00.0, compute capability: 7.5)
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yep, seems good now.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
