1. ホーム
  2. python

tensorflow_GPUが正常にインストールされているかテストします。

2022-02-16 11:18:22
<パス

tensorflow_GPUが正常にインストールされているかどうかテストします。


tensorflow_GPUが正常にインストールされているかどうかテストします。
正常な場合は2を出力し、2を出力する前に演算能力(ケイパビリティ)、GPUの割り当てなどの長い文字列を持つはずです。

コード

# coding=gbk
# test if tensorflow_GPU is installed successfully
# if normal it should output 2, and there is a long string of information such as arithmetic power (ability), gpu allocation, etc. before outputting 2.
import tensorflow as tf
a = tf.constant(1)
b = tf.constant(1)
c = a + b
sess = tf.Session(config = tf.ConfigProto(log_device_placement = True))
print(sess.run(c))


2020-11-29 15:34:00.186534: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-11-29 15:34:00.479808: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.25GiB
2020-11-29 15:34:00.480039: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2020-11-29 15:34:01.355166: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-29 15:34:01.355281: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0 
2020-11-29 15:34:01.355338: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N 
2020-11-29 15:34:01.355520: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/ task:0/device:GPU:0 with 2941 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
2020-11-29 15:34:01.357395: I tensorflow/core/common_runtime/direct_session.cc:307] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5

2020-11-29 15:34:01.358428: I tensorflow/core/common_runtime/placer.cc:927] add: (Add)/job:localhost/replica:0/task:0/device:GPU:0
2020-11-29 15:34:01.358544: I tensorflow/core/common_runtime/placer.cc:927] Const: (Const)/job:localhost/replica:0/task:0/device:GPU:0
2020-11-29 15:34:01.358660: I tensorflow/core/common_runtime/placer.cc:927] Const_1: (Const)/job:localhost/replica:0/task:0/device:GPU: 0
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
add: (Add): /job:localhost/replica:0/task:0/device:GPU:0
Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2

Process finished with exit code 0


成果

2020-11-29 15:34:00.186534: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-11-29 15:34:00.479808: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.25GiB
2020-11-29 15:34:00.480039: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2020-11-29 15:34:01.355166: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-29 15:34:01.355281: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0 
2020-11-29 15:34:01.355338: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N 
2020-11-29 15:34:01.355520: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/ task:0/device:GPU:0 with 2941 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
2020-11-29 15:34:01.357395: I tensorflow/core/common_runtime/direct_session.cc:307] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5

2020-11-29 15:34:01.358428: I tensorflow/core/common_runtime/placer.cc:927] add: (Add)/job:localhost/replica:0/task:0/device:GPU:0
2020-11-29 15:34:01.358544: I tensorflow/core/common_runtime/placer.cc:927] Const: (Const)/job:localhost/replica:0/task:0/device:GPU:0
2020-11-29 15:34:01.358660: I tensorflow/core/common_runtime/placer.cc:927] Const_1: (Const)/job:localhost/replica:0/task:0/device:GPU: 0
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5
add: (Add): /job:localhost/replica:0/task:0/device:GPU:0
Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2

Process finished with exit code 0