Intel IPP provides highly optimized building block functions for image processing, signal processing, vector math and small matrix computation. Several IPP domains contain the hand-tuned functions for Intel(R) Atom™ processor by taking advantage of Intel® Streaming SIMD Extensions (Intel® SSE) instructions. The IPP static non-threaded Linux* libraries now support Android* OS, and can be used with Android applications.
This article gives an introduction on how to add Intel IPP functions into Android NDK applications. Intel IPP provides processor-specific optimization, and only can be linked with native Android C/C++ code. To use Intel IPP with your application, you need to include Intel IPP functions in your source code, and you also need to add IPP libraries into the building command line.
Using Intel IPP
1. Adding Intel IPP functions in source
- In source files, include the Intel IPP header files (ipp.h)
- Call ippInit() before using any other IPP functions. Intel IPP detects the processor features and selects the optimizing code path for the target processors. Before calling any other Intel IPP functions, call the ippInit() to initialize the CPU dispatching for Intel IPP.
- Call Intel IPP functions in your C/C++ source.
2. Including Intel IPP libraries into the Android NDK building files
- Copy Intel IPP libraries and headers to your project folder.
- Find Intel libraries required for the application: Intel IPP libraries are categorized into different domains. Each domain has its own library, and some domain libraries depend on other ones. It needs to include all domain libraries and their dependency ones into the linkage line. Check the “Intel IPP Library Dependencies” article to learn required Intel IPP libraries.
- Add the IPP libraries to android building script file “jni/Android.mk”:
Declare each IPP library as the prebuilt library module. For example, if the application uses two Intel IPP libraries "libipps.a" and "libippcore.a", add the following into the file:
include $(CLEAR_VARS)
LOCAL_MODULE := ipps
LOCAL_SRC_FILES := ../ipp/lib/ia32/libipps.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ippcore
LOCAL_SRC_FILES := ../ipp/lib/ia32/libippcore.a
include $(PREBUILT_STATIC_LIBRARY)
Add the header path and IPP libraries into the modules calling IPP functions:
include $(CLEAR_VARS)
LOCAL_MODULE := IppAdd
LOCAL_SRC_FILES := IppAdd.c
LOCAL_STATIC_LIBRARIES := ipps ippcore
LOCAL_C_INCLUDES := ./ipp/include
include $(BUILT_SHARED_LIBRARY)
Building one sample code
A simple example is included bellow that shows Intel IPP usage in the native Android code. The code uses Intel IPP ippsAdd_32f()function to add data for two arrays.
To review Intel IPP usage in the code:
- Download the sample code and unpack it to your project folder(<projectdir>).
- Learn IPP usage in the source files: The "jni/IppAdd.c" file provides the implementation of one native function NativeIppAdd(). The function call Intel IPP ippsAdd_32f() function. The "src/com/example/testippadd/ArrayAddActivity.java" file call the native "NativeIppAdd()" function through JNI.
- Check "jni/Andriod.mk" file. This file adds the required IPP libraries into the building script. The sample uses ippsAdd_32f()function, which is belong to Intel IPP signal processing domain. The function depends on "libipps.a" and "libippcore.a" libraries. The "Andriod.mk" file creates two prebuilt libraries for them.
You can build the sample code either using the SDK and NDK command tools or using Eclipse* IDE
Build the sample from a command line
- Copy the Intel IPP headers and libraries into your project folder (e.g. <projectdir>/ipp).
- Run the "ndk-build" script from your project's directory to build the native code
>cd <projectdir>
><ndkdir>/ndk-build - Build android package and install the application
>cd <projectdir>
>android update project -p . -s
>ant debug
>adb install bin/NativeActivity-debug.apk
Build the sample by Eclipse* IDE
- Copy the Intel IPP headers and libraries into your project folder (e.g. <projectdir>/ipp).
- In Eclipse, click File >> New >> Project...>>Andriod>> Andriod Project from Existing Code. In the "Root Directory", select the sample code folder, then click Finish.
- Run the 'ndk-build' script from your project's directory to build the native code:
>cd <projectdir>
><ndkdir>/ndk-build - Build the application in the Eclipse IDE and deploy the .apk file.
Summary
This article provide the introduction on IPP usage with the native Android* applications. Check more information on Intel IPP functions in the IPP manual.