1. 查看能否运行GPU
1 2 3 4 5 6 7 8 9 10 11 12 13 | In [1]: import tensorflow as tf In [2]: tf.__version__ Out[2]: '1.4.0' In [3]: tf.test.is_gpu_available() 2020-06-01 23:37:07.634135: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 2020-06-01 23:37:09.502059: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493 pciBusID: 0000:01:00.0 totalMemory: 4.00GiB freeMemory: 3.33GiB 2020-06-01 23:37:09.527007: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1) Out[3]: True |
2. 查看GPU占用情况
3. 使用GPU进行测试
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 | In [1]: import tensorflow as tf In [2]: import numpy as np In [3]: config = tf.ConfigProto(log_device_placement=True) In [4]: with tf.Session(config=config) as sess: ...: a = tf.placeholder(tf.int32) ...: b = tf.placeholder(tf.int32) ...: add = tf.add(a, b) ...: s = sess.run(add, feed_dict={a:1, b:2}) ...: print(s) ...: 2020-06-01 23:59:37.153345: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 2020-06-01 23:59:38.879487: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493 pciBusID: 0000:01:00.0 totalMemory: 4.00GiB freeMemory: 3.33GiB 2020-06-01 23:59:38.918401: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1) Device mapping: /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1 2020-06-01 23:59:39.161636: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\direct_session.cc:299] Device mapping: /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1 Add: (Add): /job:localhost/replica:0/task:0/device:GPU:0 2020-06-01 23:59:39.265282: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] Add: (Add)/job:localhost/replica:0/task:0/device:GPU:0 Placeholder_1: (Placeholder): /job:localhost/replica:0/task:0/device:GPU:0 2020-06-01 23:59:39.283582: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] Placeholder_1: (Placeholder)/job:localhost/replica:0/task:0/device:GPU:0 Placeholder: (Placeholder): /job:localhost/replica:0/task:0/device:GPU:0 2020-06-01 23:59:39.304208: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] Placeholder: (Placeholder)/job:localhost/replica:0/task:0/device:GPU:0 3 In [5]: |