Building Android NDK applications with Intel Integrated Performance Primitives (Intel IPP)

Updated on 19-Dec-2013
HIGHLIGHTS

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.

Intel® Integrated Performance Primitives (Intel IPP) provides highly optimized building block functions for image processing, signal processing, vector math and small matrix computation. Several Intel IPP domains contain the hand-tuned functions for Intel Atom™ processor by taking advantage of Intel® Streaming SIMD Extensions (Intel SSE) instructions. The Intel IPP static non-threaded Linux* libraries now support the 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 Intel IPP libraries into the building command line.

Using Intel IPP
1. Adding Intel IPP functions in source
  • Include the Intel IPP header files (ipp.h) in the source files.
  • Call ippInit() before using any other Intel 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 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 build 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 dependencies into the linkage line. Check the article “Intel IPP Library Dependencies” to learn about the required Intel IPP libraries.
  • Add the Intel IPP libraries to android building script file “jni/Android.mk”:
    Declare each Intel 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 Intel IPP libraries into the modules calling Intel 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 below that shows Intel IPP usage in the native Android code. The code uses the Intel IPP ippsAdd_32f() function to add data for two arrays.

To review Intel IPP usage in the code:
  1. Download the sample code and unpack it to your project folder (<projectdir>).
  2. Learn Intel IPP usage in the source files: The “jni/IppAdd.c” file provides the implementation of one native function NativeIppAdd(). The function calls the Intel IPP ippsAdd_32f() function. The “src/com/example/testippadd/ArrayAddActivity.java” file calls the native “NativeIppAdd()” function through JNI.
  3. Check the “jni/Android.mk” file. This file adds the required Intel IPP libraries into the build script. The sample uses the ippsAdd_32f() function, which belongs to the Intel IPP signal processing domain. The function depends on “libipps.a” and “libippcore.a” libraries. The “Android.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
  1. Copy the Intel IPP headers and libraries into your project folder (e.g. <projectdir>/ipp).
  2. Run the “ndk-build” script from your project’s directory to build the native code
  3.          >cd <projectdir>          ><ndkdir>/ndk-build 
  4. Build the Android package and install the application
  5.          >cd <projectdir>         >android update project -p . -s         >ant debug         >adb install bin/ArrayAddActivity-debug.apk 
Build the sample by Eclipse* IDE
  1. Copy the Intel IPP headers and libraries into your project folder (e.g. <projectdir>/ipp).
  2. In Eclipse, click File >> New >> Project… >> Android >> Android Project from Existing Code. In the “Root Directory“, select the sample code folder, then click Finish.
  3. Run the ‘ndk-build’ script from your project’s directory to build the native code:
  4.          >cd <projectdir>         ><ndkdir>/ndk-build 
  5. Build the application in the Eclipse IDE and deploy the .apk file.

Team Digit

Team Digit is made up of some of the most experienced and geekiest technology editors in India!

Connect On :