R-Car/Boards/Yocto-Gen3/OpenCL

From eLinux.org
Jump to: navigation, search

OpenCL support

The meta-opencl layer provides the following packages:

  • cl-gles-user-module - OpenCL/OpenGL user module for Renesas R-Car R8A7795 SoC boards
  • gfortran - GNU Fortran compiler
  • libgfortran - GNU Fortran library
  • gflags - command line flags processing library
  • snappy - fast compressor/decompressor
  • lmdb - Lightning Memory-Mapped Database
  • opencv - Open Computer Vision library
  • openblas - optimized linear algebra library
  • viennacl - linear algebra library for computations on many-core architectures
  • clblas - library containing BLAS functions written in OpenCL
  • caffe - deep learning framework

Note: OpenCL is currently supported on Renesas R-Car R8A7795 SoC boards.

Building Yocto images with OpenCL support

Set up Yocto 2.12 as usual, and use the following steps to enable OpenCL Caffe support before starting the build:

  1. Copy OpenCL/OpenGL binaries to the meta-opencl layer:
    cp r8a7795_linux_gsx_binaries_cl_gles3.tar.bz2 meta-opencl/recipes-graphics/cl-gles-module/cl-gles-user-module/
  2. Add meta-opencl layer to BBLAYERS in bblayers.conf file:

    ${TOPDIR}/../meta-opencl \
    
  3. Add meta-python layer to BBLAYERS in bblayers.conf file:

    ${TOPDIR}/../meta-openembedded/meta-python \
    
  4. Replace all occurrences of gles-user-module with cl-gles-user-module, and add PREFERRED_PROVIDER_virtual/opencl variable equal to "cl-gles-user-module" in local.conf:

    PREFERRED_PROVIDER_virtual/libgles2 = "cl-gles-user-module"
    PREFERRED_PROVIDER_virtual/egl = "cl-gles-user-module"
    PREFERRED_PROVIDER_virtual/opencl = "cl-gles-user-module"
    
  5. Enable cl-gles-user-module instead of gles-user-module in local.conf:

    PREFERRED_PROVIDER_gles-user-module = "cl-gles-user-module"
    
  6. Edit local.conf to add Caffe to the rootfs image in local.conf:

    IMAGE_INSTALL_append = " caffe"
    
  7. Edit local.conf to add packages necessary for downloading and unpacking Caffe sample models:

    IMAGE_INSTALL_append = " git python-argparse python-pyyaml python-six"
    
  8. Start the build as usual:

    bitbake core-image-weston
    

If the target board is to be used for natively building OpenCL applications, it might be useful to follow additional configuration steps below.

  1. Enable Fortran support in local.conf:
    FORTRAN_forcevariable = ",fortran"
    RUNTIMETARGET_append_pn-gcc-runtime = " libquadmath libgfortran"
    IMAGE_INSTALL_append = " gfortran gfortran-symlinks libgfortran libgfortran-dev"
    
  2. Enable cmake in local.conf:

    IMAGE_INSTALL_append = " cmake"
    
  3. Enable boost development libraries in local.conf:

    IMAGE_INSTALL_append = " boost-dev boost-staticdev"
    
  4. Enable support development libraries in local.conf:

    IMAGE_INSTALL_append = " gflags-dev snappy-dev protobuf-dev leveldb-dev lmdb-dev opencv-dev"
    
  5. Enable BLAS development libraries in local.conf:

    IMAGE_INSTALL_append = " caffe-dev clblas-dev viennacl-dev openblas-dev"
    
  6. Build the SDK image:

    bitbake core-image-weston-sdk
    

Note: sample configuration files are available at meta-opencl/docs/sample/conf.

Testing OpenCL

Use the following command to start OpenCL unit tests on the board:

ocl_unit_test

The application should perform the unit tests and print results to the console. The last message should indicate the number of passed tests:

Finished 31 tests in 171.5 seconds: 31 passed, 0 failed (100.00%)

Testing Caffe

Before Caffe classification test can be started, Caffe model has to be downloaded and unpacked. The next two steps can be done on the target board directly, provided the board is connected to the internet, and DNS is properly set up. Otherwise, the model can be downloaded to the host system and copied to the target rootfs later.

  1. Download Caffe sources:
    git clone -b opencl -n git://github.com/BVLC/caffe.git
    cd caffe
    git checkout -b tmp e0f77c3b5f4837615f05b097ba3f2a05d7413e58
    
  2. Download and unpack Caffe model:

    ./scripts/download_model_binary.py models/bvlc_reference_caffenet
    ./data/ilsvrc12/get_ilsvrc_aux.sh
    
  3. Run Caffe classification test on the target board from Caffe source directory:

    classification \
    models/bvlc_reference_caffenet/deploy.prototxt \
    models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel \
    data/ilsvrc12/imagenet_mean.binaryproto \
    data/ilsvrc12/synset_words.txt \
    examples/images/cat.jpg
    

    The test should detect the cat in the image, and produce the following output to the console:

    Use GPU with device ID 0
    ---------- Prediction for examples/images/cat.jpg ----------
    0.3134 - "n02123045 tabby, tabby cat"
    0.2380 - "n02123159 tiger cat"
    0.1235 - "n02124075 Egyptian cat"
    0.1004 - "n02119022 red fox, Vulpes vulpes"
    0.0715 - "n02127052 lynx, catamount"