Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run TensorFlow on AMD/ATI GPU?

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.

like image 771
Suleyman Suleymanzade Avatar asked Aug 07 '18 14:08

Suleyman Suleymanzade


People also ask

Can I use AMD GPU with TensorFlow?

Before you can run an AMD machine learning framework container, your Docker environment must support AMD GPUs. X86_64 CPU(s). Note: The AMD TensorFlow framework container assumes that the server contains the required x86-64 CPU(s) and at least one of the listed AMD GPUs.

Can I use AMD GPU for deep learning?

You can use AMD GPUs for machine/deep learning, but at the time of writing Nvidia's GPUs have much higher compatibility, and are just generally better integrated into tools like TensorFlow and PyTorch.

Can TensorFlow run on any GPU?

Hardware requirements. Note: TensorFlow binaries use AVX instructions which may not run on older CPUs. The following GPU-enabled devices are supported: NVIDIA® GPU card with CUDA® architectures 3.5, 5.0, 6.0, 7.0, 7.5, 8.0 and higher.

Does TensorFlow work with AMD cpu?

AMD CPU's work just fine with tensorflow, and are usually better value than Intel CPU's. Do note that tensorflow-gpu only works with nVidia GPU's. Other than that, make sure the CPU has enough PCIe lanes for the number of GPU's you want to connect.


1 Answers

It is most certainly possible to run tensorflow on AMD GPUs. About 2 years back ROCm was released which gets things done. However, the is a caveat, that it runs only on Linux as of now owing to its open-source origins. So if you are willing to use Linux then you can most certainly train your DL models using AMD GPUs. That said the amount of support you will get is low as the community is still not large enough. Google search for ROCm and you can get instructions on how to get it set up and running on a Linux machine. May be it will work with WSL2 in windows, but I have not tried it yet and so cannot comment on that.

here is a link to ROCm installation docs

like image 115
RahulCastro Avatar answered Oct 25 '22 04:10

RahulCastro