想赶上机器学习ML深度学习的热潮不容易,光是显卡就是一笔不小的投入。网上搜索了一下,见A卡也可以勉强用于ML,遂想用手头有的一张A卡(RX470)进行学习,过程不易,记录之。
一、试用WSL2,失败。
到AMD ROCM官网查看,不支持windows平台,基本上推荐Ubuntu,心想正好在windows10上安装WSL2,最新版已经升到20.04,过程不赘述。安装好anaconda和ROCM后,rocminfo查看,报告找不到GPU,网上搜索后,确定wsl暂时(据微软说,解决方案正在研发中)不支持直接访问硬件,所以本方法失败。
二、物理机安装ubuntu20.04
按照教程安装rocm和anaconda 后, 安装tensorflow-rocm。安装很顺利,一切就绪,进入python,import tensorflow,报错!
(base) python@python-MS-7972:~$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: librocsolver.so.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/python/python-dev/anaconda3/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: librocsolver.so.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
又经过一番艰苦卓绝的搜索:),终于发现正确解决方案,竟然只是安装 rocm-libs!
suso apt install rocm-libs
但是由于rocm-libs的库文件都安装在/opt/rocm-4.3.0下面的多个子路径中,因此需要条件到LD路径中。
我这里采用的时在/etc/ld.so.conf.d下面创建一个新的独立配置文件 rocm_4.3.0_libs.conf
/opt/rocm-4.3.0/lib
/opt/rocm-4.3.0/rocsolver/lib
/opt/rocm-4.3.0/rocblas/lib
/opt/rocm-4.3.0/rocclr/lib
再次进入python导入tensorflow,终于Ok了!