欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Could not load dynamic library cudart64_100.dll

程序员文章站 2022-07-15 09:47:49
...

使用环境:

  • TensorFlow==1.15.0 Keras==2.3.1 cuda==10.1 cudnn==7.6.5
    **在玩bert的时,报:
2020-10-11 22:51:52.067448: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-10-11 22:51:52.067648: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-10-11 22:51:52.073182: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cublas64_100.dll'; dlerror: cublas64_100.dll not found
2020-10-11 22:51:52.078544: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'cufft64_100.dll'; dlerror: cufft64_100.dll not found
2020-10-11 22:51:52.081144: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'curand64_100.dll'; dlerror: curand64_100.dll not found
2020-10-11 22:51:52.086796: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'cusolver64_100.dll'; dlerror: cusolver64_100.dll not found
2020-10-11 22:51:52.090414: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Could not load dynamic library 'cusparse64_100.dll'; dlerror: cusparse64_100.dll not found
2020-10-11 22:51:52.100478: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] 
Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found

经过查找,发现其实cuda10.2中包含了cudart64_100.dll的向下兼容。网上说要将cudart64_100.dll的路径添加到环境变量中或更改cudart64_101.dll的名字。各种不行。最后在看到参考中提到可以用Anaconda,果断采用,最后确定方案是:

  • 【1】win10 CUDA安装为CUDA10.1(因为TF2.x系列也就刚支持到CUDA10.1)
  • 【2】pytorch1.6.0+cu101 和 TF2.3.1安装CUDA10.1版本的到纯净Python37(目录C:\Python37)环境下
  • 【3】纯净Python37 python执行方式:C:\Python37\python
  • 【4】纯净Python37 pip执行方式:C:\Python37\Scripts\pip list

【特别注意】Tensorflow版本关系可参考TensorFlow的一些版本约束, Pytorch版本关系可参考PyTorch一些trick

2 Anaconda 3.7

前文说道,为了解决tf1.15.0 cuda pytorch的不兼容问题,特别适用Anaconda来创建一个虚拟环境,conda方式安装cuda库(本机依然是cuda10.1)。

2.1 镜像下载

官网各版本Python对应关系https://docs.anaconda.com/anaconda/packages/oldpkglists/

官网下载仓库https://repo.anaconda.com/archive/
官网下载https://www.anaconda.com/distribution/
清华镜像https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive

这里下载的是Anaconda 2020.02 for 64-bit Windows with Python 3.7

anaconda仓库 https://anaconda.org/anaconda/repo

2.2 安装cuda10.1和纯Python3.7

win10下安装cuda10.1和cudnn
win10下安装Python3.7

2.3 配置conda源

#添加清华的源【推荐使用】
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
#中科大的源
conda config –add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ 
#阿里云的源
conda config --add channels http://mirrors.aliyun.com/pypi/simple/
#移除源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

#显示当前源
conda config --show-sources
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

还有一种方式【在C:\Users\Anjos.condarc下直接 修改其值也可以,cmd下直接就能获取到】:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

2.4 配置环境变量

将:C:\ProgramData\Anaconda3\Scripts、C:\ProgramData\Anaconda3\Library\bin、C:\ProgramData\Anaconda3添加到系统PATH环境变量中

2.5 虚拟环境

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

需要**当前环境即可。

# 搜索库和指定源安装 或 conda search cudatoolkit
anaconda search -t conda cudatoolkit
anaconda show mwojcikowski/cudatoolkit
conda install --channel https://conda.anaconda.org/mwojcikowski cudatoolkit=10.0
命令 含义
【环境检查和配置】
conda config --show-sources 显示当前源
conda config --set show_channel_urls yes 设置搜索时显示通道地址
conda env list 查看已安装的环境
conda info --envs
conda info -e
conda activate base **名称为base的环境 也可以用绝对路径C:\ProgramData\Anaconda3
conda deactivate 退出环境
conda create -n tf115 python=X.X(2.7、3.6等) 创建环境tf115在C:\Users\Anjos\.conda\envs下可查【-n表示-name】
conda create -n tf115 --clone base 创建环境(基于已有环境py3.7)
conda remove -n tf115 --all 删除环境
【conda方式安装库】(若在当前环境下可不需要-n选项)
conda list 查看当前环境下已安装包
conda list -n tf115 查看环境名为tf115下已安装包
conda search numpy 搜索numpy库,在当前源下
conda install -n tf115 numpy 安装numpy库
conda remove/uninstall -n tf115 numpy 移除numpy库
conda install pip 给当前环境安装pip,以后就用pip安装库了
【pip方式安装库】【推荐这种安装,conda顶多帮安装cudnn和cuda】
pip install tensorflow-gpu==1.15.0 -i http://mirrors.aliyun.com/pypi/simple 安装TensorFlow库
pip可直接配置统一的源即可,配置方法见配置源

2.6 idea中使用

定为他即可。C:\ProgramData\Anaconda3\python.exe

也可以借助pycharn和idea自动识别Anaconda3并创建虚拟环境,借助base环境

Could not load dynamic library cudart64_100.dll

2.7 安装TensorFlow1.15.0

conda create -n tf115 --clone base
conda activate tf115

conda install cudatoolkit=10.0
conda install cudnn=7.6.5
pip3 install tensorflow-gpu=1.15.0
# tf1.x 检查GPU是否可用
import tensorflow as tf
hello= tf.constant('Hello, TensorFlow!')
print(tf.Session().run(hello))
print(tf.test.is_gpu_available())

# tf2.x 检查GPU是否可用
import tensorflow as tf
print(tf.test.is_built_with_cuda())
print(tf.test.is_gpu_available(cuda_only=False,min_cuda_compute_capability=None))
# pytorch检查gpu是否可用【这里pytorch就采用纯净不安装了】
import torch
print(torch.cuda.is_available())
【纯净环境下cuda10.1+tf2.3.0】
2020-10-12 22:12:55.759800: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-10-12 22:12:55.770142: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2020-10-12 22:12:55.778848: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-10-12 22:12:55.785005: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-10-12 22:12:55.794067: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2020-10-12 22:12:55.802166: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2020-10-12 22:12:55.815182: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2020-10-12 22:12:55.819302: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-10-12 22:12:56.362918: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-12 22:12:56.367031: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      0
2020-10-12 22:12:56.368975: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0:   N

【conda tf115环境下cuda10.0+tf1.15.0】
2020-10-12 22:14:59.901777: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-10-12 22:15:12.576051: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-10-12 22:15:12.581228: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2020-10-12 22:15:12.584647: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-10-12 22:15:12.588276: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-10-12 22:15:12.592404: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2020-10-12 22:15:12.596107: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2020-10-12 22:15:12.600847: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2020-10-12 22:15:12.606824: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-10-12 22:15:13.177512: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-12 22:15:13.181737: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      0
2020-10-12 22:15:13.184208: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0:   N

Reference

在CUDA10.1版本下安装tensorflow-gpu=1.15版本
Conda命令 + 安装tensorflow

相关标签: Python 工程trick