Predator's Vision

画像処理、3D点群処理、DeepLearning等の備忘録

Raspberry Pi 4B の GPU で OpenCL (VC4CL)

RaspberryPiの映像出力用のGPUOpenCLから利用できると知ったので、興味本位でトライ。
結果から言うと、行列演算サンプルを実行したところ、GPU処理よりCPU処理の方が若干早かった…。

材料

    • 64bitのつもりだったが32bitのRaspbian入れてた
$ getconf LONG_BIT
32

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

参考サイト

  1. Raspberry PiのGPUをOpenCLで使う方法
  2. Raspberry PiでOpenCLを触ってみた
    • これらのサイトでは Raspberry Pi Zero W や Raspberry Pi 2B で試している
    • また、debパッケージをインストールしているが、私の環境では例のおまじない sudo apt --fix-broken install を実行しても全然ダメだった
    • OpenCLのテスト実行のリポジトリ紹介あり。本記事でも試す。

ビルド&インストール

というわけで、手元で必要物をビルドする。
具体的には下記サイトの"VC4CL installation"のセクションの通り実行する。

確認

$ sudo clinfo

Number of platforms                               1
  Platform Name                                   OpenCL for the Raspberry Pi VideoCore IV GPU
  Platform Vendor                                 doe300
  Platform Version                                OpenCL 1.2 VC4CL 0.4
  Platform Profile                                EMBEDDED_PROFILE
  Platform Extensions                             cl_khr_il_program cl_khr_spir cl_altera_device_temperature cl_altera_live_object_tracking cl_khr_icd cl_vc4cl_performance_counters
  Platform Extensions function suffix             VC4CL

  Platform Name                                   OpenCL for the Raspberry Pi VideoCore IV GPU
Number of devices                                 1
  Device Name                                     VideoCore IV GPU
  Device Vendor                                   Broadcom
  Device Vendor ID                                0xa5c
  Device Version                                  OpenCL 1.2 VC4CL 0.4
  Driver Version                                  0.4
  Device OpenCL C Version                         OpenCL C 1.2
  Device Type                                     GPU
  Device Profile                                  EMBEDDED_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               1
  Max clock frequency                             500MHz
  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                             12x12x12
  Max work group size                             12
  Preferred work group size multiple              1
  Preferred / native vector sizes
    char                                                16 / 16
    short                                               16 / 16
    int                                                 16 / 16
    long                                                 0 / 0
    half                                                 0 / 0        (n/a)
    float                                               16 / 16
    double                                               0 / 0        (n/a)
(以下略)

CPU vs GPU 速度比較

vc4clを触るときはsudoが必要

$ git clone git://github.com/HandsOnOpenCL/Exercises-Solutions.git
$ cd Exercises-Solutions/Solutions/Exercise06/C
$ make
$ sudo ./mult
Using OpenCL device: VideoCore IV GPU

===== Sequential, matrix mult (dot prod), order 1024 on host CPU ======
 25.80 seconds at 83.3 MFLOPS

===== OpenCL, matrix mult, C(i,j) per work item, order 1024 ======
 30.00 seconds at 71.6 MFLOPS

 Errors in multiplication: 246368803225600.000000
terminate called without an active exception
中止
  • CPUの方が若干早かった。
  • 途中で落ちてしまったが、原因究明未。

更に調べていると

Raspberry Pi 4 のGPUについて言及されている記事を発見。

RPi4になってGPUが変わったようですが (VideoCore VI, VC6)、本記事で入れたライブラリはRPi3以前向け (VideoCore IV, VC4) ということでした。
VC6向けのライブラリが待たれる…。