10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-11-28

TL;DR

  1. Dockerfileからpythonが実行できるイメージを作成
  2. コンテナを起動して,PlaidMLをセットアップ
  3. Pycharm Proからssh接続(Community Editionはssh接続できません)

環境

ホスト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)

前提条件

事前にDockerをインストールしている必要があります.

Dockerfileからpythonが実行できるイメージを作成

Dockerfile
FROM rastasheep/ubuntu-sshd:16.04

RUN apt-get update && apt-get install -y build-essential wget make libffi-dev mesa-opencl-icd clinfo openssh-server
RUN apt-get install -y checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev zlib1g-dev openssl libffi-dev python3-dev python3-setuptools wget

# python3.7のインストール
RUN wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz && \
    tar -xzf Python-3.7.1.tgz && \
    cd Python-3.7.1 && \
    ./configure && \
    make && \
    make install

# 使用するpythonのライブラリをインストール(事前にホスト側でrequirements.txtを用意)
ADD requirements.txt /
RUN pip3 install -r /requirements.txt

# kerasの設定(事前にホスト側でdocker-keras.json用意)
ADD docker-keras.json /
RUN mkdir ~/.keras && cat /docker-keras.json > ~/.keras/keras.json

# amdgpu-proのインストール
RUN 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 && \
    ./amdgpu-pro-install --compute -y

# sshのためにパスワードを設定する
RUN echo 'root:root' | chpasswd
requirements.txt(事前にホスト側で用意)
keras==2.2.2
plaidml-keras==0.3.5
plaidml==0.3.5
docker-keras.json(事前にホスト側で用意)
{
    "epsilon": 1e-07,
    "floatx": "float32",
    "image_data_format": "channels_last",
    "backend": "plaidml.keras.backend"
}
sudo docker build ./ -t radeon-keras

コンテナを起動して,コンテナ内でPlaidMLをセットアップ

コンテナを起動します.

sudo docker run -itd  --privileged -p 8022:22 --name radeon_keras_container radeon-keras

sshで接続します.

# コンテナのIPアドレスを取得
sudo docker inspect radeon_keras_container
# ssh接続,パスワードは'root'(Dockerfile参照)
ssh root@172.17.0.2

コンテナ内でGPUが認識されているかどうか確認します.

root@5314470cb19b:~# clinfo | grep "Device Board Name"
  Device Board Name (AMD)                         Radeon RX 560 Series

PlaidMLのセットアップします.「Experimental Config Devices:」と尋ねられたら,「opencl_amd_baffin.0」を選択します.

root@5314470cb19b:~# 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:
   opencl_amd_baffin.0 : Advanced Micro Devices, Inc. Baffin (OpenCL)
   llvm_cpu.0 : CPU (LLVM)
   opencl_amd_radeon_rx_560_series_(polaris11_/_drm_3.23.0_/_4.15.0-39-generic,_llvm_6.0.0).0 : AMD Radeon RX 560 Series (POLARIS11 / DRM 3.23.0 / 4.15.0-39-generic, LLVM 6.0.0) (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 : opencl_amd_baffin.0
   2 : llvm_cpu.0
   3 : opencl_amd_radeon_rx_560_series_(polaris11_/_drm_3.23.0_/_4.15.0-39-generic,_llvm_6.0.0).0

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

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 /root/.plaidml? (y,n)[y]:y
Success!

root@5314470cb19b:~# exit
logout
Connection to 172.17.0.2 closed.

Pycharmからssh接続する.

Dockerコンテナを起動して,PycharmのSettings > Project Interpreter > Show All... > + > SSH Interpreterから設定.

Screenshot from 2018-11-29 06-00-03.png

Screenshot from 2018-11-29 06-00-36.png

Screenshot from 2018-11-29 06-12-24.png

参考文献

10
9
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?