How to run TensorFlow on AMD/ATI GPU?

2019-07-07 20:13发布

问题:

After reading this tutorial https://www.tensorflow.org/guide/using_gpu I checked GPU session on this simple code

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)

The output was

2018-08-07 18:44:59.019144: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Device mapping: no known devices. 2018-08-07 18:44:59.019536: I tensorflow/core/common_runtime/direct_session.cc:288] Device mapping:

MatMul: (MatMul): /job:localhost/replica:0/task:0/device:CPU:0 2018-08-07 18:44:59.019902: I tensorflow/core/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: I tensorflow/core/common_runtime/placer.cc:886] a: (Const)/job:localhost/replica:0/task:0/device:CPU:0 b: (Const): /job:localhost/replica:0/task:0/device:CPU:0 2018-08-07 18:44:59.019934: I tensorflow/core/common_runtime/placer.cc:886] b: (Const)/job:localhost/replica:0/task:0/device:CPU:0 [[ 22. 28.] [ 49. 64.]]

As you see there is no calculation done by GPU. and when I changed the code to use GPU's configuration and process fraction:

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)

The output was

2018-08-07 18:52:22.681221: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA [[ 22. 28.] [ 49. 64.]]

What can I do to run the session on GPU card? Thank you.

回答1:

I believe TensorFlow-GPU only support GPU card with CUDA Compute Capability >= 3.0 of NVIDIA.

The following TensorFlow variants are available for installation:

TensorFlow with CPU support only. If your system does not have a NVIDIA® GPU, you must install this version. This version of TensorFlow is usually easier to install, so even if you have an NVIDIA GPU, we recommend installing this version first.

TensorFlow with GPU support. TensorFlow programs usually run much faster on a GPU instead of a CPU. If you run performance-critical applications and your system has an NVIDIA® GPU that meets the prerequisites, you should install this version. See TensorFlow GPU support for details.

https://www.tensorflow.org/install/install_linux