当前位置: 首页 > 知识库问答 >
问题:

修复Tensorflow GPU不加载动态库的问题

章心水
2023-03-14

我想用我的GPU做Tensorflow。

我试过了,在只使用CPU的安装中无法加载动态库cudart64_101.dll。

不幸的是,我不断得到一个错误<代码>无法加载动态库' cudart 64 _ 110 . dll ';dlerror:找不到cudart 64 _ 110 . dll 。我该如何解决这个问题?Python版本:3.8.3,CUDA 10.1

2020-11-03 12:30:28.832014: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2020-11-03 12:30:28.832688: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2020-11-03 12:30:28.833342: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2020-11-03 12:30:28.833994: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2020-11-03 12:30:28.834645: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-11-03 12:30:28.835297: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-11-03 12:30:28.835948: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2020-11-03 12:30:28.836594: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2020-11-03 12:30:28.836789: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1761] 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...
2020-11-03 12:30:28.837575: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-11-03 12:30:28.838495: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1265] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-03 12:30:28.838708: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1271]      
2020-11-03 12:30:28.838831: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set

共有3个答案

欧阳嘉年
2023-03-14

安装Cuda时没有安装.dll文件。但我已经安装了pytorch,并且该包包含dll文件。所以我将其添加到路径变量中,下次运行tensorflow时,它可以找到dll(从我最近添加的路径中),并且它可以工作。

pytorch库中的dll路径

C:\用户\YOUR_USER_NAME\应用数据\漫游\Python\Python 38\site-包\torch\lib

确认

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
Num GPUs Available:  1

以前是0

卞轶
2023-03-14

好吧,您可以看到Tensorflow安装正在寻找版本11,10的Cuda库,而您有10.1。因此,为了解决此问题,请安装正确的Cuda版本。为什么它正在寻找3个不同的版本,我不知道。但是你可以在这里找到库达、张量流和库德NN的有效组合。

