<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Tensorflow | Cyrille Froehlich</title>
    <link>https://cyrille.hazeliris.com/tag/tensorflow/</link>
      <atom:link href="https://cyrille.hazeliris.com/tag/tensorflow/index.xml" rel="self" type="application/rss+xml" />
    <description>Tensorflow</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Wed, 18 Dec 2019 04:23:17 +0000</lastBuildDate>
    <image>
      <url>https://cyrille.hazeliris.com/media/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_2.png</url>
      <title>Tensorflow</title>
      <link>https://cyrille.hazeliris.com/tag/tensorflow/</link>
    </image>
    
    <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>
