RX590でtensorflowを利用する

2019/01/16

Radeon RX590をtensorflowで利用する。2019年1月の時点でのrocm公式(version 2.0)のドライバでは RX590を正しく利用することはできない。 rocm用のデバイスドライバは、Linuxのカーネルにもマージされているので、そちらを利用すればよいらしい。

最新のfixがはいったカーネルのソースコードは

https://lists.freedesktop.org/archives/amd-gfx/2018-December/029658.html (2018/12/12の時点での問題修正のもの) https://lists.freedesktop.org/archives/amd-gfx/2019-January/030363.html (2019/01/09の時点での最新のもの)

などにあるので、kernelをbuildしてインストールすればよいはず。だが、動作しなかったので検索したところ、 これらのパッチが当たったkernelのbinaryが配布されていた。

https://github.com/M-Bab/linux-kernel-amdgpu-binaries

このカーネルは12月のパッチ相当のものが当てられていると思われる。 ここの説明によると「Since kernel 4.15 it might be necessary to add amdgpu.dc=1 to the boot parameters.」とのこと。。。 このカーネルでは問題なく動作した。 結果、1月9日のカーネルを自分でbuildしたものでも"amdgpu.dc=1"とすれば問題なかった。参考:https://gihyo.jp/admin/serial/01/ubuntu-recipe/0526?page=2

Ubuntuの場合は"/etc/default/grub"の該当行に

GRUB_CMDLINE_LINUX_DEFAULT="amdgpu.dc=1"

と追記してから"update-grub"コマンドを実行すればばよい。

sudo apt update sudo apt install rocm-dev echo ‘SUBSYSTEM==“kfd”, KERNEL==“kfd”, TAG+=“uaccess”, GROUP=“video”’ | sudo tee /etc/udev/rules.d/70-kfd.rules

sudo apt install rocm-dev

だけ。“rocm-dkms"をインストールしてはいけない。

rocmに対応したtensorflowは

pip3 install tensorflow-rocm

でインストールできる。以下利用したバージョンは1.12。

実行コマンドは

python3 cifar10_train.py --max_steps 8000 --batch_size 512

RX590 のログ抜粋

ログ冒頭 (warningは除く)

2019-01-16 08:45:44.577928: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-01-16 08:45:44.578740: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1530] Found device 0 with properties:
name: Device 67df
AMDGPU ISA: gfx803
memoryClockRate (GHz) 1.576
pciBusID 0000:2e:00.0
Total memory: 8.00GiB
Free memory: 7.75GiB
2019-01-16 08:45:44.578753: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Adding visible gpu devices: 0
2019-01-16 08:45:44.578767: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1051] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-01-16 08:45:44.578771: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1057]      0
2019-01-16 08:45:44.578774: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1070] 0:   N
2019-01-16 08:45:44.578796: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1189] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7539 MB memory) -> physical GPU (device: 0, name: Device 67df, pci bus id: 0000:2e:00.0)
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
2019-01-16 08:45:48.313694: I tensorflow/core/kernels/conv_grad_filter_ops.cc:975] running auto-tune for Backward-Filter
2019-01-16 08:45:48.442058: I tensorflow/core/kernels/conv_grad_input_ops.cc:1023] running auto-tune for Backward-Data
2019-01-16 08:45:48.530418: I tensorflow/core/kernels/conv_grad_filter_ops.cc:975] running auto-tune for Backward-Filter
Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.

ログの最後の5行

2019-01-16 08:51:17.812098: step 7950, loss = 0.66 (13975.9 examples/sec; 0.037 sec/batch)
2019-01-16 08:51:18.179680: step 7960, loss = 0.76 (13929.2 examples/sec; 0.037 sec/batch)
2019-01-16 08:51:18.545570: step 7970, loss = 0.75 (13993.0 examples/sec; 0.037 sec/batch)
2019-01-16 08:51:18.911994: step 7980, loss = 0.81 (13973.3 examples/sec; 0.037 sec/batch)
2019-01-16 08:51:19.280183: step 7990, loss = 0.77 (13905.8 examples/sec; 0.037 sec/batch)

Vega64 のログ抜粋

ログの最後の5行 (maxstep異なる)

2018-12-26 21:11:24.545697: step 950, loss = 2.42 (20708.0 examples/sec; 0.025 sec/batch)
2018-12-26 21:11:24.791090: step 960, loss = 2.37 (20864.4 examples/sec; 0.025 sec/batch)
2018-12-26 21:11:25.039427: step 970, loss = 2.39 (20618.0 examples/sec; 0.025 sec/batch)
2018-12-26 21:11:25.285705: step 980, loss = 2.65 (20790.0 examples/sec; 0.025 sec/batch)
2018-12-26 21:11:25.533574: step 990, loss = 2.54 (20654.8 examples/sec; 0.025 sec/batch)

結果について

Vega64と比べると(過去の結果 http://galaxy.u-aizu.ac.jp/l/posts/2018/04/26/tensorflow-benchmarks/ )、 70%くらいの性能。価格は10万円 vs. 4万円くらいなので、fp32ではRX590のコスパがよい。