11 Sep 2017
Running OpenCL Sample Application on Open-Q™ 820 System on Module, powered by Qualcomm® Snapdragon™ 820 SOC
Running OpenCL Sample Application on Open-Q™ 820
OpenCL (Open Computing Language) is an industry standard that allows software developers to take advantage of multiple processors in order to increase the performance of computational tasks. While originally designed for desktop computers, OpenCL has in recent years slowly been becoming more available on embedded systems as more Graphics Processing Units (GPUs) become OpenCL compatible. With the help of OpenCL, GPUs are able to perform intensive parallel programming tasks in graphics-related as well as non-graphics related computational workloads, allowing for significantly improved processing times. One of the GPUs used in smartphones and tablets that now supports OpenCL is Qualcomm’s Adreno 530, which is used in Intrinsyc’s Open-Q 820 Development Kit.
In order to demonstrate the decreased processing time enabled by OpenCL on the Adreno 530, a sample application originally taken from the Sony Mobile website  will be used. (This is not available on the Sony website any more but is available as archived pages , and in Github ). Since the source code was originally targeted toward Sony Xperia devices , it has been slightly modified for use by the different hardware of the Open-Q 820. The sample application applies OpenCL to a math intensive bilateral filter operation on a noisy photo. In one case, the bilateral filter is applied using OpenCL, while in the second case it is applied using Native C. While the execution time improvements may vary across different OpenCL-supported devices due to differences in architecture, executing the bilateral filter using OpenCL on the Open-Q 820 (GPU) has demonstrated to be over 300 times faster than using Native C (ARM/CPU).
The following sections describe our modifications to Sony’s sample application that we performed for the Open-Q 820. Section 1 illustrates the expected behavior of the application after modifying it for use on the Open-Q 820. Section 2 describes the steps that were taken to modify the original sample application from Sony Mobile such that the source code could be built for Intrinsyc’s Open-Q 820. Section 3 provides some suggestions for when troubleshooting is required.
Note: the instructions in this blog were tested for Open-Q 820 BSP Version 4.1. These instructions may still work for other versions if OpenCL is supported on them. Please see Section 3, step 2 to check if OpenCL is supported.
Section 1: Using the OpenCL Sample Application
Upon opening OpenCLexample1 on the device, a noisy image is shown along with three buttons.
The application will run a bilateral filter on the image to reduce the noise using either OpenCL or Native C, depending on which button is pressed. Press Reset between running OpenCL and NativeC to ensure the bilateral filter is applied to the noisy image. Pressing the OpenCL button should yield a much faster processing time than pressing the NativeC button (for example, 5ms versus 1638ms). The processing time will be displayed at the top of the screen.
Section 2: Modifying the Original OpenCL Sample Application to be built for the Open-Q 820
The following tutorial outlines the steps required to modify and build Sony’s OpenCL code example, taken from the Sony Mobile website, using Android Studio for Intrinsyc’s Open-Q 820 Development Kit.
Before initiating the steps below, ensure the latest NDK is set up by following steps at https://developer.android.com/ndk/guides/index.html
Download Sony’s OpenCL code example from Github:
git clone https://github.com/alon21034/android-opencl-example.git
or from archived pages of original Sony website as in .
Ensure NDK is set up:
Import openclexample1 into Android Studio as a new project:
In Android Studio, select File New Import Project (Gradle, Eclipse ADT, etc)
Select the location of android-opencl-example/OpenCL_code_example/openclexample1
Create an import destination directory.
Click Finish with the default options selected
Manually copy over any files from listed under "Ignored Files" in the generated import-summary.txt file.
For example, it may be necessary to manually copy over the following from the OpenCL_code_example/openclexample1 folder to the destination directory created in step 3c:
/OpenCL_code_example/openclexample1/extra_libs to /OpenCLSample/app/src/main/extra_libs
/OpenCL_code_example/openclexample1/include/ to /OpenCLSample/app/src/main/include
Link C++ project with gradle:
Right-click the project in Android Studio ("app" in the project view) and select "Link C++ Project with Gradle"
Select ndk-build and the location of Android.mk for the Build System and Project Path, respectively.
Replace libOpenCL.so with the one used by the device:
Use adb pull to get the file directly from the device.
adb pull vendor/lib64/libOpenCL.so
Replace openclexample1/OpenCLSample/app/src/main/extra_libs/libOpenCL.so with this new libOpenCL.so file.
The ABI used by the Open-Q 820 dev kit is arm64-v8a, which is supported as of SDK version 27. Therefore:
Modify the app level build.gradle file:
Change values of compileSdkVersion, minSdkVersion, and targetSdkVersion to 27. (This is for Android Oreo 8.1. For other Android versions use SDK level corresponding to the version)
Add abiFilters ‘arm64-v8a’ to ndk (which should have been generated under defaultConfig).