【发布时间】:2019-01-14 17:24:18
【问题描述】:
阅读本教程https://www.tensorflow.org/guide/using_gpu 后,我在这个简单的代码上检查了 GPU 会话
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
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(config=tf.ConfigProto(log_device_placement=True)) as sess:
x = sess.run(c)
print(x)
输出是
2018-08-07 18:44:59.019144: 我 tensorflow/core/platform/cpu_feature_guard.cc:141] 你的 CPU 支持 此 TensorFlow 二进制文件未编译使用的指令:AVX2 FMA 设备映射:没有已知设备。 2018-08-07 18:44:59.019536: 我 tensorflow/core/common_runtime/direct_session.cc:288] 设备映射:
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:CPU:0 2018-08-07 18:44:59.019902: 我 张量流/核心/common_runtime/placer.cc:886] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:CPU:0 a: (Const): /job:localhost/replica:0/task:0/device:CPU:0 2018-08-07 18:44:59.019926:我 tensorflow/core/common_runtime/placer.cc:886] 一个: (常量)/job:localhost/replica:0/task:0/device:CPU:0 b: (常量): /job:localhost/replica:0/task:0/device:CPU:0 2018-08-07 18:44:59.019934:我 tensorflow/core/common_runtime/placer.cc:886] b: (常量)/job:localhost/replica:0/task:0/device:CPU:0 [[ 22. 28.] [ 49. 64.]]
如您所见,GPU 没有进行任何计算。 当我更改代码以使用 GPU 的配置和处理分数时:
conf = tf.ConfigProto()
conf.gpu_options.per_process_gpu_memory_fraction = 0.4
with tf.Session(config = conf) as sess:
x = sess.run(c)
print(x)
输出是
2018-08-07 18:52:22.681221: 我 tensorflow/core/platform/cpu_feature_guard.cc:141] 你的 CPU 支持 此 TensorFlow 二进制文件未编译使用的指令:AVX2 FMA [[ 22. 28.] [ 49. 64.]]
如何在 GPU 卡上运行会话?谢谢。
【问题讨论】:
标签: tensorflow gpu amd