1.进入系统的英伟达文件夹查看显卡信息
cd C:\Program Files\NVIDIA Corporation
输入nvidia-smi
查看显卡信息,可以看到本电脑支持的cuda版本是11.0
查看支持cuda的显卡和显卡的计算能力
https://developer.nvidia.com/zh-cn/cuda-gpus
2.下载cuda
全部版本的cuda下载 https://developer.nvidia.com/cuda-toolkit-archive
cuda11下载链接 https://developer.nvidia.com/zh-cn/cuda-downloads
(本处我选择的cuda版本是11.1,虽然和上面查出来的版本不一样,但安装包第一步进行系统检查的时候也通过了)
安装程序类型选择的是local(local版本3.1G,用迅雷下载也很快,一开始使用network版本下载虽然很快,但是安装联网不知道为什么特别慢)
3.安装
自定义安装中,只勾选CUDA
记住这个安装位置,后面还有用
安装完成后测试,输入
nvcc -V
1.cuDNN下载
https://developer.nvidia.com/rdp/cudnn-archive
选择对应的CUDA版本
cuDNN下载需要登陆,没有账号的可以注册一个,很快
需要登陆或注册,登陆后提示即可继续下载(火狐下载很慢,用迅雷)
2.配置
解压下载的cuDNN压缩包,得到如下
此时,需要用到上述CUDA安装的地址,我的地址如下
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
把解压后的bin,include,lib三个文件夹直接选中,然后复制到CUDA的安装地址中(直接选中复制即可,没有重复冲突之类的东西)
3.检查系统变量配置
通常情况,安装后会自动帮我们配置环境变量,以防万一,我们进行一下检查,打开此电脑-属性-高级系统设置-环境变量
Path中:
在anaconda的官网,我选择的individual版本,选择对应的操作系统下载安装即可
https://www.anaconda.com/products/individual
我下载时,只有Python3.8的版本,但此时我电脑上已经安装了Python3.9,要注意安装conda后电脑上存在两个版本的Python。conda的Python安装路径在anaconda下的pkgs
文件夹下
安装时,没有选择Add Anaconda to my PATH environment variable
选项,需要使用时打开anaconda powershell prompt即可。
安装后,我们改一下anaconda默认下载源,在anaconda的控制台中输入,可以在c盘-用户-个人用户下看到.condac
文件
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
进入官网选择对应的版本
https://pytorch.org/get-started/locally/
进入到anaconda的命令台,粘贴下面的命令行,即开始安装(试了一下吧版本改成11.1,不成功)
提示的选择y进行下载安装即可
PS:安装期间报错InvalidArchiveError(‘Error with archive D:\Program Files\Anaconda\pkgs\numpy-base-1.19.1-py36ha3
解决方法https://blog.csdn.net/u011208984/article/details/109176212
python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> a=torch.cuda.is_available();
>>> print(a)
True
>>> ngpu= 1
>>> device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
>>> print(device)
cuda:0
>>> print(torch.cuda.get_device_name(0))
GeForce RTX 2060
>>> print(torch.rand(3,3).cuda())
tensor([[0.9715, 0.1951, 0.4351],
[0.4067, 0.3654, 0.8233],
[0.4502, 0.8057, 0.5741]], device='cuda:0')
在anaconda的控制台下输入,会在anaconda的envs文件夹中创建名为tensorflow
的文件夹
conda create –name tensorflow python=3.8
1.在cmd进入conda下的script目录
C:\Users\lenovo>D:
D:\>cd D:\code\anaconda3\Scripts
2.创建虚环境,procced选项选即可
conda create –n py38 python=3.8
命令执行后提示
激活环境
conda activate py38
退出环境
conda deactivate
3.查看tensorflow和对应cuda的版本
https://tensorflow.google.cn/install/source_windows
在tensorflow的官网查看Python和pip版本要求
https://tensorflow.google.cn/install/pip
4.安装tensorflow-gpu
在anaconda的控制台下激活刚才创建的虚环境,并查看 Python对应的版本和pip对应的版本
(base) PS C:\Users\lenovo> conda activate py38
(py38) PS C:\Users\lenovo> python --version
Python 3.8.5
(py38) PS C:\Users\lenovo> pip --version
pip 20.3 from D:\code\anaconda3\envs\py38\lib\site-packages\pip (python 3.8)
确定都满足要求之后,输入
//安装最新gpu版本
pip intall tensorflow-gpu
//指定版本
pip intall tensorflow-gpu==2.1.0
测试安装:输入"import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
(py38) PS C:\Users\lenovo> python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2020-12-07 14:57:43.056616: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 14:57:43.056761: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-12-07 14:57:47.601373: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-07 14:57:47.634589: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 245.91GiB/s
2020-12-07 14:57:47.636856: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 14:57:47.638105: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-12-07 14:57:47.664987: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-12-07 14:57:47.671588: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-12-07 14:57:47.673032: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-12-07 14:57:47.674327: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-12-07 14:57:47.675763: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-12-07 14:57:47.675822: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] 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-12-07 14:57:47.676642: 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-12-07 14:57:47.685301: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1d2cc13b480 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-12-07 14:57:47.685428: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-12-07 14:57:47.685904: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-07 14:57:47.686063: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
tf.Tensor(368.9865, shape=(), dtype=float32)
85904: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-07 14:57:47.686063: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
tf.Tensor(368.9865, shape=(), dtype=float32)