Difference between revisions of "R-Car/Boards/Yocto-Gen3/OpenCL"
< R-Car | Boards/Yocto-Gen3
m |
|||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{TOC right}} | {{TOC right}} | ||
== OpenCL support == | == OpenCL support == | ||
+ | T.B.D | ||
+ | <!-- | ||
+ | The '''meta-opencl''' layers provide the following packages: | ||
− | + | * '''meta-ocl-rcar-gen3''' layer: | |
+ | ** ''cl-gles-user-module'' - OpenCL/OpenGL user module for Renesas R-Car R8A7795 SoC boards | ||
+ | * '''meta-ocl-common''' layer: | ||
+ | ** ''libgfortran'' - GNU Fortran library (fixes) | ||
+ | ** ''opencv'' - Open Computer Vision library (fixes) | ||
+ | ** ''gflags'' - command line flags processing library | ||
+ | ** ''snappy'' - fast compressor/decompressor | ||
+ | ** ''lmdb'' - Lightning Memory-Mapped Database | ||
+ | ** ''openblas'' - optimized linear algebra library | ||
+ | ** ''viennacl'' - linear algebra library for computations on many-core architectures | ||
+ | ** ''clblas'' - library containing BLAS functions written in OpenCL | ||
+ | ** ''clblast'' - OpenCL BLAS library written in C++11 | ||
+ | ** ''caffe'' - deep learning framework | ||
+ | ** ''renesas-opencl-sdk'' - separate set of Caffe/clBlas/ATLAS libraries and samples provided by Luxoft | ||
− | + | '''Notes:''' | |
− | * | + | * OpenCL is currently supported on the following boards: |
− | * | + | ** Renesas R-Car H3/M3 SoC boards (Yocto 3.7.0 and above). |
− | * '' | + | ** Renesas R-Car H3 SoC boards (prior to Yocto 3.7.0). |
− | + | * Luxoft ''renesas-opencl-sdk'' provides separate set of Caffe and clBlas libraries, and does not depend on ''caffe'' or ''clblas'' packages. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | == Downloading the prerequisites == | |
− | + | Download basic Yocto layers as described in ''Yocto Start-Up Guide'', and use the following commands to download ''meta-opencl'' layers: | |
+ | <ol><li>Clone ''meta-opencl'' git repository along with the other Yocto layers: | ||
+ | <pre> | ||
+ | git clone https://github.com/CogentEmbedded/meta-opencl.git | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Switch to the proper branch: | ||
+ | <ul><li> | ||
+ | Yocto 2.12.0: | ||
+ | <pre> | ||
+ | git -C meta-opencl checkout v2.12.0 | ||
+ | </pre> | ||
+ | </li><li>Yocto 2.19.0: | ||
+ | <pre> | ||
+ | git -C meta-opencl checkout v2.19.0 | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Yocto 2.23.0: | ||
+ | <pre> | ||
+ | git -C meta-opencl checkout v2.23.0 | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Yocto 3.7.0: | ||
+ | <pre> | ||
+ | git -C meta-opencl checkout v3.7.0 | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Yocto 3.9.0: | ||
+ | <pre> | ||
+ | git -C meta-opencl checkout v3.9.0 | ||
+ | </pre> | ||
+ | </li></ul> | ||
+ | </li></ol> | ||
+ | Download the OpenGL/OpenCL combined GPU libraries using the following link: https://www.renesas.com/us/en/solutions/automotive/rcar-download/rcar-opencl.html | ||
+ | The zip archive should contain ''linux_gsx_binaries_cl_gles'' tarball that is to be used with ''meta-opencl/meta-ocl-rcar-gen3'' layer. | ||
+ | <br> | ||
+ | '''Note:''' Yocto 3.7.0 tarball can be used with Yocto 3.9.0 as well. | ||
− | Set up Yocto | + | == Enabling OpenCL support in Yocto for R-Car Gen3 boards == |
+ | |||
+ | Set up Yocto as usual, and use the following steps to enable OpenCL support before starting the build. | ||
<ol><li> | <ol><li> | ||
− | Copy OpenCL/OpenGL binaries to the meta-opencl layer: | + | Copy OpenCL/OpenGL binaries to the ''meta-opencl/meta-ocl-rcar-gen3'' layer: |
− | < | + | <ul><li> |
+ | Yocto 3.7.0 and above: | ||
+ | <pre> | ||
+ | DEST=meta-opencl/meta-ocl-rcar-gen3/recipes-graphics/cl-gles-module/cl-gles-user-module | ||
+ | for f in *_linux_gsx_binaries_cl_gles.tar.bz2; do | ||
+ | cp ${f} ${DEST}/${f#EVA_} && echo "Copied: ${f}" | ||
+ | done | ||
+ | </pre> | ||
+ | '''Note:''' Strip the ''EVA_'' prefix while copying when using evaluation version. | ||
</li><li> | </li><li> | ||
− | + | Prior to Yocto 3.7.0: | |
<pre> | <pre> | ||
− | + | cp r8a7795_linux_gsx_binaries_cl_gles3.tar.bz2 meta-opencl/meta-ocl-rcar-gen3/recipes-graphics/cl-gles-module/cl-gles-user-module/ | |
</pre> | </pre> | ||
+ | </li></ul> | ||
</li><li> | </li><li> | ||
− | Add meta-python layer to BBLAYERS in bblayers.conf file: | + | Add meta-python layer to ''BBLAYERS'' in ''bblayers.conf'' file: |
<pre> | <pre> | ||
− | ${TOPDIR}/../meta-openembedded/meta-python \ | + | ${TOPDIR}/../meta-openembedded/meta-python \</pre> |
+ | </li><li> | ||
+ | Add meta-opencl layers to ''BBLAYERS'' in ''bblayers.conf'' file: | ||
+ | <pre> | ||
+ | ${TOPDIR}/../meta-opencl/meta-ocl-common \ | ||
+ | ${TOPDIR}/../meta-opencl/meta-ocl-rcar-gen3 \ | ||
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | 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: | + | 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'': |
+ | <ul><li> | ||
+ | Yocto 2.23.0 and above: | ||
+ | <pre> | ||
+ | PREFERRED_PROVIDER_virtual/libgles2 = "cl-gles-user-module" | ||
+ | PREFERRED_PROVIDER_virtual/opencl = "cl-gles-user-module" | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Prior to Yocto 2.23.0: | ||
<pre> | <pre> | ||
PREFERRED_PROVIDER_virtual/libgles2 = "cl-gles-user-module" | PREFERRED_PROVIDER_virtual/libgles2 = "cl-gles-user-module" | ||
Line 41: | Line 111: | ||
PREFERRED_PROVIDER_virtual/opencl = "cl-gles-user-module" | PREFERRED_PROVIDER_virtual/opencl = "cl-gles-user-module" | ||
</pre> | </pre> | ||
+ | </li></ul> | ||
</li><li> | </li><li> | ||
− | Enable cl-gles-user-module instead of gles-user-module in local.conf: | + | Enable ''cl-gles-user-module'' instead of ''gles-user-module'' in ''local.conf'': |
<pre> | <pre> | ||
PREFERRED_PROVIDER_gles-user-module = "cl-gles-user-module" | PREFERRED_PROVIDER_gles-user-module = "cl-gles-user-module" | ||
</pre> | </pre> | ||
− | </li>< | + | </li></ol> |
− | + | ||
+ | Sample configuration files are available at ''meta-opencl/meta-ocl-rcar-gen3/docs/sample/conf''. | ||
+ | |||
+ | == Enabling Caffe support in Yocto == | ||
+ | |||
+ | Once OpenCL is enabled, enable Caffe support by adding the following line to ''local.conf'': | ||
<pre> | <pre> | ||
IMAGE_INSTALL_append = " caffe" | IMAGE_INSTALL_append = " caffe" | ||
</pre> | </pre> | ||
− | </ | + | |
− | + | Caffe can be configured with ''PACKAGECONFIG'' variable. | |
+ | The following configuration features are supported: | ||
+ | * ''opencv'' - enable OpenCV support (ON) | ||
+ | * ''clblas'' - build using clBLAS instead of ViennaCL (OFF) | ||
+ | * ''clblast'' - build using CLBlast instead of ViennaCL (OFF) | ||
+ | * ''lmdb'' - enable LMDB support (OFF) | ||
+ | * ''leveldb'' - enable LevelDB support (OFF) | ||
+ | |||
+ | Only OpenCV support is enabled by default. In case you need to use clBLAS instead of ViennaCL, add the following configuration variable to ''local.conf'' file: | ||
+ | <pre> | ||
+ | PACKAGECONFIG_append_pn-caffe = " clblas" | ||
+ | </pre> | ||
+ | |||
+ | If CLBlast support is needed, the following variable should be used: | ||
+ | <pre> | ||
+ | PACKAGECONFIG_append_pn-caffe = " clblast" | ||
+ | </pre> | ||
+ | |||
+ | In case database support is need, use the following variable in ''local.conf'': | ||
+ | <pre> | ||
+ | PACKAGECONFIG_append_pn-caffe = " leveldb lmdb" | ||
+ | </pre> | ||
+ | |||
+ | Any number of features can be combined using ''PACKAGECONFIG'' variable, | ||
+ | however clBLAS and CLBlast features are mutually exclusive, for example: | ||
+ | <pre> | ||
+ | PACKAGECONFIG_append_pn-caffe = " clblas leveldb lmdb" | ||
+ | </pre> | ||
+ | |||
+ | Finally, edit ''local.conf'' to add packages necessary for downloading and unpacking Caffe sample models: | ||
<pre> | <pre> | ||
IMAGE_INSTALL_append = " git python-argparse python-pyyaml python-six" | IMAGE_INSTALL_append = " git python-argparse python-pyyaml python-six" | ||
</pre> | </pre> | ||
− | < | + | |
+ | == Enabling OpenCL SDK by Luxoft == | ||
+ | |||
+ | Edit ''local.conf'' to add Renesas OpenCL SDK by Luxoft: | ||
+ | <pre> | ||
+ | IMAGE_INSTALL_append += " renesas-opencl-sdk" | ||
+ | </pre> | ||
+ | |||
+ | == Building Yocto images == | ||
+ | |||
Start the build as usual: | Start the build as usual: | ||
<pre> | <pre> | ||
bitbake core-image-weston | bitbake core-image-weston | ||
</pre> | </pre> | ||
− | |||
If the target board is to be used for natively building OpenCL applications, | If the target board is to be used for natively building OpenCL applications, | ||
Line 67: | Line 180: | ||
<ol><li> | <ol><li> | ||
− | Enable Fortran support in local.conf: | + | Enable Fortran support in ''local.conf'': |
<pre> | <pre> | ||
FORTRAN_forcevariable = ",fortran" | FORTRAN_forcevariable = ",fortran" | ||
− | RUNTIMETARGET_append_pn-gcc-runtime = " libquadmath | + | RUNTIMETARGET_append_pn-gcc-runtime = " libquadmath" |
IMAGE_INSTALL_append = " gfortran gfortran-symlinks libgfortran libgfortran-dev" | IMAGE_INSTALL_append = " gfortran gfortran-symlinks libgfortran libgfortran-dev" | ||
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | Enable cmake in local.conf: | + | Enable cmake in ''local.conf'': |
<pre> | <pre> | ||
IMAGE_INSTALL_append = " cmake" | IMAGE_INSTALL_append = " cmake" | ||
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | Enable boost development libraries in local.conf: | + | Enable boost development libraries in ''local.conf'': |
<pre> | <pre> | ||
IMAGE_INSTALL_append = " boost-dev boost-staticdev" | IMAGE_INSTALL_append = " boost-dev boost-staticdev" | ||
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | Enable | + | Enable other development libraries in ''local.conf'': |
<pre> | <pre> | ||
− | IMAGE_INSTALL_append = " gflags-dev snappy-dev protobuf-dev leveldb-dev lmdb-dev opencv-dev" | + | IMAGE_INSTALL_append = " gflags-dev snappy-dev protobuf-dev leveldb-dev lmdb-dev opencv-dev opencv-apps" |
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | Enable BLAS development libraries in local.conf: | + | Enable BLAS development libraries in ''local.conf'': |
<pre> | <pre> | ||
− | IMAGE_INSTALL_append = " caffe-dev clblas-dev viennacl-dev openblas-dev" | + | IMAGE_INSTALL_append = " caffe-dev clblas-dev clblast-dev viennacl-dev openblas-dev" |
</pre> | </pre> | ||
</li><li> | </li><li> | ||
− | Build | + | Prior to Yocto 3.7.0: disable ''cpio.gz'' image generation in ''local.conf'' to avoid 2GB cpio image size limitation issues: |
+ | <pre> | ||
+ | IMAGE_FSTYPES_remove = "cpio.gz" | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Remove Linux kernel sources and LTP to make SDK image smaller if necessary: | ||
+ | <pre> | ||
+ | IMAGE_INSTALL_remove = "kernel-devsrc ltp" | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Build SDK image: | ||
<pre> | <pre> | ||
bitbake core-image-weston-sdk | bitbake core-image-weston-sdk | ||
Line 100: | Line 223: | ||
</li></ol> | </li></ol> | ||
− | + | == Testing OpenCL on R-Car Gen3 boards == | |
− | |||
− | == Testing OpenCL == | ||
Use the following command to start OpenCL unit tests on the board: | Use the following command to start OpenCL unit tests on the board: | ||
Line 109: | Line 230: | ||
</pre> | </pre> | ||
− | The application should perform the unit tests and print results to the console. | + | The application should perform the unit tests, and print results to the console. |
The last message should indicate the number of passed tests: | The last message should indicate the number of passed tests: | ||
<pre> | <pre> | ||
Finished 31 tests in 171.5 seconds: 31 passed, 0 failed (100.00%) | Finished 31 tests in 171.5 seconds: 31 passed, 0 failed (100.00%) | ||
+ | </pre> | ||
+ | |||
+ | '''Note:''' OpenCL unit test is included in the ''cl-gles-module-dev'' package which is added to ''core-image-weston-sdk'' by default. | ||
+ | |||
+ | == Testing ViennaCL == | ||
+ | |||
+ | Use the following command to display ViennaCL information: | ||
+ | <pre> | ||
+ | viennacl-info | ||
+ | </pre> | ||
+ | |||
+ | Make sure that GPU device type is used: | ||
+ | <pre> | ||
+ | Type: GPU | ||
</pre> | </pre> | ||
Line 119: | Line 254: | ||
Before Caffe classification test can be started, Caffe model has to be downloaded and unpacked. | 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 | The next two steps can be done on the target board directly, provided the board is connected | ||
− | to the internet, and DNS is properly | + | to the internet, and DNS is properly setup. Otherwise, the model can be downloaded to the host |
− | system and copied to the target | + | system and copied to the target root filesystem later. |
− | |||
<ol><li> | <ol><li> | ||
Download Caffe sources: | Download Caffe sources: | ||
Line 145: | Line 279: | ||
examples/images/cat.jpg | examples/images/cat.jpg | ||
</pre> | </pre> | ||
− | + | </li><li> | |
The test should detect the cat in the image, and produce the following output to the console: | The test should detect the cat in the image, and produce the following output to the console: | ||
<pre> | <pre> | ||
Line 157: | Line 291: | ||
</pre> | </pre> | ||
</li></ol> | </li></ol> | ||
+ | |||
+ | == Testing Renesas OpenCL SDK by Luxoft == | ||
+ | |||
+ | <ol><li> | ||
+ | Export ''RENESAS_OPENCL_SDK_ROOT'' directory, for example: | ||
+ | <pre> | ||
+ | export RENESAS_OPENCL_SDK_ROOT=/opt/renesas/renesas-opencl-sdk-1.0.5 | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Create SDK working directory: | ||
+ | <pre> | ||
+ | mkdir -p /home/root/RenoclSDK | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Copy binaries and libs from ''RENESAS_OPENCL_SDK_ROOT'' to SDK working directory: | ||
+ | <pre> | ||
+ | cp $RENESAS_OPENCL_SDK_ROOT/__output/* /home/root/RenoclSDK | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Copy resources from ''RENESAS_OPENCL_SDK_ROOT'' to SDK working directory: | ||
+ | <pre> | ||
+ | cp -r $RENESAS_OPENCL_SDK_ROOT/Resources /home/root/RenoclSDK | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Export ''LD_LIBRARY_PATH'': | ||
+ | <pre> | ||
+ | export LD_LIBRARY_PATH=/home/root/RenoclSDK:$LD_LIBRARY_PATH | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Change current working directory to the SDK working directory: | ||
+ | <pre> | ||
+ | cd /home/root/RenoclSDK | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Run Face Detection Samples, for example: | ||
+ | <pre> | ||
+ | ./BasicFaceDetHaar -image Resources/images/singleFace.jpg | ||
+ | ./OpenCLFaceDetHaar -image Resources/images/singleFace.jpg | ||
+ | </pre> | ||
+ | </li><li> | ||
+ | Run Deep Learning Samples, for example: | ||
+ | <pre> | ||
+ | ./BasicCaffeSegNet -image Resources/Segnet/0001TP_008550.png | ||
+ | ./OpenCLCaffeSegNet -image Resources/Segnet/0001TP_008550.png | ||
+ | </pre> | ||
+ | </li></ol> | ||
+ | |||
+ | For further details, please refer to the documentation available at ''$RENESAS_OPENCL_SDK_ROOT/documents''. | ||
+ | |||
+ | --> |