Windows下查看cuda与cuDNN的版本n-Tensorflow与Pytorch

配置环境,害,咋说呢,一生之敌,却又不得不卑微地屈服

其实pytorch和TensorFlow现在的配置都很简单了,包括用Anaconda,真的非常方便,想起当时大三的时候配的那个Hadoop和Spark那才是真正的崩溃。。。不过也许只是当时自己特别憨憨吧,经过研一研二配置嵌入式之后,感觉自己的耐心好多了,而且最重要的是,心态放平了,不再那么如履薄冰了,其实没啥大不了的,大不了重装系统嘛(妈的别装了。但确实是的,配环境,认真看教程,不要看一步做一步,最好了解上下文,然后觉得靠谱了去试,错了也不打紧,有问题就去解决问题好了。

写这个简单的blog只是记录下常用的查看指令,免得每次都是要百度。。

Anaconda

首先配置深度学习环境的话,首推当然是Anaconda,我记得我大四的时候第一次配Tensorflow,那时候还有好多声音说没必要,那个全但是笨重,所以我是直接装的,当时也比较幸运,跟的是手把手在Windows上安装TensorFlow无坑教程,确实也没有坑,只不过当时pip install的时候直接是tensorflow,但是要装gpu版本的话是需要,pip install tensorflow-gpu,但是TensorFlow在2.0后,二者统一了,没有区别了

而且Anaconda还有一个最屌的,就是他可以自己安装和TensorFlow或者pytorch配套的CUDA和cuDNN,我之前配置的时候,还是按老规矩老老实实地装了驱动,cuda,载了cuDNN放进去,然后我发现我在创建虚拟环境后,通过conda安装TensorFlow或者pytorch的时候,他会自己寻找合适的cuda和cuDNN,这个可以通过后续查看版本的时候验证

查看版本

直接查看安装路径

最最简单粗暴的是,查看安装路径。。

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2

喏,一目了然,是10.2的cuda,那么cuDNN呢,打开include文件夹,搜索打开cudnn.h,查看:

image-20200723232528044

所以cuDNN就是7.6.5,简单粗暴吧

通过CMD指令

也可以在cmd中查看本机的cuda和cuDNN,很简单,在装cuda的时候添加环境变量后即可,然后在cmd中输入,nvcc -V即可获取当前的cuda版本,然后还可以通过nvidia-smi 获取当前显卡设备的状态

image-20200723232318168

(忽略中间拼错的愚蠢。。

但是上述两种方法的局限在于,当我们是用conda创建了多个env放不同的tensorflow和pytorch的时候,我们不好直接找到各个环境下的版本信息,所以用一下的方法

通过conda list查看包的版本信息

通过conda list,直接查看当前环境下安装的版本,如:

image-20200723233714535

pytorch环境下的,但是有个问题,只有pytorch不显示cuDNN的版本

image-20200723233757997.

TensorFlow环境下的:

image-20200723233845938

通过TensorFlow和pytorch的接口

这个是最科学的,意味着你真正调用的时候是啥版本,同时它也才是真正检验安装成功的标准

TensorFlow:

这个是最明显的,因为如果装的是gpu版本,cuda和cudnn没问题的话,你一操作TensorFlow就会有一堆信息输出。。。

可以通过简单的Session跑一个constant,也可以通过以下接口

信息太多,主要的是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(tensorflow) C:\Users\Wu>python
Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-07-23 23:44:40.411315: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
>>> tf.test.gpu_device_name()
'/device:GPU:0'
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
True
>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 2182526894326393463
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3140970087
locality {
bus_id: 1
links {
}
}
incarnation: 16323860753275536829
physical_device_desc: "device: 0, name: Quadro P1000, pci bus id: 0000:65:00.0, compute capability: 6.1"
]
>>>

全文是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(tensorflow) C:\Users\Wu>python
Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-07-23 23:44:40.411315: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
>>> tf.test.gpu_device_name()
2020-07-23 23:44:54.210402: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-07-23 23:44:54.218134: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-07-23 23:44:54.250205: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:65:00.0 name: Quadro P1000 computeCapability: 6.1
coreClock: 1.4805GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 74.65GiB/s
2020-07-23 23:44:54.250419: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-07-23 23:44:54.300697: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-07-23 23:44:54.342842: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-07-23 23:44:54.352593: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-07-23 23:44:54.408776: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-07-23 23:44:54.433255: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-07-23 23:44:54.528026: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-07-23 23:44:54.529742: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
2020-07-23 23:44:56.894511: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-23 23:44:56.895100: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0
2020-07-23 23:44:56.896178: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N
2020-07-23 23:44:56.901069: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/device:GPU:0 with 2995 MB memory) -> physical GPU (device: 0, name: Quadro P1000, pci bus id: 0000:65:00.0, compute capability: 6.1)
'/device:GPU:0'
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2020-07-23 23:45:15.149208: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:65:00.0 name: Quadro P1000 computeCapability: 6.1
coreClock: 1.4805GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 74.65GiB/s
2020-07-23 23:45:15.149293: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-07-23 23:45:15.149656: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-07-23 23:45:15.149987: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-07-23 23:45:15.150327: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-07-23 23:45:15.150667: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-07-23 23:45:15.151006: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-07-23 23:45:15.151343: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-07-23 23:45:15.152040: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
2020-07-23 23:45:15.152146: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-23 23:45:15.152539: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0
2020-07-23 23:45:15.152901: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N
2020-07-23 23:45:15.153622: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/device:GPU:0 with 2995 MB memory) -> physical GPU (device: 0, name: Quadro P1000, pci bus id: 0000:65:00.0, compute capability: 6.1)
True
>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()
2020-07-23 23:45:50.518614: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:65:00.0 name: Quadro P1000 computeCapability: 6.1
coreClock: 1.4805GHz coreCount: 5 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 74.65GiB/s
2020-07-23 23:45:50.522100: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-07-23 23:45:50.522709: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-07-23 23:45:50.523088: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-07-23 23:45:50.523489: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-07-23 23:45:50.523841: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-07-23 23:45:50.524201: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-07-23 23:45:50.524554: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-07-23 23:45:50.525288: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
2020-07-23 23:45:50.525383: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-23 23:45:50.525704: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0
2020-07-23 23:45:50.526051: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N
2020-07-23 23:45:50.529254: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/device:GPU:0 with 2995 MB memory) -> physical GPU (device: 0, name: Quadro P1000, pci bus id: 0000:65:00.0, compute capability: 6.1)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 2182526894326393463
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3140970087
locality {
bus_id: 1
links {
}
}
incarnation: 16323860753275536829
physical_device_desc: "device: 0, name: Quadro P1000, pci bus id: 0000:65:00.0, compute capability: 6.1"
]
>>>

