Answers: <p>Tensorflow doesn't have access to libd3d12.so file:</p>
  <blockquote>
  <p>2022-08-18 12:29:39.540717: &gt;tensorflow/stream_executor/platform/default/dso_loader.cc:108] Could not load dynamic library 'libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so'; dlerror: libd3d12.so: cannot open shared object file: No such file or directory</p>
  </blockquote>
  <p>Here is an article solving this issue:
  <a href="https://nnt339es.hatenablog.com/entry/2022/07/31/045059" rel="nofollow noreferrer">enter link description here</a></p>
  <p>Shortly said, use this line instead:</p>
  <pre><code>docker run -it --rm --device /dev/dxg --mount type=bind,src=/usr/lib/wsl,dst=/usr/lib/wsl -e LD_LIBRARY_PATH=/usr/lib/wsl/lib python:3.9.10
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-10-02T13:34:08.530Z
Answers: 2022-10-02T13:34:41.967Z
Answers: 2022-10-02T13:34:41.967Z
Answers: Jedy
Body: <p>I'd like to do some machine learning on my AMD 6800 XT gpu within a python image based on <code>python:3.9.10</code>. I can confirm that <a href="https://superuser.com/questions/1737193/amd-radeon-rx-6800-xt-not-visible-within-debian-wsl2/1737384">the GPU is available outside of the image</a> (in a wsl2 instance). However, if I do <code>docker run -it python:3.9.10 /bin/bash</code> and then complete the same tutorial (<a href="https://docs.microsoft.com/en-us/windows/ai/directml/gpu-tensorflow-wsl#install-the-tensorflow-with-directml-package" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/ai/directml/gpu-tensorflow-wsl#install-the-tensorflow-with-directml-package</a>) it doesn't work:</p>
  <pre><code>(directml) root@8a8274e5337f:/# python
  Python 3.6.13 |Anaconda, Inc.| (default, Jun  4 2021, 14:25:59)
  [GCC 7.5.0] on linux
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import tensorflow.compat.v1 as tf
  &gt;&gt;&gt; tf.enable_eager_execution(tf.ConfigProto(log_device_placement=True))
  &gt;&gt;&gt; print(tf.add([1.0, 2.0], [3.0, 4.0]))
  2022-08-18 12:29:39.540717: W tensorflow/stream_executor/platform/default/dso_loader.cc:108] Could not load dynamic library 'libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so'; dlerror: libd3d12.so: cannot open shared object file: No such file or directory
  2022-08-18 12:29:39.540760: W tensorflow/core/common_runtime/dml/dml_device_cache.cc:137] Could not load DirectML.
  2022-08-18 12:29:39.540793: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:250] DirectML device enumeration: found 0 compatible adapters.
  2022-08-18 12:29:39.541010: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  2022-08-18 12:29:39.545145: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:CPU:0
  tf.Tensor([4. 6.], shape=(2,), dtype=float32)
  </code></pre>
  <p>This article has led me to think that perhaps docker doesn't support AMD GPUs at all: <a href="https://docs.docker.com/desktop/windows/wsl/" rel="nofollow noreferrer">https://docs.docker.com/desktop/windows/wsl/</a></p>
  <p>Can anyone suggest what I might be able to do to get this to work?</p>
  <p>Note that the reason I have picked this image is that my environment is based on a rather lengthy Dockerfile inheriting from <code>python:3.9.10</code>, and I'd like to keep using that image on the PC with the GPU as well as other (nvidia) environments, so I'm after a portable solution as far as the image is concerned, although I'd be grateful for any solution at this point.</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-08-18T13:49:53.260Z
Comments: Basically you are just passing it in with the `--device` flag but you need drivers and stuff. Check this project out https://github.com/RadeonOpenCompute/ROCm-docker the details section is really helpful.
Comments: Levi
Tags: <docker>
Title: How do I make my AMD GPU available within a docker image based on python:3.9.10
UserDisplayName: quant
ThreadText: # How do I make my AMD GPU available within a docker image based on python:3.9.10
  
  (Asked by: username_0 on 2022-08-18)
  
  I'd like to do some machine learning on my AMD 6800 XT gpu within a python image based on `python:3.9.10`. I can confirm that [the GPU is available outside of the image](https://superuser.com/questions/1737193/amd-radeon-rx-6800-xt-not-visible-within-debian-wsl2/1737384) (in a wsl2 instance). However, if I do `docker run -it python:3.9.10 /bin/bash` and then complete the same tutorial (<https://docs.microsoft.com/en-us/windows/ai/directml/gpu-tensorflow-wsl#install-the-tensorflow-with-directml-package>) it doesn't work:
  
  ```
  (directml) root@8a8274e5337f:/# python
  Python 3.6.13 |Anaconda, Inc.| (default, Jun  4 2021, 14:25:59)
  [GCC 7.5.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import tensorflow.compat.v1 as tf
  >>> tf.enable_eager_execution(tf.ConfigProto(log_device_placement=True))
  >>> print(tf.add([1.0, 2.0], [3.0, 4.0]))
  2022-08-18 12:29:39.540717: W tensorflow/stream_executor/platform/default/dso_loader.cc:108] Could not load dynamic library 'libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so'; dlerror: libd3d12.so: cannot open shared object file: No such file or directory
  2022-08-18 12:29:39.540760: W tensorflow/core/common_runtime/dml/dml_device_cache.cc:137] Could not load DirectML.
  2022-08-18 12:29:39.540793: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:250] DirectML device enumeration: found 0 compatible adapters.
  2022-08-18 12:29:39.541010: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  2022-08-18 12:29:39.545145: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:CPU:0
  tf.Tensor([4. 6.], shape=(2,), dtype=float32)
  
  ```
  
  This article has led me to think that perhaps docker doesn't support AMD GPUs at all: <https://docs.docker.com/desktop/windows/wsl/>
  
  Can anyone suggest what I might be able to do to get this to work?
  
  Note that the reason I have picked this image is that my environment is based on a rather lengthy Dockerfile inheriting from `python:3.9.10`, and I'd like to keep using that image on the PC with the GPU as well as other (nvidia) environments, so I'm after a portable solution as far as the image is concerned, although I'd be grateful for any solution at this point.
  
  **Tags:** docker
  
  > **Comments:**
  > **username_1**: Basically you are just passing it in with the `--device` flag but you need drivers and stuff. Check this project out https://github.com/RadeonOpenCompute/ROCm-docker the details section is really helpful.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-10-02. Score: 0
  
  Tensorflow doesn't have access to libd3d12.so file:
  
  > 2022-08-18 12:29:39.540717: >tensorflow/stream\_executor/platform/default/dso\_loader.cc:108] Could not load dynamic library 'libdirectml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.so'; dlerror: libd3d12.so: cannot open shared object file: No such file or directory
  
  Here is an article solving this issue:
  [enter link description here](https://nnt339es.hatenablog.com/entry/2022/07/31/045059)
  
  Shortly said, use this line instead:
  
  ```
  docker run -it --rm --device /dev/dxg --mount type=bind,src=/usr/lib/wsl,dst=/usr/lib/wsl -e LD_LIBRARY_PATH=/usr/lib/wsl/lib python:3.9.10
  
  ```
  
  
  ---
  
  