PlaidML을 통해 AMD GPU 사용하기 (macOS)
R로 Deep Learning을 macbook의 GPU를 활용해서 분석하기 위한 환경설정.
Miniconda 설치 (reticulate 릍 통해)
https://onesixx.com/miniconda/
가상환경 설치 (ex. sixxDL)
### create new myENV by cloning U> conda create --name sixxDL --clone r-reticulate U> conda activate sixxDL
condaenv 선택 (reticulate 릍 통해)
library(reticulate) myENV='sixxDL' use_condaenv(condaenv=myENV, required=T)
Keras 설치
# (sixxDL) ~$➜ conda upgrade pip # (sixxDL) ~$➜ sudo conda update -n base conda # 설치된 패키지 확인 ~$➜ conda list tensorflow 또는 ~$➜ pip list | grep tensorflow (sixxDL) ~$➜ pip install tensorflow==2.2.0 (sixxDL) ~$➜ pip uninstall keras-preprocessing (sixxDL) ~$➜ pip install keras-preprocessing==1.1.0 (sixxDL) ~$➜ pip install keras==2.2.4 (sixxDL) ~$➜ plaidml-setup
추가 모듈 설치
#library(keras) #install_keras(method="conda") #install_keras(method="conda", version="2.2.4") conda_install(envname=myENV, c("matplotlib","pandas","seaborn","scikit-learn"))
Keras 란
Keras란, High-level neural networks API written in Python
for using TensorFlow, CNTK, or Theano
#install.packages("keras") # 'config', 'tensorflow', 'tfruns', 'zeallot' library(keras)
> install.packages("keras") Installing package into '/home/oschung_skcc/R/x86_64-pc-linux-gnu-library/3.6' (as 'lib' is unspecified) also installing the dependencies 'config', 'tensorflow', 'tfruns', 'zeallot' ....
GPU 버전 설치 (miniconda의 가상환경에 설치)
condadev에 설치하기위해 아래 사용. (miniconda 없으면 먼저 설치하고, r-reticulate 가상환경에 설치됨)
use_condaenv(condaenv='sixxDL', required=T) #cf.> use_python, use_virtualenv, use_miniconda use_python(python="~/.local/share/r-miniconda/envs/sixxDL/bin/python" ) install_keras(method="conda", tensorflow="gpu")
설치후 확인 작업
#.rs.restartR() # cmd+shift+F10 use_condaenv(condaenv='sixxDL', required=T) #cf.> use_python, use_virtualenv, use_miniconda use_python(python="~/.local/share/r-miniconda/envs/sixxDL/bin/python" ) py_config()
> install_keras(method="conda", tensorflow="gpu") Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done ## Package Plan ## environment location: /home/oschung_skcc/.local/share/r-miniconda/envs/sixxDL added / updated specs: - python=3.6 The following packages will be downloaded: package | build ---------------------------|----------------- certifi-2020.6.20 | py36_0 156 KB python-3.6.10 | hcf32534_1 29.7 MB setuptools-49.2.0 | py36_0 748 KB ------------------------------------------------------------ Total: 30.6 MB The following packages will be REMOVED: python_abi-3.8-1_cp38 The following packages will be UPDATED: ca-certificates conda-forge::ca-certificates-2020.6.2~ --> pkgs/main::ca-certificates-2020.6.24-0 The following packages will be SUPERSEDED by a higher-priority channel: certifi conda-forge::certifi-2020.6.20-py38h3~ --> pkgs/main::certifi-2020.6.20-py36_0 openssl conda-forge::openssl-1.1.1g-h516909a_1 --> pkgs/main::openssl-1.1.1g-h7b6447c_0 python conda-forge::python-3.8.5-h4d41432_2_~ --> pkgs/main::python-3.6.10-hcf32534_1 setuptools conda-forge::setuptools-49.2.1-py38h3~ --> pkgs/main::setuptools-49.2.0-py36_0 Downloading and Extracting Packages certifi-2020.6.20 | 156 KB | ########## | 100% python-3.6.10 | 29.7 MB | ########## | 100% setuptools-49.2.0 | 748 KB | ########## | 100% Preparing transaction: ...working... done Verifying transaction: ...working... done Executing transaction: ...working... done Collecting tensorflow-gpu==2.2.0 Downloading tensorflow_gpu-2.2.0-cp36-cp36m-manylinux2010_x86_64.whl (516.2 MB) Collecting keras Downloading Keras-2.4.3-py2.py3-none-any.whl (36 kB) Collecting tensorflow-hub Downloading tensorflow_hub-0.8.0-py2.py3-none-any.whl (101 kB) Collecting h5py Downloading h5py-2.10.0-cp36-cp36m-manylinux1_x86_64.whl (2.9 MB) Collecting pyyaml==3.12 Downloading PyYAML-3.12.tar.gz (253 kB) Collecting requests Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB) Collecting Pillow Downloading Pillow-7.2.0-cp36-cp36m-manylinux1_x86_64.whl (2.2 MB) Collecting scipy Downloading scipy-1.5.2-cp36-cp36m-manylinux1_x86_64.whl (25.9 MB) Collecting astunparse==1.6.3 Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB) Collecting google-pasta>=0.1.8 Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB) Collecting keras-preprocessing>=1.1.0 Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB) Collecting tensorboard<2.3.0,>=2.2.0 Downloading tensorboard-2.2.2-py3-none-any.whl (3.0 MB) Collecting termcolor>=1.1.0 Downloading termcolor-1.1.0.tar.gz (3.9 kB) Collecting six>=1.12.0 Downloading six-1.15.0-py2.py3-none-any.whl (10 kB) Collecting opt-einsum>=2.3.2 Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB) Collecting absl-py>=0.7.0 Downloading absl-py-0.9.0.tar.gz (104 kB) Collecting grpcio>=1.8.6 Downloading grpcio-1.31.0-cp36-cp36m-manylinux2014_x86_64.whl (3.4 MB) Collecting gast==0.3.3 Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB) Collecting protobuf>=3.8.0 Downloading protobuf-3.12.4-cp36-cp36m-manylinux1_x86_64.whl (1.3 MB) Collecting tensorflow-estimator<2.3.0,>=2.2.0 Downloading tensorflow_estimator-2.2.0-py2.py3-none-any.whl (454 kB) Requirement already satisfied, skipping upgrade: wheel>=0.26; python_version >= "3" in /home/oschung_skcc/.local/share/r-miniconda/envs/sixxDL/lib/python3.6/site-packages (from tensorflow-gpu==2.2.0) (0.34.2) Collecting numpy<2.0,>=1.16.0 Downloading numpy-1.19.1-cp36-cp36m-manylinux2010_x86_64.whl (14.5 MB) Collecting wrapt>=1.11.1 Downloading wrapt-1.12.1.tar.gz (27 kB) Collecting idna<3,>=2.5 Downloading idna-2.10-py2.py3-none-any.whl (58 kB) Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 Downloading urllib3-1.25.10-py2.py3-none-any.whl (127 kB) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /home/oschung_skcc/.local/share/r-miniconda/envs/sixxDL/lib/python3.6/site-packages (from requests) (2020.6.20) Collecting chardet<4,>=3.0.2 Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB) Collecting werkzeug>=0.11.15 Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB) Requirement already satisfied, skipping upgrade: setuptools>=41.0.0 in /home/oschung_skcc/.local/share/r-miniconda/envs/sixxDL/lib/python3.6/site-packages (from tensorboard<2.3.0,>=2.2.0->tensorflow-gpu==2.2.0) (49.2.0.post20200714) Collecting google-auth-oauthlib<0.5,>=0.4.1 Downloading google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB) Collecting markdown>=2.6.8 Downloading Markdown-3.2.2-py3-none-any.whl (88 kB) Collecting google-auth<2,>=1.6.3 Downloading google_auth-1.20.0-py2.py3-none-any.whl (91 kB) Collecting tensorboard-plugin-wit>=1.6.0 Downloading tensorboard_plugin_wit-1.7.0-py3-none-any.whl (779 kB) Collecting requests-oauthlib>=0.7.0 Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB) Collecting importlib-metadata; python_version < "3.8" Downloading importlib_metadata-1.7.0-py2.py3-none-any.whl (31 kB) Collecting cachetools<5.0,>=2.0.0 Downloading cachetools-4.1.1-py3-none-any.whl (10 kB) Collecting pyasn1-modules>=0.2.1 Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB) Collecting rsa<5,>=3.1.4; python_version >= "3.5" Downloading rsa-4.6-py3-none-any.whl (47 kB) Collecting oauthlib>=3.0.0 Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB) Collecting zipp>=0.5 Downloading zipp-3.1.0-py3-none-any.whl (4.9 kB) Collecting pyasn1<0.5.0,>=0.4.6 Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB) Building wheels for collected packages: pyyaml, termcolor, absl-py, wrapt Building wheel for pyyaml (setup.py): started Building wheel for pyyaml (setup.py): finished with status 'done' Created wheel for pyyaml: filename=PyYAML-3.12-cp36-cp36m-linux_x86_64.whl size=43058 sha256=45b3408336f39c507fb9adf0c315b9207c17a175b68574df5a2dbaadb2aa1bbd Stored in directory: /home/oschung_skcc/.cache/pip/wheels/40/06/c3/a48dc77c7d8f60b64eaf0fffd5ee5ab8abce5d13893b73109b Building wheel for termcolor (setup.py): started Building wheel for termcolor (setup.py): finished with status 'done' Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4830 sha256=0d0066fbd9c799fceafe5b1cb4d56401073038bda6fcddd5c56d6739596d64c8 Stored in directory: /home/oschung_skcc/.cache/pip/wheels/93/2a/eb/e58dbcbc963549ee4f065ff80a59f274cc7210b6eab962acdc Building wheel for absl-py (setup.py): started Building wheel for absl-py (setup.py): finished with status 'done' Created wheel for absl-py: filename=absl_py-0.9.0-py3-none-any.whl size=121931 sha256=9a43044398ebd2078b7713cac330118bcce02aac04f9a3a07a9a286b49689d7e Stored in directory: /home/oschung_skcc/.cache/pip/wheels/c3/af/84/3962a6af7b4ab336e951b7877dcfb758cf94548bb1771e0679 Building wheel for wrapt (setup.py): started Building wheel for wrapt (setup.py): finished with status 'done' Created wheel for wrapt: filename=wrapt-1.12.1-cp36-cp36m-linux_x86_64.whl size=69791 sha256=3f52189b8c53754c6004277272bae334624efee34b1ccfbcdf3be260e7cc31a9 Stored in directory: /home/oschung_skcc/.cache/pip/wheels/32/42/7f/23cae9ff6ef66798d00dc5d659088e57dbba01566f6c60db63 Successfully built pyyaml termcolor absl-py wrapt Installing collected packages: six, astunparse, google-pasta, numpy, keras-preprocessing, absl-py, werkzeug, protobuf, idna, urllib3, chardet, requests, oauthlib, requests-oauthlib, cachetools, pyasn1, pyasn1-modules, rsa, google-auth, google-auth-oauthlib, grpcio, zipp, importlib-metadata, markdown, tensorboard-plugin-wit, tensorboard, scipy, termcolor, h5py, opt-einsum, gast, tensorflow-estimator, wrapt, tensorflow-gpu, pyyaml, keras, tensorflow-hub, Pillow ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts. We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default. tensorflow-gpu 2.2.0 requires scipy==1.4.1; python_version >= "3", but you'll have scipy 1.5.2 which is incompatible. Successfully installed Pillow-7.2.0 absl-py-0.9.0 astunparse-1.6.3 cachetools-4.1.1 chardet-3.0.4 gast-0.3.3 google-auth-1.20.0 google-auth-oauthlib-0.4.1 google-pasta-0.2.0 grpcio-1.31.0 h5py-2.10.0 idna-2.10 importlib-metadata-1.7.0 keras-2.4.3 keras-preprocessing-1.1.2 markdown-3.2.2 numpy-1.19.1 oauthlib-3.1.0 opt-einsum-3.3.0 protobuf-3.12.4 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyyaml-3.12 requests-2.24.0 requests-oauthlib-1.3.0 rsa-4.6 scipy-1.5.2 six-1.15.0 tensorboard-2.2.2 tensorboard-plugin-wit-1.7.0 tensorflow-estimator-2.2.0 tensorflow-gpu-2.2.0 tensorflow-hub-0.8.0 termcolor-1.1.0 urllib3-1.25.10 werkzeug-1.0.1 wrapt-1.12.1 zipp-3.1.0 Installation complete. Restarting R session...
CPU버전 설치
install_keras()
Collecting tensorflow==2.0.0 Using cached tensorflow-2.0.0-cp36-cp36m-macosx_10_11_x86_64.whl (102.7 MB) Collecting keras Using cached Keras-2.3.1-py2.py3-none-any.whl (377 kB) Collecting tensorflow-hub Using cached tensorflow_hub-0.8.0-py2.py3-none-any.whl (101 kB) Collecting h5py Using cached h5py-2.10.0-cp36-cp36m-macosx_10_6_intel.whl (3.0 MB) Processing /Users/onesixx/Library/Caches/pip/wheels/e5/9d/ad/2ee53cf262cba1ffd8afe1487eef788ea3f260b7e6232a80fc/PyYAML-5.3.1-cp36-cp36m-macosx_10_9_x86_64.whl Collecting requests Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB) Collecting Pillow Using cached Pillow-7.1.1-cp36-cp36m-macosx_10_10_x86_64.whl (2.2 MB) Collecting scipy Using cached scipy-1.4.1-cp36-cp36m-macosx_10_6_intel.whl (28.5 MB) Requirement already satisfied, skipping upgrade: six>=1.10.0 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.14.0) Processing /Users/onesixx/Library/Caches/pip/wheels/c3/af/84/3962a6af7b4ab336e951b7877dcfb758cf94548bb1771e0679/absl_py-0.9.0-py3-none-any.whl Collecting keras-preprocessing>=1.0.5 Using cached Keras_Preprocessing-1.1.0-py2.py3-none-any.whl (41 kB) Collecting google-pasta>=0.1.6 Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB) Processing /Users/onesixx/Library/Caches/pip/wheels/93/2a/eb/e58dbcbc963549ee4f065ff80a59f274cc7210b6eab962acdc/termcolor-1.1.0-py3-none-any.whl Processing /Users/onesixx/Library/Caches/pip/wheels/32/42/7f/23cae9ff6ef66798d00dc5d659088e57dbba01566f6c60db63/wrapt-1.12.1-cp36-cp36m-macosx_10_9_x86_64.whl Requirement already satisfied, skipping upgrade: wheel>=0.26 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from tensorflow==2.0.0) (0.34.2) Processing /Users/onesixx/Library/Caches/pip/wheels/19/a7/b9/0740c7a3a7d1d348f04823339274b90de25fbcd217b2ee1fbe/gast-0.2.2-py3-none-any.whl Collecting protobuf>=3.6.1 Using cached protobuf-3.11.3-cp36-cp36m-macosx_10_9_x86_64.whl (1.3 MB) Collecting tensorboard<2.1.0,>=2.0.0 Using cached tensorboard-2.0.2-py3-none-any.whl (3.8 MB) Collecting grpcio>=1.8.6 Using cached grpcio-1.28.1-cp36-cp36m-macosx_10_9_x86_64.whl (2.6 MB) Requirement already satisfied, skipping upgrade: numpy<2.0,>=1.16.0 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from tensorflow==2.0.0) (1.18.1) Collecting opt-einsum>=2.3.2 Using cached opt_einsum-3.2.1-py3-none-any.whl (63 kB) Collecting keras-applications>=1.0.8 Using cached Keras_Applications-1.0.8-py3-none-any.whl (50 kB) Collecting tensorflow-estimator<2.1.0,>=2.0.0 Using cached tensorflow_estimator-2.0.1-py2.py3-none-any.whl (449 kB) Collecting astor>=0.6.0 Using cached astor-0.8.1-py2.py3-none-any.whl (27 kB) Collecting idna<3,>=2.5 Using cached idna-2.9-py2.py3-none-any.whl (58 kB) Collecting chardet<4,>=3.0.2 Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from requests) (2020.4.5.1) Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB) Requirement already satisfied, skipping upgrade: setuptools in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==2.0.0) (46.1.3.post20200330) Collecting google-auth<2,>=1.6.3 Using cached google_auth-1.14.1-py2.py3-none-any.whl (89 kB) Collecting google-auth-oauthlib<0.5,>=0.4.1 Using cached google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB) Collecting werkzeug>=0.11.15 Using cached Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB) Collecting markdown>=2.6.8 Using cached Markdown-3.2.1-py2.py3-none-any.whl (88 kB) Collecting rsa<4.1,>=3.1.4 Using cached rsa-4.0-py2.py3-none-any.whl (38 kB) Collecting cachetools<5.0,>=2.0.0 Using cached cachetools-4.1.0-py3-none-any.whl (10 kB) Collecting pyasn1-modules>=0.2.1 Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB) Collecting requests-oauthlib>=0.7.0 Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB) Collecting pyasn1>=0.1.3 Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB) Collecting oauthlib>=3.0.0 Using cached oauthlib-3.1.0-py2.py3-none-any.whl (147 kB) Installing collected packages: absl-py, keras-preprocessing, google-pasta, termcolor, wrapt, gast, protobuf, pyasn1, rsa, cachetools, pyasn1-modules, google-auth, idna, chardet, urllib3, requests, oauthlib, requests-oauthlib, google-auth-oauthlib, werkzeug, grpcio, markdown, tensorboard, opt-einsum, h5py, keras-applications, tensorflow-estimator, astor, tensorflow, scipy, pyyaml, keras, tensorflow-hub, Pillow Successfully installed Pillow-7.1.1 absl-py-0.9.0 astor-0.8.1 cachetools-4.1.0 chardet-3.0.4 gast-0.2.2 google-auth-1.14.1 google-auth-oauthlib-0.4.1 google-pasta-0.2.0 grpcio-1.28.1 h5py-2.10.0 idna-2.9 keras-2.3.1 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 oauthlib-3.1.0 opt-einsum-3.2.1 protobuf-3.11.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyyaml-5.3.1 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 tensorboard-2.0.2 tensorflow-2.0.0 tensorflow-estimator-2.0.1 tensorflow-hub-0.8.0 termcolor-1.1.0 urllib3-1.25.9 werkzeug-1.0.1 wrapt-1.12.1 Installation complete. Restarting R session...
plaidML (an OpenCL compatible backend)
https://github.com/plaidml/plaidml/
https://plaidml.github.io/plaidml/docs/install.html
https://rpubs.com/siero5335/399690 – Install Keras and PlaidML
https://towardsdatascience.com/deep-learning-using-gpu-on-your-macbook-c9becba7c43
https://tree.rocks/python/mac-amd-gpu-keras-accelerate/
https://keras.rstudio.com/articles/faq.html#how-can-i-use-the-plaidml-backend
https://community.rstudio.com/t/reticulate-1-14-together-with-miniconda3-and-tensorflow-not-working/49180/3
macos 설정 확인
https://onesixx.com/opencl/
~$➜ brew install clinfo ~$➜ clinfo Number of platforms 1 Platform Name Apple Platform Vendor Apple Platform Version OpenCL 1.2 (Jun 8 2020 17:36:15) Platform Profile FULL_PROFILE Platform Extensions cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event Platform Name Apple Number of devices 3 Device Name Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz Device Vendor Intel Device Vendor ID 0xffffffff Device Version OpenCL 1.2 Driver Version 1.1 Device OpenCL C Version OpenCL C 1.2 Device Type CPU Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 8 Max clock frequency 3100MHz Device Partition (core) Max number of sub-devices 0 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 1024x1x1 Max work group size 1024 Preferred work group size multiple 1 Preferred / native vector sizes char 16 / 16 short 8 / 8 int 4 / 4 long 2 / 2 half 0 / 0 (n/a) float 4 / 4 double 2 / 2 (cl_khr_fp64) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Correctly-rounded divide and sqrt operations Yes Double-precision Floating-point support (cl_khr_fp64) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Address bits 64, Little-Endian Global memory size 17179869184 (16GiB) Error Correction support No Max memory allocation 4294967296 (4GiB) Unified memory for Host and Device Yes Minimum alignment for any data type 128 bytes Alignment of base address 1024 bits (128 bytes) Global Memory cache type Read/Write Global Memory cache size 64 Global Memory cache line size 8388608 bytes Image support Yes Max number of samplers per kernel 16 Max size for 1D images from buffer 65536 pixels Max 1D or 2D image array size 2048 images Base address alignment for 2D image buffers 1 bytes Pitch alignment for 2D image buffers 1 pixels Max 2D image size 8192x8192 pixels Max 3D image size 2048x2048x2048 pixels Max number of read image args 128 Max number of write image args 8 Local memory type Global Local memory size 32768 (32KiB) Max number of constant args 8 Max constant buffer size 65536 (64KiB) Max size of kernel argument 4096 (4KiB) Queue properties Out-of-order execution No Profiling Yes Prefer user sync for interop Yes Profiling timer resolution 1ns Execution capabilities Run OpenCL kernels Yes Run native kernels Yes printf() buffer size 1048576 (1024KiB) Built-in kernels (n/a) Device Extensions cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_image2d_from_buffer cl_APPLE_fp64_basic_ops cl_APPLE_fixed_alpha_channel_orders cl_APPLE_biased_fixed_point_image_formats cl_APPLE_command_queue_priority Device Name Intel(R) HD Graphics 630 Device Vendor Intel Inc. Device Vendor ID 0x1024500 Device Version OpenCL 1.2 Driver Version 1.2(Jul 6 2020 11:56:19) Device OpenCL C Version OpenCL C 1.2 Device Type GPU Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 24 Max clock frequency 1100MHz Device Partition (core) Max number of sub-devices 0 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 256x256x256 Max work group size 256 Preferred work group size multiple 32 Preferred / native vector sizes char 1 / 1 short 1 / 1 int 1 / 1 long 1 / 1 half 0 / 0 (n/a) float 1 / 1 double 0 / 0 (n/a) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Correctly-rounded divide and sqrt operations Yes Double-precision Floating-point support (n/a) Address bits 64, Little-Endian Global memory size 1610612736 (1.5GiB) Error Correction support No Max memory allocation 402653184 (384MiB) Unified memory for Host and Device Yes Minimum alignment for any data type 128 bytes Alignment of base address 1024 bits (128 bytes) Global Memory cache type None Image support Yes Max number of samplers per kernel 16 Max size for 1D images from buffer 25165824 pixels Max 1D or 2D image array size 2048 images Base address alignment for 2D image buffers 4 bytes Pitch alignment for 2D image buffers 32 pixels Max 2D image size 16384x16384 pixels Max 3D image size 2048x2048x2048 pixels Max number of read image args 128 Max number of write image args 8 Local memory type Local Local memory size 65536 (64KiB) Max number of constant args 8 Max constant buffer size 65536 (64KiB) Max size of kernel argument 1024 Queue properties Out-of-order execution No Profiling Yes Prefer user sync for interop Yes Profiling timer resolution 80ns Execution capabilities Run OpenCL kernels Yes Run native kernels No printf() buffer size 1048576 (1024KiB) Built-in kernels (n/a) Device Extensions cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_image2d_from_buffer cl_khr_gl_depth_images cl_khr_depth_images cl_khr_3d_image_writes Device Name AMD Radeon Pro 560 Compute Engine Device Vendor AMD Device Vendor ID 0x1021c00 Device Version OpenCL 1.2 Driver Version 1.2 (Aug 7 2020 15:44:49) Device OpenCL C Version OpenCL C 1.2 Device Type GPU Device Profile FULL_PROFILE Device Available Yes Compiler Available Yes Linker Available Yes Max compute units 16 Max clock frequency 907MHz Device Partition (core) Max number of sub-devices 0 Supported partition types None Supported affinity domains (n/a) Max work item dimensions 3 Max work item sizes 256x256x256 Max work group size 256 Preferred work group size multiple 64 Preferred / native vector sizes char 4 / 4 short 2 / 2 int 1 / 1 long 1 / 1 half 0 / 0 (n/a) float 1 / 1 double 1 / 1 (cl_khr_fp64) Half-precision Floating-point support (n/a) Single-precision Floating-point support (core) Denormals No Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add No Support is emulated in software No Correctly-rounded divide and sqrt operations Yes Double-precision Floating-point support (cl_khr_fp64) Denormals Yes Infinity and NANs Yes Round to nearest Yes Round to zero Yes Round to infinity Yes IEEE754-2008 fused multiply-add Yes Support is emulated in software No Address bits 32, Little-Endian Global memory size 4294967296 (4GiB) Error Correction support No Max memory allocation 1073741824 (1024MiB) Unified memory for Host and Device No Minimum alignment for any data type 128 bytes Alignment of base address 32768 bits (4096 bytes) Global Memory cache type None Image support Yes Max number of samplers per kernel 16 Max size for 1D images from buffer 65536 pixels Max 1D or 2D image array size 2048 images Base address alignment for 2D image buffers 256 bytes Pitch alignment for 2D image buffers 256 pixels Max 2D image size 16384x16384 pixels Max 3D image size 2048x2048x2048 pixels Max number of read image args 128 Max number of write image args 8 Local memory type Local Local memory size 32768 (32KiB) Max number of constant args 8 Max constant buffer size 65536 (64KiB) Max size of kernel argument 1024 Queue properties Out-of-order execution No Profiling Yes Prefer user sync for interop Yes Profiling timer resolution 40ns Execution capabilities Run OpenCL kernels Yes Run native kernels No printf() buffer size 134217728 (128MiB) Built-in kernels (n/a) Device Extensions cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_image2d_from_buffer cl_khr_depth_images cl_APPLE_command_queue_priority cl_APPLE_command_queue_select_compute_units cl_khr_fp64 NULL platform behavior clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) Apple clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [P0] clCreateContext(NULL, ...) [default] Success [P0] clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) Success (2) Platform Name Apple Device Name Intel(R) HD Graphics 630 Device Name AMD Radeon Pro 560 Compute Engine clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) Success (1) Platform Name Apple Device Name Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (2) Platform Name Apple Device Name Intel(R) HD Graphics 630 Device Name AMD Radeon Pro 560 Compute Engine clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) Invalid device type for platform clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (3) Platform Name Apple Device Name Intel(R) HD Graphics 630 Device Name AMD Radeon Pro 560 Compute Engine Device Name Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz \tNOTE:\tyour OpenCL library only supports OpenCL 1.0, \t\tbut some installed platforms support OpenCL 1.2. \t\tPrograms using 1.2 features may crash \t\tor behave unexpectedly
PlaidML 설치
|➜ pip install -U plaidml-keras Collecting plaidml-keras Using cached plaidml_keras-0.7.0-py2.py3-none-any.whl (19 kB) Collecting plaidml Using cached plaidml-0.7.0-py2.py3-none-macosx_10_10_x86_64.whl (17.8 MB) Requirement already satisfied, skipping upgrade: six in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml-keras) (1.14.0) Collecting keras==2.2.4 Using cached Keras-2.2.4-py2.py3-none-any.whl (312 kB) Collecting cffi Using cached cffi-1.14.0-cp36-cp36m-macosx_10_9_x86_64.whl (174 kB) Requirement already satisfied, skipping upgrade: numpy in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml->plaidml-keras) (1.18.1) Collecting enum34>=1.1.6 Using cached enum34-1.1.10-py3-none-any.whl (11 kB) Requirement already satisfied, skipping upgrade: pyyaml in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (5.3.1) Requirement already satisfied, skipping upgrade: h5py in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (2.10.0) Requirement already satisfied, skipping upgrade: scipy>=0.14 in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.4.1) Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.1.0) Requirement already satisfied, skipping upgrade: keras-applications>=1.0.6 in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.0.8) Collecting pycparser Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB) Installing collected packages: pycparser, cffi, enum34, plaidml, keras, plaidml-keras Attempting uninstall: keras Found existing installation: Keras 2.3.1 Uninstalling Keras-2.3.1: Successfully uninstalled Keras-2.3.1 Successfully installed cffi-1.14.0 enum34-1.1.10 keras-2.2.4 plaidml-0.7.0 plaidml-keras-0.7.0 pycparser-2.20 onesixx:~|➜ conda list keras # packages in environment at /Users/onesixx/Library/r-miniconda/envs/r-reticulate: # # Name Version Build Channel keras 2.2.4 pypi_0 pypi keras-applications 1.0.8 pypi_0 pypi keras-preprocessing 1.1.0 pypi_0 pypi plaidml-keras 0.7.0 pypi_0 pypi
PlaidML 설정
PlaidML라이브러리가 Metal(OpenCL)을 통해 Keras의 backend를 책임질 수 있게 설정
|➜ plaidml-setup n 3 : metal_amd_radeon_pro_560.0 y
PlaidML Setup (0.7.0) Thanks for using PlaidML! The feedback we have received from our users indicates an ever-increasing need for performance, programmability, and portability. During the past few months, we have been restructuring PlaidML to address those needs. To make all the changes we need to make while supporting our current user base, all development of PlaidML has moved to a branch — plaidml-v1. We will continue to maintain and support the master branch of PlaidML and the stable 0.7.0 release. Read more here: https://github.com/plaidml/plaidml Some Notes: * Bugs and other issues: https://github.com/plaidml/plaidml/issues * Questions: https://stackoverflow.com/questions/tagged/plaidml * Say hello: https://groups.google.com/forum/#!forum/plaidml-dev * PlaidML is licensed under the Apache License 2.0
experimental device는 굳이 enable하지 않고,
3 : metal_amd_radeon_pro_560.0 으로 default device 설정 후
해당 설정은 ~/.plaidml 에 저장
Default Config Devices: llvm_cpu.0 : CPU (via LLVM) metal_intel(r)_hd_graphics_630.0 : Intel(R) HD Graphics 630 (Metal) metal_amd_radeon_pro_560.0 : AMD Radeon Pro 560 (Metal) Experimental Config Devices: llvm_cpu.0 : CPU (via LLVM) opencl_amd_radeon_pro_560_compute_engine.0 : AMD AMD Radeon Pro 560 Compute Engine (OpenCL) opencl_intel_hd_graphics_630.0 : Intel Inc. Intel(R) HD Graphics 630 (OpenCL) metal_intel(r)_hd_graphics_630.0 : Intel(R) HD Graphics 630 (Metal) metal_amd_radeon_pro_560.0 : AMD Radeon Pro 560 (Metal) Using experimental devices can cause poor performance, crashes, and other nastiness. Enable experimental device support? (y,n)[n]:n Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS). Please choose a default device: 1 : llvm_cpu.0 2 : metal_intel(r)_hd_graphics_630.0 3 : metal_amd_radeon_pro_560.0 Default device? (1,2,3)[1]:3 Selected device: metal_amd_radeon_pro_560.0 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 /Users/onesixx/.plaidml? (y,n)[y]:y Success!
|➜ subl ~/.plaidml
{ "PLAIDML_DEVICE_IDS":[ "metal_amd_radeon_pro_560.0" ], "PLAIDML_EXPERIMENTAL":false }
테스트
MobileNet in plaidbench를 설치하고, 이를 활용하여 TEST한다.
|➜ pip install plaidml-keras plaidbench
Requirement already satisfied: plaidml-keras in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (0.7.0) Collecting plaidbench Using cached plaidbench-0.7.0-py2.py3-none-any.whl (10.1 MB) Requirement already satisfied: six in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml-keras) (1.14.0) Requirement already satisfied: keras==2.2.4 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml-keras) (2.2.4) Requirement already satisfied: plaidml in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml-keras) (0.7.0) Requirement already satisfied: enum34>=1.1.6 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidbench) (1.1.10) Collecting click>=6.0.0 Using cached click-7.1.1-py2.py3-none-any.whl (82 kB) Collecting colorama Using cached colorama-0.4.3-py2.py3-none-any.whl (15 kB) Requirement already satisfied: numpy in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidbench)(1.18.1) Requirement already satisfied: h5py>=2.7.0 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidbench) (2.10.0) Requirement already satisfied: keras-preprocessing>=1.0.5 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.1.0) Requirement already satisfied: scipy>=0.14 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.4.1) Requirement already satisfied: pyyaml in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (5.3.1) Requirement already satisfied: keras-applications>=1.0.6 in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from keras==2.2.4->plaidml-keras) (1.0.8) Requirement already satisfied: cffi in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from plaidml->plaidml-keras) (1.14.0) Requirement already satisfied: pycparser in /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (from cffi->plaidml->plaidml-keras) (2.20) Installing collected packages: click, colorama, plaidbench Successfully installed click-7.1.1 colorama-0.4.3 plaidbench-0.7.0
|➜ plaidbench keras mobilenet
Running 1024 examples with mobilenet, batch size 1, on backend plaid INFO:plaidml:Opening device "metal_amd_radeon_pro_560.0" Compiling network... Warming up... Running... Example finished, elapsed: 0.494s (compile), 8.796s (execution) ----------------------------------------------------------------------------------------- Network Name Inference Latency Time / FPS ----------------------------------------------------------------------------------------- mobilenet 8.59 ms 0.00 ms / 1000000000.00 fps Correctness: PASS, max_error: 1.675534622336272e-05, max_abs_error: 7.674098014831543e-07, fail_ratio: 0.0
Activity Monitor로 GPU사용 확인
Windows – GPU history ( cmd+4 )
(Mac용 활성 상태 보기 앱> 윈도우 > GPU 기록)
GPU사용 환경 확인 in R
library(reticulate) py_config() #use_condaenv(condaenv="r-reticulate", required=TRUE) # use_python use_miniconda(condaenv="r-reticulate", required=TRUE) conda_list()
> py_config() python: /Users/onesixx/Library/r-miniconda/envs/r-reticulate/bin/python libpython: /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/libpython3.6m.dylib pythonhome: /Users/onesixx/Library/r-miniconda/envs/r-reticulate:/Users/onesixx/Library/r-miniconda/envs/r-reticulate version: 3.6.10 |Anaconda, Inc.| (default, Mar 25 2020, 18:53:43) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] numpy: /Users/onesixx/Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/numpy numpy_version: 1.18.1 > conda_list() name python 1 r-miniconda /Users/onesixx/Library/r-miniconda/bin/python 2 r-reticulate /Users/onesixx/Library/r-miniconda/envs/r-reticulate/bin/python
library(tensorflow) library(keras) tf_config() is_keras_available() use_backend(backend="plaidml") # Set PlaidML as backend
> tf_config() TensorFlow v2.0.0 () Python v3.6 (~/Library/r-miniconda/envs/r-reticulate/bin/python) > is_keras_available() [1] TRUE
TEST using mnist_cnn
https://rpubs.com/siero5335/399690
https://onesixx.com/tutorial-started-with-keras/
library(reticulate) library(tensorflow) library(keras) use_miniconda(condaenv="r-reticulate", required=TRUE) use_backend(backend="plaidml")
ex)
library(reticulate) library(tensorflow) library(keras) use_miniconda(condaenv="r-reticulate", required=TRUE) use_backend(backend="plaidml") # Set Parameter ---------------------------------------------------------------- batch_size <- 128 num_classes <- 10 epochs <- 5 img_rows <- 28 img_cols <- 28 # Load Data & set train/test --------------------------------------------------- mnist <- dataset_mnist() x_train <- mnist$train$x y_train <- mnist$train$y x_test <- mnist$test$x y_test <- mnist$test$y # reshape - Image Flatten ------------------------------------------------------ x_train <- array_reshape(x_train, c(nrow(x_train), img_rows, img_cols, 1)) x_test <- array_reshape(x_test, c(nrow(x_test), img_rows, img_cols, 1)) input_shape <- c(img_rows, img_cols, 1) # rescale - convert the grayscale values --------------------------------------- x_train <- x_train / 255 x_test <- x_test / 255 # Prepare Y data for training ------------------------------------------------- y_train <- to_categorical(y_train, 10) y_test <- to_categorical(y_test, 10) # Defining the Model : CNN ----------------------------------------------------- model <- keras_model_sequential() %>% layer_conv_2d(filters=32, kernel_size=c(3,3), activation='relu', input_shape=input_shape) %>% layer_conv_2d(filters=64, kernel_size=c(3,3), activation='relu') %>% layer_max_pooling_2d(pool_size=c(2, 2)) %>% layer_dropout(rate=0.25) %>% layer_flatten() %>% layer_dense(units=128, activation='relu') %>% layer_dropout(rate=0.5) %>% layer_dense(units=num_classes, activation='softmax') model %>% summary() # compile the model ------------------------------------------------------------ model %>% compile( loss = loss_categorical_crossentropy, optimizer = optimizer_adadelta(), metrics = c('accuracy') ) # Fitting - Training and Evaluation -------------------------------------------- # **** Train model using plaidml (GPU) **** ------------------------------------ model %>% fit( x_train, y_train, batch_size = batch_size, epochs = epochs, validation_split = 0.2 )
thank you very much. It worked for me!
감사합니다