Pytorch:

可以通过torch.cuda.is_available()确认我们的显卡和cuda是否可用,可以则配置成功啦,具体的版本信息接口如下:

1
2
3
4
5
6
7
8
9
10
11
12
(pytorch) C:\Users\Wu>python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.2.0'
>>> torch.version.cuda
'10.0'
>>> torch.backends.cudnn.version()
7401
>>> torch.cuda.is_available()
True

Conda clean

如果觉得conda的包比较多,占空间,可以用conda clean来清理

conda clean使用
删除从不使用的包

1
$ conda clean --packages

删除tar包

1
$ conda clean --tarballs

删除索引缓存、锁定文件、未使用过的包和tar包

1
$ conda clean -a

完整如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$ conda clean -H
usage: conda clean [-h] [-a] [-i] [-l] [-p] [-t] [-f]
[-c TEMPFILES [TEMPFILES ...]] [-d] [--json] [-q] [-v] [-y]

Remove unused packages and caches.

Options:

optional arguments:
-h, --help Show this help message and exit.

Removal Targets:
-a, --all Remove index cache, lock files, unused cache packages,
and tarballs.
-i, --index-cache Remove index cache.
-l, --lock Remove all conda lock files.
-p, --packages Remove unused packages from writable package caches.
WARNING: This does not check for packages installed
using symlinks back to the package cache.
-t, --tarballs Remove cached package tarballs.
-f, --force-pkgs-dirs
Remove *all* writable package caches. This option is
not included with the --all flag. WARNING: This will
break environments with packages installed using
symlinks back to the package cache.
-c TEMPFILES [TEMPFILES ...], --tempfiles TEMPFILES [TEMPFILES ...]
Remove temporary files that could not be deleted
earlier due to being in-use. Argument is path(s) to
prefix(es) where files should be found and removed.

Output, Prompt, and Flow Control Options:
-d, --dry-run Only display what would have been done.
--json Report all output as json. Suitable for using conda
programmatically.
-q, --quiet Do not display progress bar.
-v, --verbose Can be used multiple times. Once for INFO, twice for
DEBUG, three times for TRACE.
-y, --yes Do not ask for confirmation.

Examples:

conda clean --tarballs

参考自Conda clean 净化Anaconda

0%