HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2019/10/12

Raspberry Pi 3で GPGPU py-videocoreを動かしてみるテスト Raspberry Pi 3で GPGPU py-videocoreを動かしてみるテスト

(Raspberry Pi 3で GPUを使用した演算ライブラリを動かしてみるテスト、ビルドするだけ)

Tags: [Raspberry Pi], [電子工作], [ディープラーニング]




● Raspberry Pi 3で GPGPU py-videocoreを動かしてみるテスト

Raspberry PiでGPGPU

nineties/py-videocore

● GPGPUとは?
GPGPU - Wikipedia
 GPGPU(General-purpose computing on graphics processing units; GPUによる汎用計算)とは、GPUの演算資源を画像処理以外の目的に応用する技術のことである

● GPGPU py-videocoreのインストール方法

 py-videocoreの Gitの公式手順通りに行なえば良いが Python 2系だと文字列処理の Unicodeでエラーが出る。
 ※ Python 2はもう時代遅れだから特に理由が無い限り使わない方が良いです。

# お決まりの sudo apt-get update
sudo apt-get update

# GPUの使用メモリを 128MBにする
sudo raspi-config nonint do_memory_split 128

# GPUのファームウェアをアップデートする
sudo rpi-update

# 再起動する
sudo reboot

● Python 2系に py-videocore GPGPUをインストール
# Python 2.7にインストール
# rpi-vcsmをビルドする
cd
git clone https://github.com/Idein/rpi-vcsm.git
cd /rpi-vcsm
pip install -r requirements.txt
# sudoを付ける
sudo python setup.py install

sudo pip install nose
Requirement already satisfied: nose in /usr/lib/python2.7/dist-packages
nosetests -v -s

# test_alloc.test_alloc ... size=0x01e84800
# Got handle:               0x00001000
# Got bus address:          0xfca01000
# Got user virtual address: 0x743dc000
# ok
# Ran 1 test in 0.054s


# py-videocoreをビルドする
cd
git clone https://github.com/nineties/py-videocore.git
cd py-videocore
sudo python setup.py install

# ImportError: No module named ioctl_opt
# ERROR: Failure: ImportError (No module named ioctl_opt)
sudo pip install ioctl_opt

sudo python examples/hello_world.py

# ====================================== a =======================================
# [ 0.09550926  0.06157777  0.33552986  0.20879871  0.76467568  0.0567187
#   0.2239961   0.70769143  0.89694625  0.17859548  0.33774614  0.07542561
#   0.59062463  0.89705694  0.80400401  0.43503112]
# ====================================== b =======================================
# [ 0.45032692  0.76187927  0.15575893  0.9705568   0.8624804   0.72089052
#   0.24694943  0.43457165  0.56043392  0.57559961  0.80636567  0.92991167
#   0.36385882  0.6477505   0.64253622  0.75419736]
# ===================================== a+b ======================================
# [ 0.54583615  0.823457    0.49128878  1.1793555   1.62715602  0.77760917
#   0.47094554  1.14226305  1.45738018  0.75419509  1.14411175  1.00533724
#   0.95448345  1.54480743  1.44654024  1.18922842]
# ==================================== error =====================================
# [  5.96046448e-08   5.96046448e-08   0.00000000e+00   0.00000000e+00
#    0.00000000e+00   5.96046448e-08   0.00000000e+00   0.00000000e+00
#    0.00000000e+00   0.00000000e+00   1.19209290e-07   0.00000000e+00
#    0.00000000e+00   0.00000000e+00   0.00000000e+00   1.19209290e-07]

sudo nosetests -v
# TypeError: unicode argument expected, got 'str'
# Ran 95 tests in 8.779s
# FAILED (errors=2)

● Python 3に py-videocore GPGPUをインストール
# Python 3.5にインストール
# pipを pip3
# pythonを python3
sudo apt install python3-pip

# ImportError: No module named 'numpy'
sudo pip3 install numpy

# rpi-vcsmをビルドする
cd
git clone https://github.com/Idein/rpi-vcsm.git
cd /rpi-vcsm
pip3 install -r requirements.txt
# sudoを付ける
sudo python3 setup.py install

sudo pip3 install nose
# Collecting nose

nosetests -v -s

# test_alloc.test_alloc ... size=0x01e84800
# Got handle:               0x00001000
# Got bus address:          0xfca01000
# Got user virtual address: 0x741e7000
# ok
# Ran 1 test in 0.104s


# py-videocoreをビルドする
cd
git clone https://github.com/nineties/py-videocore.git
cd py-videocore
sudo python3 setup.py install

# ImportError: No module named ioctl_opt
# ERROR: Failure: ImportError (No module named ioctl_opt)
sudo pip3 install ioctl_opt

sudo python3 examples/hello_world.py

