Linux上でOpenCLを使う時に必要な設定。 mesa-libOpenCLを使うと、GPU上でOpenCLを動かせる。

RPMのインストール

  • Fedora 27から以下のパッケージをダウンロードして、インストール。

     ocl-icd-2.2.11-4.fc27.x86_64.rpm
     ocl-icd-devel-2.2.11-4.fc27.x86_64.rpm
     opencl-filesystem-1.0-6.fc27.noarch.rpm
     opencl-headers-2.1-3.fc27.noarch.rpm
     mesa-libOpenCL-17.3.5-1.fc27.x86_64
    
     hwloc-libs-1.11.5-6.fc27.x86_64.rpm
     numactl-libs-2.0.11-5.fc27.x86_64.rpm
     pocl-0.15-0.1.20171023git53ef5e8.fc27.x86_64.rpm
    
    

動作確認

  $ clinfo
  Number of platforms                               2
    Platform Name                                   Clover
    Platform Vendor                                 Mesa
    Platform Version                                OpenCL 1.1 Mesa 17.3.5
    Platform Profile                                FULL_PROFILE
    Platform Extensions                             cl_khr_icd
    Platform Extensions function suffix             MESA

    Platform Name                                   Portable Computing Language
    Platform Vendor                                 The pocl project
    Platform Version                                OpenCL 1.2 pocl 0.15-pre, LLVM 5.0.0
    Platform Profile                                FULL_PROFILE
    Platform Extensions                             cl_khr_icd
    Platform Extensions function suffix             POCL

    Platform Name                                   Clover
  Number of devices                                 2
    Device Name                                     AMD Radeon HD 7800 Series (TAHITI / DRM 3.23.0 / 4.15.6-berry, LLVM 5.0.1)
    Device Vendor                                   AMD
    Device Vendor ID                                0x1002
    Device Version                                  OpenCL 1.1 Mesa 17.3.5
    Driver Version                                  17.3.5
    Device OpenCL C Version                         OpenCL C 1.1 
    Device Type                                     GPU

サンプル

  $ clang -Os ocl_vadd.c -o ocl_vadd `pkg-config --libs --cflags OpenCL`
  $ ./ocl_vadd 
  AMD Radeon HD 7800 Series (TAHITI / DRM 3.23.0 / 4.15.6-berry, LLVM 5.0.1) (platform 0, device 0)
  Maximum memory allocation size is 2254037811 bytes
  0.944981 + 0.508560 = 1.453541
  0.088696 + 0.883952 = 0.972648
  0.218562 + 0.401520 = 0.620082
  0.700157 + 0.740968 = 1.441126
  0.057511 + 0.860197 = 0.917708
  0.241567 + 0.017945 = 0.259512
  0.725138 + 0.159084 = 0.884221
  0.514352 + 0.842749 = 1.357100
  0.020787 + 0.305010 = 0.325797
  0.602458 + 0.016200 = 0.618658
  • ocl_vadd.c
  • ocl.h