如何在 AMD/ATI GPU 上 运行 TensorFlow?
How to run TensorFlow on AMD/ATI GPU?
读完本教程后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: 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.]]
如您所见,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: 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.]]
我可以运行 GPU 卡上的会话做什么?谢谢。
我相信 TensorFlow-GPU 只支持 NVIDIA CUDA 计算能力 >= 3.0 的 GPU 卡。
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.
您可以使用 TensorflowJS,即 Javascript 版本的 tensorflow。
TensorflowJS 没有任何硬件限制,可以 运行 在所有支持 webGL 的 gpu 上。
api 与 python 中的 tf 非常相似,该项目提供了将模型从 python 转换为 JS
的脚本
肯定有可能在 AMD GPU 上 运行 tensorflow。大约 2 年前,ROCm 发布,它完成了任务。但是,需要注意的是,由于其开源起源,它 运行 目前仅在 Linux 上可用。因此,如果您愿意使用 Linux,那么您肯定可以使用 AMD GPU 训练您的 DL 模型。也就是说,由于社区仍然不够大,您将获得的支持量很少。 Google 搜索 ROCm,您可以获得有关如何在 Linux 机器上设置和 运行ning 的说明。它可能会在 windows 中与 WSL2 一起使用,但我还没有尝试过,所以无法对此发表评论。
读完本教程后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: 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.]]
如您所见,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: 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.]]
我可以运行 GPU 卡上的会话做什么?谢谢。
我相信 TensorFlow-GPU 只支持 NVIDIA CUDA 计算能力 >= 3.0 的 GPU 卡。
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.
您可以使用 TensorflowJS,即 Javascript 版本的 tensorflow。 TensorflowJS 没有任何硬件限制,可以 运行 在所有支持 webGL 的 gpu 上。
api 与 python 中的 tf 非常相似,该项目提供了将模型从 python 转换为 JS
的脚本肯定有可能在 AMD GPU 上 运行 tensorflow。大约 2 年前,ROCm 发布,它完成了任务。但是,需要注意的是,由于其开源起源,它 运行 目前仅在 Linux 上可用。因此,如果您愿意使用 Linux,那么您肯定可以使用 AMD GPU 训练您的 DL 模型。也就是说,由于社区仍然不够大,您将获得的支持量很少。 Google 搜索 ROCm,您可以获得有关如何在 Linux 机器上设置和 运行ning 的说明。它可能会在 windows 中与 WSL2 一起使用,但我还没有尝试过,所以无法对此发表评论。