PythonでCUDA/GPU利用の確認

CentOS7.8、CUDA9.1で確認

① cupyのインスト
② cupy-cuda91のインスト(CUDAのバージョンによって異なる)
③ サンプルスクリプトの実行

[hoge@hogehoge ~]$ pip install –user cupy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting cupy
Using cached cupy-7.1.1.tar.gz (3.7 MB)
Collecting numpy>=1.9.0
Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
|????????????????????????????????| 17.0 MB 10.4 MB/s
Requirement already satisfied: six>=1.9.0 in /usr/lib/python2.7/site-packages (from cupy) (1.9.0)
Collecting fastrlock>=0.3
Downloading fastrlock-0.5-cp27-cp27mu-manylinux1_x86_64.whl (31 kB)
Using legacy ‘setup.py install’ for cupy, since package ‘wheel’ is not installed.
Installing collected packages: numpy, fastrlock, cupy
Running setup.py install for cupy … done
Successfully installed cupy-7.1.1 fastrlock-0.5 numpy-1.16.6
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$ pip install –user cupy-cuda91
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting cupy-cuda91
Downloading cupy_cuda91-6.7.0-cp27-cp27mu-manylinux1_x86_64.whl (306.0 MB)
|????????????????????????????????| 306.0 MB 24 kB/s
Requirement already satisfied: numpy>=1.9.0 in ./.local/lib/python2.7/site-packages (from cupy-cuda91) (1.16.6)
Requirement already satisfied: fastrlock>=0.3 in ./.local/lib/python2.7/site-packages (from cupy-cuda91) (0.5)
Requirement already satisfied: six>=1.9.0 in /usr/lib/python2.7/site-packages (from cupy-cuda91) (1.9.0)
Installing collected packages: cupy-cuda91
Successfully installed cupy-cuda91-6.7.0
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$ pip freeze
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
backports.ssl-match-hostname==3.5.0.1
blivet==0.61.15.75
Brlapi==0.6.0
chardet==2.2.1
configobj==4.7.2
coverage==3.6b3
cupshelpers==1.0
cupy==7.1.1
cupy-cuda91==6.7.0
decorator==3.4.0
di==0.3
ethtool==0.8
fastrlock==0.5
firstboot==19.5
fros==1.0
futures==3.1.1
iniparse==0.4
initial-setup==0.3.9.45
iotop==0.6
ipaddress==1.0.16
IPy==0.75
javapackages==1.0.0
kitchen==1.1.1
langtable==0.0.31
lxml==3.2.1
ntplib==0.3.2
numpy==1.16.6
perf==0.1
policycoreutils-default-encoding==0.1
pycups==1.9.63
pycurl==7.19.0
pygobject==3.22.0
pygpgme==0.3
pyinotify==0.9.4
pykickstart==1.99.66.21
pyliblzma==0.5.3
pyparted==3.9
pysmbc==1.0.13
python-augeas==0.5.0
python-linux-procfs==0.4.9
python-meh==0.25.3
python-nss==0.16.0
pytz==2016.10
pyudev==0.15
pyxattr==0.5.1
PyYAML==3.10
schedutils==0.4
seobject==0.1
sepolicy==1.1
setroubleshoot==1.1
six==1.9.0
slip==0.4.0
slip.dbus==0.4.0
somepackage==1.2.3
subprocess32==3.2.6
urlgrabber==3.10
yum-langpacks==0.4.2
yum-metadata-parser==1.1.4
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$ cat cupy91.py ←サンプルプログラム
import cupy as cp
import time

A = cp.arange(9).reshape(3, 3).astype(‘f’)
B = cp.arange(9).reshape(3, 3).astype(‘f’)
print(‘A = \n’, A)
print(‘B = \n’, B)

time.sleep(300)
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$
[hoge@hogehoge ~]$ python cupy91.py
(‘A = \n’, array([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]], dtype=float32))
(‘B = \n’, array([[0., 1., 2.],
[3., 4., 5.],
[6., 7., 8.]], dtype=float32))
[hoge@hogehoge ~]$

[hoge@hogehoge ~]# nvidia-smi
Fri Oct 30 08:31:07 2020
+—————————————————————————–+
| NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.0 |
|——————————-+———————-+———————-+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Quadro RTX 6000 Off | 00000000:37:00.0 Off | Off |
| 34% 47C P2 64W / 260W | 626MiB / 24217MiB | 0% Default |
| | | N/A |
+——————————-+———————-+———————-+
>
+—————————————————————————–+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 15506 C python 175MiB |
| 0 N/A N/A 17587 G /usr/bin/X 64MiB |
| 0 N/A N/A 17675 G /usr/bin/gnome-shell 12MiB |
| 0 N/A N/A 31205 C …R2019b/bin/glnxa64/MATLAB 369MiB |
+—————————————————————————–+
[hoge@hogehoge ~]#