CPU vs GPU in Oracle Cloud

If you read my blog post called “Optimizing TensorFlow for CPU“, you learned that you can improve TensorFlow for CPU by just choosing the correct distribution, in this case the Anaconda distribution.

CPU instances will do the work for simple AI projects, but if you need more computing power to reduce the execution or training time of your project, you need to use GPU instances.

Since many people have asked me to run the same test using GPU instances, in this post you will see the results of this test!

For this test, I used Oracle Cloud Infrastructure instead of the Oracle Cloud Infrastructure Classic used in the last blog post. Oracle Cloud Infrastructure is the new generation of Oracle’s IaaS, so it’s the right solution to use now.

These are the instances:

  • CPU Instance (VM.Standard2.2) = 2 OCPUs + 30GB memory
  • GPU Instance (VM.GPU3.1) = 1 GPU V100 + 90GB memory

In the CPU instance I created the Anaconda environment using:

conda create -n py36tf tensorflow python=3.6

In the GPU instance I created the Anaconda environment using:

conda create -n py36tf tensorflow-gpu python=3.6

To evaluate performance between CPU and GPU instances, I used TensorFlow to run the following matrix multiplication script:

import tensorflow as tf
import time

tf.set_random_seed(42)
A = tf.random_normal([10000,10000])
B = tf.random_normal([10000,10000])

def check():
start_time = time.time()
with tf.Session() as sess:
print(sess.run(tf.reduce_sum(tf.matmul(A,B))))
print("It took {} seconds".format(time.time() - start_time))

check()

These were the results:

In CPU instance it took 22.23 seconds.

In GPU instance it took 3.41 seconds.

The difference between CPU and GPU instances was close to 650%!

The main goal of this post was to show that you need to think about the requirements of your AI project to choose the right tools and environments to run it with the best performance and budget!

Have a good time!

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.