tensorflow测试gpu_如何检验 tensorflow-gpu 安装成功 ?
編寫 demo.py
import tensorflow as tf sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))查看日志信息若包含gpu信息,就是使用了gpu。
其他方法:跑計算量大的代碼,通過 nvidia-smi 命令查看gpu的內存使用量。
執行 demo.py
執行方式1:在 python-IDLE 中打開文件demo.py 并 Run Model :
>>> == RESTART: D:下載forGPU--CUDA--TensorFlow--CUDNNtensorflow-gpu_demo_01.py == >>>什么情況?沒有 gpu 信息?
執行方式2:在cmd下執行demo.py :
D:下載forGPU--CUDA--TensorFlow--CUDNN>tensorflow-gpu_demo_01.py 2018-11-02 17:25:34.590159: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 Device mapping: no known devices. 2018-11-02 17:25:34.609960: I tensorflow/core/common_runtime/direct_session.cc:291] Device mapping:問題:無法獲取GPU設備信息?
win10 下安裝 tensorflow_gpu 的各種嘗試之后,終于可獲取 GPU 設備了。
遇到的坑,備忘如下:
1. 為GPU顯卡安裝驅動: Nvidia GPU drivers: for GeForce 730
特別說明:考慮到驅動版本比CUDA9所帶版本要高,可能會有沖突,可以跳過這一步,直接在第3步安裝CUDA 9 時一起安裝,保持版本一致,安心些。
2. 安裝 Microsoft Visual C++ 2015 Redistributable Update 3 and Build Tools
說明:win10下之前安裝了vs2017,但查資料要求vc++2015 Redistributable...多次安裝 tensorflow_gpu 無果后,老實安裝單個組件!否則CUDA9安裝時就會報一個失敗信息:
3. 安裝 CUDA Toolkit: 9.0.176
開始安裝了CUDA 10,盡管有資料顯示,目前 CUDA 10 也是可以構建 tensorflow_gpu 的,但是,各種嘗試失敗,放棄了,老實安裝 CUDA 9。
4. CUDNN: 7.0.5-win10 for CUDA 9.0
開始安裝了 cuDNN 7.2 for CUDA10,后來安裝了cuDNN 7.2 for CUDA 9,失敗。前人的經驗貼,還是要 cuDNN 7.0 才能與 CUDA 9 匹配。
5. Python 3.6.7
這個沒啥坑。
6. Tensorflow_gpu : 1.10.0 for win10
開始安裝的 tensorflow_gpu==1.11.0 就是找不到系統的GPU設備。嗯。
最終可用環境
win10 環境變量設置:
所裝軟件:
python3 所裝模塊:
D:下載forGPU--CUDA--TensorFlow--CUDNN005-tensorflow>pip3 list Package Version ------------------- ------- absl-py 0.6.1 astor 0.7.1 cycler 0.10.0 gast 0.2.0 grpcio 1.16.0 h5py 2.8.0 Keras-Applications 1.0.6 Keras-Preprocessing 1.0.5 kiwisolver 1.0.1 Markdown 3.0.1 matplotlib 3.0.1 numpy 1.14.5 pip 18.1 protobuf 3.6.1 pyparsing 2.3.0 python-dateutil 2.7.5 scipy 1.1.0 setuptools 39.0.1 six 1.11.0 tensorboard 1.10.0 tensorflow-gpu 1.10.0 termcolor 1.1.0 Werkzeug 0.14.1 wheel 0.32.2首個測試腳本:
from tensorflow.python.client import device_lib print(device_lib.list_local_devices())測試結果:
D:下載forGPU--CUDA--TensorFlow--CUDNN005-tensorflowforPip3>python list_devices.py 2018-11-06 16:27:41.136529: I T:srcgithubtensorflowtensorflowcoreplatformcpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2018-11-06 16:27:41.432483: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:1405] Found device 0 with properties: name: GeForce GT 730 major: 3 minor: 5 memoryClockRate(GHz): 0.9015 pciBusID: 0000:01:00.0 totalMemory: 2.00GiB freeMemory: 1.66GiB 2018-11-06 16:27:41.442557: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:1484] Adding visible gpu devices: 0 2018-11-06 16:27:42.162345: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-11-06 16:27:42.169115: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:971] 0 2018-11-06 16:27:42.174183: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:984] 0: N 2018-11-06 16:27:42.177441: I T:srcgithubtensorflowtensorflowcorecommon_runtimegpugpu_device.cc:1097] Created TensorFlow device (/device:GPU:0 with 1437 MB memory) -> physical GPU (device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0, compute capability: 3.5) [name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 8266507417800313319 , name: "/device:GPU:0" device_type: "GPU" memory_limit: 1507796582 locality {bus_id: 1links {} } incarnation: 5735230319323510955 physical_device_desc: "device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0, compute capability: 3.5" ]最后再注明一下,其他坑花了半天時間,最后這兩個坑 cuDNN 7.2 與 tensorflow_gpu==1.11.0 因為下載時看到官方說明是支持的,啊啊啊~~~ 害我折騰了兩天,最后放棄抗爭,采用 cuDNN 7.0 與 tensorflow_gpu==1.10.0,才搞定了。
終于搞定,開心下!
總結
以上是生活随笔為你收集整理的tensorflow测试gpu_如何检验 tensorflow-gpu 安装成功 ?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux pmap 内存泄露,一个驱动
- 下一篇: java实现把数据写入到Excel并下载