LoginSignup
6
5

More than 5 years have passed since last update.

Ubuntu18.04 + AMD Radeon + Kerasでディープラーニングするための環境構築

Last updated at Posted at 2018-11-28

注意(追記)

環境構築して再起動したら,画面の表示が乱れ,ログインできなくなりました.Ctrl+Alt+F3で一時的にCUIで操作できるようになるのですが,5秒程で強制的にGUIに切り替えられます.おそらく,GPUのドライバーをインストールしたことが原因だと思われます.

上記のような不具合を避けるために,Dockerで環境構築し直しました.
Keras + AMD Radeon + Dockerでディープラーニングするための環境構築

環境

OS: Ubuntu 18.04.1 LTS
GPU: Radeon RX 560 Series (POLARIS11 / DRM 3.23.0 / 4.15.0-39-generic, LLVM 6.0.0)

インストール

# ドライバーのインストール
wget --referer=http://support.amd.com https://www2.ati.com/drivers/linux/beta/ubuntu/amdgpu-pro-17.40.2712-510357.tar.xz
tar -Jxvf amdgpu-pro-17.40.2712-510357.tar.xz
cd amdgpu-pro-17.40.2712-510357
chmod u+x ./amdgpu-pro-install
sudo ./amdgpu-pro-install --compute -y

# python,keras等のインストール
sudo apt install python3.7 clinfo
sudo -H pip install -U plaidml-keras plaidbench

GPUが認識されているかどうか確認する

hoge@fuga:~$ clinfo | grep "Device Board Name"
  Device Board Name (AMD)                         Radeon RX 560 Series

plaidml-setup

hoge@fuga:~$ plaidml-setup

PlaidML Setup (0.3.5)

Thanks for using PlaidML!

Some Notes:
  * Bugs and other issues: https://github.com/plaidml/plaidml
  * Questions: https://stackoverflow.com/questions/tagged/plaidml
  * Say hello: https://groups.google.com/forum/#!forum/plaidml-dev
  * PlaidML is licensed under the GNU AGPLv3

Default Config Devices:
   No devices.

Experimental Config Devices:
   llvm_cpu.0 : CPU (LLVM)
   opencl_amd_baffin.0 : Advanced Micro Devices, Inc. Baffin (OpenCL)

Using experimental devices can cause poor performance, crashes, and other nastiness.

Enable experimental device support? (y,n)[n]:y

Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS).
Please choose a default device:

   1 : llvm_cpu.0
   2 : opencl_amd_baffin.0

Default device? (1,2)[1]:2

Selected device:
    opencl_amd_baffin.0

PlaidML sends anonymous usage statistics to help guide improvements.
We'd love your help making it better.

Enable telemetry reporting? (y,n)[y]:n

Almost done. Multiplying some matrices...
Tile code:
  function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }
Whew. That worked.

Save settings to /home/hoge/.plaidml? (y,n)[y]:y
Success!

ベンチマーク

ベンチマーク用のライブラリをインストール

pip install plaidml-keras plaidbench

ベンチマークを計測する(GPU Radeon RX 560 Series (POLARIS11 / DRM 3.23.0 / 4.15.0-39-generic, LLVM 6.0.0))

GPU
hoge@fuga:~$ plaidbench keras mobilenet
Running 1024 examples with mobilenet, batch size 1
INFO:plaidml:Opening device "opencl_amd_baffin.0"
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.6/mobilenet_1_0_224_tf.h5
17227776/17225924 [==============================] - 13s 1us/step
17235968/17225924 [==============================] - 13s 1us/step
Model loaded.
Compiling network...
Warming up ...
Main timing
Example finished, elapsed: 2.88427686691 (compile), 7.65398216248 (execution), 0.00747459195554 (execution per example)
Correctness: PASS, max_error: 1.81299965334e-05, max_abs_error: 6.70552253723e-07, fail_ratio: 0.0

ベンチマークを計測する(CPU AMD Ryzen Threadripper 2950X 16-Core Processor)

CPU
hoge@fuga:~$ plaidbench keras mobilenet
Running 1024 examples with mobilenet, batch size 1
INFO:plaidml:Opening device "llvm_cpu.0"
Model loaded.
Compiling network...
Warming up ...
Main timing
Example finished, elapsed: 4.06161594391 (compile), 139.089559078 (execution), 0.135829647537 (execution per example)
Correctness: PASS, max_error: 1.7511049009e-05, max_abs_error: 6.55651092529e-07, fail_ratio: 0.0

GPUでは,コンパイル時間が約71%,実行時間が約6%になった

参考文献

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5