编辑:从Cuda版本中去掉了8,Tensorflow其实是在找CUDNN版本8。所以不要忘了安装CUDNN(我猜你安装的是Tensorflow的最新版本-

靳睿
2023-03-14

我建议您使用conda(Ananconda/Minicon da)创建一个单独的环境并安装tenorflow-gpucudnncudatoolkit。Minicon da的占用空间比Anaconda小得多。如果您还没有conda,我建议您安装Minicon da。

# Quick and dirty: with channel specification
conda create -n tf_gpu_env python=3.8 
conda activate tf_gpu_env
conda install tensorflow-gpu -c anaconda
conda install cudnn -c conda-forge 
conda install cudatoolkit -c anaconda

有关更多详细信息,请参阅:https://www.tensorflow.org/guide/gpu

# Sanity check for validating 
# visibility of the GPUs to TF
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

尽管您可以如前所示快速创建conda(Ananconda/Miniconda)环境,但更可取的做法是使安装过程尽可能可复制:进入环境。yml文件。

将环境文件保存在存储库(或项目)的根目录下,然后运行以下命令,使用环境文件将所有包安装在隔离的 conda 环境(此处我将其命名为tfgpu_env)中。环境文件的顶部包含一些有用的命令。

conda env create -f environment.yml

将以下内容另存为environment.yml在您的存储库下。并考虑将固定以下三个库:

例如:

  • 张量流-gpu=2.4
  • cud nn=8
  • cuda工具包=11
## filename: environment.yml

## Environment File Definition

name: tfgpu_env # tensorflow-gpu environment
channels:
  - conda-forge
  - anaconda
  - default
dependencies:
  - python=3.8
  ## Core Necessities
  - numpy # -c conda-forge, anaconda
  - pandas # -c conda-forge, anaconda
  - tabulate # -c conda-forge, anaconda  # necessary for df.to_markdown() in pandas
  - scipy # -c conda-forge, anaconda
  - matplotlib # -c conda-forge, anaconda
  ## Jupyter Related
  - jupyter # -c anaconda, conda-forge
  - jupyterlab # -c anaconda, conda-forge
  - jupyter_dashboards # -c conda-forge  (see: https://medium.com/plotly/introducing-jupyterdash-811f1f57c02e)
  - jupyter_contrib_nbextensions # -c conda-forge
  ## Progressbar
  - tqdm # -c conda-forge, anaconda
  ## Machine Learning
  - tensorflow-gpu # -c anaconda | version: 2.4.1 (linux), 2.3.0 (windows)
  # - tensorflow # -c anaconda | version: 2.2.0 (linux), 2.1.0 (windows)
  - cudnn # -c conda-forge | version: 8.1.0.77 (linux/windows)
  #       # -c anaconda | version: 7.6.5 (linux/windows)
  - cudatoolkit # -c conda-forge | version: 8.1.0.77 (linux/windows)
  #             # -c anaconda | version: 11.0.221 (linux/windows)
  - scikit-learn # -c conda-forge, anaconda
  ## Hyperparameter Optimization
  - optuna # -c conda-forge # works for pytorch, tf/keras, mxnet, scikit-learn, xgboost, lightgbm
  - keras-tuner # -c conda-forge
  ## Image Processing
  - opencv # -c conda-forge, anaconda
  - imageio # -c anaconda, conda-forge
  ## Image Augmentation
  - albumentations # -c conda-forge
  - imgaug # -c conda-forge
  ## Code Linting
  - pylint # -c conda-forge, anaconda
  - autopep8 # -c conda-forge, anaconda
  ## Installations with pip
  - pip:
    ## Web App Framework
    # - Flask-Testing
    - streamlit # https://docs.streamlit.io/en/stable/troubleshooting/clean-install.html

您也可以将下面的指令复制并粘贴到环境文件中,以方便使用。

# Instruction:
#-----------------------------------------------------------
#
## For an environment installed locally (under: ./.venv)
# mkdir -p .venv && cd .venv
# conda env create --prefix . -f ../environment.yml
## For Updating local environment
# cd .venv
# conda env update --prefix . -f ../environment.yml  --prune
#
## For an environment installed globally
## with a name: fav_env 
# NOTE: The env-name is stored inside the 
#       environment.yml file.
# conda env create -f environment.yml
## For Updating global environment from env-file
# conda env update -f ./environment.yml  --prune
#
## Update conda itself
# conda update -n base -c defaults conda
#
## Creating a global environment in one-line: py37, py38
# conda create -n py37 python=3.7
# conda create -n py38 python=3.8
#
### In each of the envs: base, py37, py38
# conda install jupyter jupyterlab numpy scipy pandas matplotlib scikit-learn scikit-image tqdm plotly imageio requests pylint autopep8 tabulate opencv
#
## Export a platform independent copy of an environment
#  conda env export --from-history > path/to/environment.yml
### Make exports directory (if not present already) and export
# $targetDir = conda_exports
# mkdir ./$targetDir
# conda env export --from-history > ./$targetDir/exported_environment.yml

>

  • 如何使用Conda管理包。

    https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/

    https://www.tensorflow.org/guide/gpu

    https://www.fastwebhost.in/blog/how-to-find-if-linux-is-running-on-32-bit-or-64-bit/

    迷你康达装置:https://docs.conda.io/en/latest/miniconda.html

  •  类似资料:
    • 本文向大家介绍Android ViewPager动态加载问题,包括了Android ViewPager动态加载问题的使用技巧和注意事项,需要的朋友参考一下 今天做项目时,纠结了很久,动态添加view,刚开始按照其他的adapter处理,但是不会刷新view,来回翻几页,还会view覆盖,最后手动调用adapter的destroyItem和instantiateItem方法,还是不行,最后重写not

    • 问题内容: 如何从库本身中获取共享库的路径? 换句话说,假设使用来加载库X ,如何从库本身内部访问用于加载所述库的路径? 请注意,我不能首先将这个库加载到该库中。 更新: 这是使用静态变量的方法: 问题答案: 动态链接器实际上搜索几个位置以找到每个动态库。其中包括(来自man ld.so): 环境变量给定的路径 烘焙到二进制文件中的路径将加载条目下的库 缓存文件/etc/ld.so.cache /

    • 我本来是用PyCharm运行Tensorflow的,在PyCharm中,没有出现和标题一样的短语,但是我切换到VS Code,安装了Python扩展后,当我把的时候,像标题这样的错误反复出现。 导入错误: 无法加载动态库“cudart64_110.dll” 考虑到PyCharm中没有问题,这似乎不是环境变量问题。 当我在命令提示符窗口中键入在VS Code中执行的相同命令时,会出现另一个短语, “

    • 我有高塞拉操作系统-版本10.13.6 PHP版本:PHP 7.1.9 当我尝试做命令总是出现这样的错误: PHP启动:无法加载动态库'/usr/本地/php5-7.1.9-20170914-100859 /lib/php/extensions/no-debug-non-zts-20160303/imagick.so'-dlopens(/usr/本地/php5-7.1.9-20170914-100