LoginSignup
7
8

More than 5 years have passed since last update.

TensorflowGPU 動作確認用スクリプト

Last updated at Posted at 2018-07-11

自分のTensorflow-gpuが動作しているかどうかを判定するスクリプト:


import tensorflow as tf

# デフォルトGPU (device:0)を指名で行列計算を行う
with tf.device('/gpu:0'):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
    c = tf.matmul(a, b)
with tf.Session() as sess:
    print (sess.run(c))

[Tensorflow ver1.40+以降で確認済み]

エラーにならず、以下を確認できれば確実にGPUで回ってる事が確認できる:
image.png

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8