# ====================================== a =======================================
# [0.13132179 0.55223787 0.5172157  0.8479564  0.7408608  0.01316501
#  0.76502925 0.54789263 0.5151787  0.77505535 0.5502023  0.7974032
#  0.0217595  0.6921781  0.8138592  0.9165716 ]
# ====================================== b =======================================
# [0.08988494 0.90722847 0.15878879 0.8609826  0.34071782 0.6918225
#  0.788849   0.5328154  0.2175739  0.02097949 0.60043126 0.29935727
#  0.2277096  0.5354425  0.9392305  0.8002648 ]
# ===================================== a+b ======================================
# [0.22120672 1.4594663  0.67600447 1.708939   1.0815786  0.7049875
#  1.5538782  1.080708   0.73275256 0.7960348  1.1506336  1.0967604
#  0.2494691  1.2276205  1.7530897  1.7168363 ]
# ==================================== error =====================================
# [0.0000000e+00 0.0000000e+00 5.9604645e-08 1.1920929e-07 0.0000000e+00
#  0.0000000e+00 1.1920929e-07 0.0000000e+00 0.0000000e+00 0.0000000e+00
#  0.0000000e+00 1.1920929e-07 0.0000000e+00 1.1920929e-07 0.0000000e+00
#  1.1920929e-07]

sudo nosetests -v

# Ran 95 tests in 7.638s
# OK

Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l

pi@raspberrypi:~ $ sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17910  100 17910    0     0  14081      0  0:00:01  0:00:01 --:--:-- 14080
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.14.98-v7+
#############################################################
WARNING: 'rpi-update' updates to pre-releases of the linux
kernel tree and Videocore firmware.

'rpi-update' should only be used if there is a specific
reason to do so - for example, a request by a Raspberry Pi
engineer.

DO NOT use 'rpi-update' as part of a regular update process.

##############################################################
Would you like to proceed? (y/N)
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0    211      0 --:--:-- --:--:-- --:--:--   211
100  114M  100  114M    0     0   762k      0  0:02:33  0:02:33 --:--:--  798k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.19.76-v7+
 *** depmod 4.19.76+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 9f816f3392e1c1eae156b99bed94a8a314310999
 *** A reboot is needed to activate the new firmware

pi@raspberrypi:~ $ sudo reboot

Linux raspberrypi 4.19.76-v7+ #1272 SMP Fri Oct 4 14:48:47 BST 2019 armv7l

pi@raspberrypi:~ $ sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Your firmware is already up to date

● Python 2.7 + py-videocore GPGPU
pi@raspberrypi:~/py-videocore $ sudo python examples/hello_world.py
====================================== a =======================================
[ 0.09550926  0.06157777  0.33552986  0.20879871  0.76467568  0.0567187
  0.2239961   0.70769143  0.89694625  0.17859548  0.33774614  0.07542561
  0.59062463  0.89705694  0.80400401  0.43503112]
====================================== b =======================================
[ 0.45032692  0.76187927  0.15575893  0.9705568   0.8624804   0.72089052
  0.24694943  0.43457165  0.56043392  0.57559961  0.80636567  0.92991167
  0.36385882  0.6477505   0.64253622  0.75419736]
===================================== a+b ======================================
[ 0.54583615  0.823457    0.49128878  1.1793555   1.62715602  0.77760917
  0.47094554  1.14226305  1.45738018  0.75419509  1.14411175  1.00533724
  0.95448345  1.54480743  1.44654024  1.18922842]
==================================== error =====================================
[  5.96046448e-08   5.96046448e-08   0.00000000e+00   0.00000000e+00
   0.00000000e+00   5.96046448e-08   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   1.19209290e-07   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   1.19209290e-07]

pi@raspberrypi:~/py-videocore $ sudo python examples/sgemm.py
==== sgemm example (96x363 times 363x3072) ====
threads: 12
numpy: 0.3798 sec, 0.5660 Gflops
GPU: 0.0309 sec, 6.9574 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01

pi@raspberrypi:~/py-videocore $ sudo python examples/sgemm_1thread.py
==== sgemm example (96x363 times 363x3072) ====
threads: 1
numpy: 0.1827 sec, 1.1765 Gflops
GPU: 0.2902 sec, 0.7409 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01

pi@raspberrypi:~/py-videocore $ sudo python examples/sgemm_cached.py
==== sgemm example (96x363 times 363x3072) ====
threads: 12
numpy: 0.1245 sec, 1.7270 Gflops
GPU: 0.0320 sec, 6.7151 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01

● Python 3.5 + py-videocore GPGPU
pi@raspberrypi:~/py-videocore $ sudo python3 examples/hello_world.py
====================================== a =======================================
[0.34269547 0.99267775 0.40157902 0.9358803  0.99025863 0.6584293
 0.6922591  0.53420657 0.9273042  0.76134753 0.420411   0.26351935
 0.311109   0.5584752  0.3618928  0.6188871 ]
====================================== b =======================================
[0.280316   0.8523227  0.753718   0.91294    0.0950773  0.04780851
 0.5121754  0.14201    0.87746185 0.69470865 0.49425608 0.2276722
 0.7659188  0.01047304 0.9416806  0.14164068]
