win10 安装tenserflow GPU过程记录

文章目录

    • 资料
    • 1.安装cuda
    • 2. 安装cudnn
    • 测试tensorflow是否有使用GPU

现在安装和上一年安装相比要便捷的多,没有太多琐碎的步骤,

注意cuda、cudnn、GPU、tensorflow之间的版本对应关系。

资料

tensorflow官网

Win10安装tensorflow-gpu步骤

windows下cuda的安装

cudnn官方文档

tensorflow查看使用的是cpu还是gpu

WIN10安装TENSORFLOW(GPU版本)详解(超详细,从零开始)

1.安装cuda

win10 安装tenserflow GPU过程记录_第1张图片
win10 安装tenserflow GPU过程记录_第2张图片

谷歌搜索:cuda 10.2.141 driver
https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
win10 安装tenserflow GPU过程记录_第3张图片

win10 安装tenserflow GPU过程记录_第4张图片
避免安装不必要的组件,这里选择自定义安装
win10 安装tenserflow GPU过程记录_第5张图片
win10 安装tenserflow GPU过程记录_第6张图片
win10 安装tenserflow GPU过程记录_第7张图片
C盘空间充足,所以这里我不做更改
win10 安装tenserflow GPU过程记录_第8张图片
win10 安装tenserflow GPU过程记录_第9张图片
完毕
win10 安装tenserflow GPU过程记录_第10张图片
win10 安装tenserflow GPU过程记录_第11张图片
关于cuda的环境变量,我这里是安装完毕后自动添加的有。
在这里插入图片描述

在cuda samples文件夹中启动示例,查看运行输出,可以看到运行示例程序时在GPU、CPU上的时间。
win10 安装tenserflow GPU过程记录_第12张图片

win10 安装tenserflow GPU过程记录_第13张图片

2. 安装cudnn

访问该页面(url)查看cudnn和cuda版本对应关系
win10 安装tenserflow GPU过程记录_第14张图片
cudnn下载页面:https://developer.nvidia.com/rdp/form/cudnn-download-survey
根据系统版本,我这里选的是cudnn library for win10
win10 安装tenserflow GPU过程记录_第15张图片
下载解压后
F:\下载\ChromeDownload\cudnn-10.2-windows10-x64-v7.6.5.32\cuda\bin\cudnn*.dll复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin路径下
win10 安装tenserflow GPU过程记录_第16张图片
F:\下载\ChromeDownload\cudnn-10.2-windows10-x64-v7.6.5.32\cuda\include\cudnn*.h复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include
win10 安装tenserflow GPU过程记录_第17张图片
F:\下载\ChromeDownload\cudnn-10.2-windows10-x64-v7.6.5.32\cuda\lib\x64复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64
win10 安装tenserflow GPU过程记录_第18张图片
打开一个cmd,键入control sysdm.cpl
win10 安装tenserflow GPU过程记录_第19张图片
添加环境变量
变量名:CUDA_PATH
变量的值:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2
win10 安装tenserflow GPU过程记录_第20张图片
我这边在安装cuda时已经自动添加过这个环境变量。

如果在开发过程中使用的是visual studio 那么还需要将cudnn.lib添加到你的项目中,在“项目”->“属性” “链接器” “输入” “附加依赖项” 中添加cudnn.lib并确定即可
win10 安装tenserflow GPU过程记录_第21张图片

测试tensorflow是否有使用GPU

新建python文件
运行如下内容

from tensorflow.python.client import device_lib

print(device_lib.list_local_devices())

查看输出,可以看到GPU设备,说明成功~~

2020-07-20 19:46:00.994189: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-07-20 19:46:00.994416: 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-07-20 19:46:03.496997: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-07-20 19:46:03.506445: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x27217c3dcf0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-20 19:46:03.506899: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-07-20 19:46:03.518994: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-07-20 19:46:03.575822: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1050 Ti computeCapability: 6.1
coreClock: 1.62GHz coreCount: 6 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s
2020-07-20 19:46:03.579216: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-07-20 19:46:03.662971: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-07-20 19:46:03.714476: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-07-20 19:46:03.735304: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-07-20 19:46:03.804328: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-07-20 19:46:03.838115: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-07-20 19:46:03.947359: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-07-20 19:46:03.947536: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] 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-07-20 19:46:04.065192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-20 19:46:04.065428: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-07-20 19:46:04.065533: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-07-20 19:46:04.070126: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x27217c3c970 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-07-20 19:46:04.070448: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1050 Ti, Compute Capability 6.1
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 11094447684184939916
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 11168722219354010654
physical_device_desc: "device: XLA_CPU device"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 5706144976707029859
physical_device_desc: "device: XLA_GPU device"
]

你可能感兴趣的:(Machine,Learning)