tensorflow測試gpu_如何檢驗 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: 1
links {
}
}
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,才搞定了。
終於搞定,開心下!