===================================== a+b ======================================
[0.62301147 1.8450004  1.155297   1.8488203  1.0853359  0.7062378
 1.2044344  0.67621654 1.804766   1.4560561  0.91466707 0.49119154
 1.0770278  0.5689482  1.3035734  0.7605278 ]
==================================== error =====================================
[0.0000000e+00 1.1920929e-07 0.0000000e+00 0.0000000e+00 1.1920929e-07
 5.9604645e-08 0.0000000e+00 5.9604645e-08 0.0000000e+00 0.0000000e+00
 0.0000000e+00 2.9802322e-08 0.0000000e+00 0.0000000e+00 0.0000000e+00
 0.0000000e+00]

pi@raspberrypi:~/py-videocore $ sudo python3 examples/sgemm.py
==== sgemm example (96x363 times 363x3072) ====
threads: 12
numpy: 0.5747 sec, 0.3741 Gflops
GPU: 0.0308 sec, 6.9707 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.1553e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0522e+01

# sudoが無くても動く
pi@raspberrypi:~/py-videocore $ python examples/sgemm_1thread.py
==== sgemm example (96x363 times 363x3072) ====
threads: 1
numpy: 0.1832 sec, 1.1737 Gflops
GPU: 0.2901 sec, 0.7411 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01

pi@raspberrypi:~/py-videocore $ sudo python examples/sgemm_cached.py
==== sgemm example (96x363 times 363x3072) ====
threads: 12
numpy: 0.1322 sec, 1.6259 Gflops
GPU: 0.0327 sec, 6.5708 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01

pi@raspberrypi:~/py-videocore $ python examples/sgemm_cached.py
==== sgemm example (96x363 times 363x3072) ====
threads: 12
numpy: 0.1238 sec, 1.7361 Gflops
GPU: 0.0329 sec, 6.5375 Gflops
minimum absolute error: 0.0000e+00
maximum absolute error: 9.0027e-04
minimum relative error: 0.0000e+00
maximum relative error: 1.0929e+01


● pi-gemm

jetpacapp/pi-gemm

cd
git clone https://github.com/jetpacapp/pi-gemm
cd pi-gemm

sudo apt-get install libatlas-dev m4
make

pi@raspberrypi:~/pi-gemm $ make
g++ -Ofast -DTARGET_PI -march=armv6 -mfloat-abi=hard -ftree-vectorize -funroll-all-loops -mfpu=vfp  -fPIC -c mailbox.cpp -o mailbox.o
g++ -Ofast -DTARGET_PI -march=armv6 -mfloat-abi=hard -ftree-vectorize -funroll-all-loops -mfpu=vfp  -fPIC -c cstring_helpers.cpp -o cstring_helpers.o
g++ -Ofast -DTARGET_PI -march=armv6 -mfloat-abi=hard -ftree-vectorize -funroll-all-loops -mfpu=vfp  -fPIC -c main.cpp -o main.o
g++ -Ofast -DTARGET_PI -march=armv6 -mfloat-abi=hard -ftree-vectorize -funroll-all-loops -mfpu=vfp  -fPIC -c buffer.cpp -o buffer.o
m4 gemm_float.asm | qpu-asm -o gemm_float.cdat -c g_gemm_floatCode
/bin/sh: 1: qpu-asm: not found
Makefile:17: recipe for target 'gemm_float.cdat' failed
make: *** [gemm_float.cdat] Error 127

● qpu-asm
cd
git clone https://github.com/jetpacapp/qpu-asm
cd qpu-asm
make

ls -l
# -rw-r--r-- 1 pi pi   8430 Oct 13 13:51 helpers.asm
# -rw-r--r-- 1 pi pi    127 Oct 13 13:51 Makefile
# -rwxr-xr-x 1 pi pi 322984 Oct 13 13:51 qpu-asm
# -rw-r--r-- 1 pi pi  30552 Oct 13 13:51 qpu-asm.cpp
# -rwxr-xr-x 1 pi pi  30260 Oct 13 13:51 qpu-dis
# -rw-r--r-- 1 pi pi  14117 Oct 13 13:51 qpu-dis.cpp

sudo cp qpu-* /usr/bin/

cd
cd pi-gemm
make

g++ -Ofast -DTARGET_PI -march=armv6 -mfloat-abi=hard -ftree-vectorize -funroll-all-loops -mfpu=vfp  -x c -c gemm_float.cdat -o gemm_float.do
g++ -g -O3 -o gemm ./qpu-asm.o ./mailbox.o ./qpu-dis.o ./cstring_helpers.o ./main.o ./buffer.o gemm_float.do -lblas
./qpu-dis.o: In function `main':
qpu-dis.cpp:(.text.startup+0x0): multiple definition of `main'
./qpu-asm.o:qpu-asm.cpp:(.text.startup+0x0): first defined here
./main.o: In function `main':
main.cpp:(.text.startup+0x0): multiple definition of `main'
./qpu-asm.o:qpu-asm.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'gemm' failed
make: *** [gemm] Error 1
rm gemm_float.cdat



Tags: [Raspberry Pi], [電子工作], [ディープラーニング]



[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2019 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_gpgpu_py_videocore/