Google ColabのGPU vs Macbook ProのCPU
GPUが12時間まで無料で使えてしまうGoogle Colab、それなりの規模のデータセットをGoogle Driveにアップロードするところがボトルネックになっていて、これなら多少遅くとも家で使わずに眠っているMacbook Proを稼働させた方が良いのでは...?という気がしてきて、とりあえずどれぐらいの性能差があるのか把握するためにパフォーマンス測定をしてみた。
Google Colab(GPU)のパフォーマンス測定
こちらの記事を参考に、以下のコードを使ってGPU/CPUのパフォーマンスを測定。
Colab側で動かしたコードはこちら(GPUパフォーマンスを測定):
import tensorflow as tf
import timeit
# See https://www.tensorflow.org/tutorials/using_gpu#allowing_gpu_memory_growth
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
with tf.device('/gpu:0'):
random_image_gpu = tf.random_normal((100, 100, 100, 3))
net_gpu = tf.layers.conv2d(random_image_gpu, 32, 7)
net_gpu = tf.reduce_sum(net_gpu)
sess = tf.Session(config=config)
# Test execution once to detect errors early.
try:
sess.run(tf.global_variables_initializer())
except tf.errors.InvalidArgumentError:
print(
'\n\nThis error most likely means that this notebook is not '
'configured to use a GPU. Change this in Notebook Settings via the '
'command palette (cmd/ctrl-shift-P) or the Edit menu.\n\n')
raise
def gpu():
sess.run(net_gpu)
# Runs the op several times.
print('Time (s) to convolve 32x7x7x3 filter over random 100x100x100x3 images '
'(batch x height x width x channel). Sum of ten runs.')
print('GPU (s):')
gpu_time = timeit.timeit('gpu()', number=10, setup="from __main__ import gpu")
print(gpu_time)
sess.close()
測定結果:
GPU (s):
0.04387849099998675
Macbook Pro(CPU)のパフォーマンス測定
### 2019の16インチ(2.4GHz 8コアIntel Core i9プロセッサ/ 64GB 2,666MHz メモリ)で測定
最後まで読んでいただきありがとうございます!もし参考になる部分があれば、スキを押していただけると励みになります。 Twitterもフォローしていただけたら嬉しいです。 https://twitter.com/shu223/