深度学习-推荐系统-CV-NLP大数据,机器学习,人工智能人工智能技术圈

TensorFlow: Use GPU 使用GPU运行Tenso

2019-07-08  本文已影响3人  正在学习的Yuki

使用GPU运行TensorFlow

System Information

Step1: 检查硬件

硬件要求:NVIDIA® GPU card with CUDA® Compute Capability 3.5 or higher.

1. 确认电脑配备GPU
2. 查看GPU的计算能力(需>=3.5)

See the list of CUDA-enabled GPU cards.
e.g. NVIDIA GeForce 930M是

GPU_ComputeCapability.png

Step2: 安装软件

软件要求:

一些建议:

1. NVIDIA® GPU drivers:更新driver

设备管理器 -> GPU 右键 属性 -> Driver 栏 -> Update Driver


UpdateDriver.png
2. CUDA Toolkit:10.0 (9.0或以上)

安装:https://developer.nvidia.com/cuda-toolkit-archive

3. cuDNN

Download cuDNN v7.6.1 (June 24, 2019), for CUDA 10.0
All versions here

Step3: 添加环境变量

将CUDA, CUPTI, cuDNN 路径 加到 系统环境变量PATH 中。
Terminal command:

SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;%PATH%
SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64;%PATH%
SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include;%PATH%
SET PATH=C:\tools\cuda\bin;%PATH%

Step4: 安装 tensorflow-gpu (in Anaconda Prompt)

1. 创建一个python3.7的环境

教程:https://www.jianshu.com/p/64b94a6a7e98

2. 激活环境

conda activate [env_name]

3. 安装tensorflow-gpu1.13.1

建议先 uninstall tensorflow cpu: pip uninstall tensorflow
再安装 tensorflow-gpu1.13.1: pip install tensorflow-gpu==1.13.1

Step5: 测试

'''test.py'''

import tensorflow as tf

import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0" # 设置GPU DEVICE为0 (单显卡)

print("GPU Available: ", tf.test.is_gpu_available()) 
# 若成功,会返回:
# GPU Available:  True

在Terminal中运行成功:


RunningSuccess_Terminal.png

用Pycharm出现的问题

1. Configuration

PyCharm: Configure a Conda virtual environment
PyCharm: Setting an existing project interpreter

2. Import Error
PYCHARM from . import _mklinit 
ImportError: DLL load failed: The specified module could not be found.
解决方法: Update Driver (见Step2.1)
3. CUDA Error
E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit:
CUDA_ERROR_UNKNOWN: unknown error
解决方法 (Refer to Guilherme Melo's advice):
source activate [env_name]
conda install -c conda-forge conda-wrappers
Edit_InterpreterPath.png

最后终于在PyCharm中运行成功啦:


RunningSuccess_Terminal.png

参考来源:https://www.tensorflow.org/install/gpu
有问题欢迎留言讨论

上一篇下一篇

猜你喜欢

热点阅读