Android NDK and the x86 Platform

28
Android and the x86 Platform Sebastian Mauer GDG Aachen December Meetup December 16th, 2013

description

 

Transcript of Android NDK and the x86 Platform

Page 1: Android NDK and the x86 Platform

Android and the x86 Platform

Sebastian Mauer GDG Aachen

December Meetup December 16th, 2013

Page 2: Android NDK and the x86 Platform

Who am I?Sebastian MauerGDG Aachen Co-Lead CS StudentSoftware Engineer I don’t work for Google…yet

Page 3: Android NDK and the x86 Platform

Part I: x86: The new kid on the block?

Page 4: Android NDK and the x86 Platform

Android Platforms

MIPS x86ARM

Page 5: Android NDK and the x86 Platform

Android on x86 is already here

Page 6: Android NDK and the x86 Platform

Android VM

Hardware

Linux Kernel

Dalvik VM App

App

App

App

App

App

Page 7: Android NDK and the x86 Platform

From Source to BytecodeJava

Sourcecode

Java Bytecode (.class)

Dalvik Bytecode (.dex)

JAR Archive

Dalvik VM

Java VM

Page 8: Android NDK and the x86 Platform

It just works™

• The DalvikVM is already optimized for the x86 Platform

• Apps relying on the Android SDK / Dalvik Bytecodewill automatically benefit from Platform-specific Optimizations (like SSE & Co.)

Page 9: Android NDK and the x86 Platform

Part II: Going native. The NDK.

Page 10: Android NDK and the x86 Platform

What’s the NDK?

• NDK stands for Native Development Kit

• Allows to compile C/C++ code to native (read: platform specific) executables/libraries.

• Has to be compiled for every platform you want to support

Page 11: Android NDK and the x86 Platform

What’s an NDK app?It’s an Android application that uses native libraries. !Libraries are .so files, usually found inside libs/CPU_ABI/. !These libs can be generated from native sources inside jni folder, game engines, or required by other 3rd party libraries. !There is no 100% native application. Even an application purely written in C/C++, using native_app_glue.h, will be executed in the context of the Dalvik Virtual Machine. !

Page 12: Android NDK and the x86 Platform

NDK Anatomy

Native Platform

Dalvik VMDalvik Bytecode

NDK compiled binary

Java Native Interface

(JNI)

Page 13: Android NDK and the x86 Platform
Page 14: Android NDK and the x86 Platform

Compile for all the platforms.If you have the source code of your native libraries, you can compile it for several CPU architectures by setting APP_ABI to all in the Makefile “jni/Application.mk”:! APP_ABI=all

The NDK will generate optimized code for all target ABIs You can also pass APP_ABI variable directly to ndk-build, and specify each ABI: ndk-build APP_ABI=x86

ARM v7a libs are built

ARM v5 libs are built x86 libs are built

mips libs are built

Put APP_ABI=all inside Application.mkRun ndk-build…

Page 15: Android NDK and the x86 Platform

Fat Binaries

Use lib/armeabi libraries

Use lib/armeabi-v7a libraries

Use lib/x86 libraries

libs/armeabi-v7a

libs/x86

libs/armeabi

APK file

Page 16: Android NDK and the x86 Platform

Part III: We must go deeper. Porting Processor-specific code

Page 17: Android NDK and the x86 Platform

SIMD Instructions

• SIMD (Single instruction, multiple data)

• NEON Instruction set on certain ARM CPUS

• MMX™, Intel® SSE, SSE2, SSE3, SSSE3 on Intel® Atom™ processor based platforms

Page 18: Android NDK and the x86 Platform

Easy Way Out: NEONvsSSE.h//******* definition sample ***************** int8x8_t vadd_s8(int8x8_t a, int8x8_t b); // VADD.I8 d0,d0,d0 #ifdef USE_MMX #define vadd_s8 _mm_add_pi8 //MMX #else #define vadd_s8 _mm_add_epi8 #endif //…

• Wraps NEON functions and intrinsics to SSE3 – 100% covered

• Available at http://intel.ly/10JjuY4

Page 19: Android NDK and the x86 Platform

Memory AlignmentBy default

Easy fix

struct TestStruct { int mVar1; long long mVar2; int mVar3; };

struct TestStruct { int mVar1; long long mVar2 __attribute__ ((aligned(8))); int mVar3; };

Page 20: Android NDK and the x86 Platform

Part IV: Ecosystem & Tools

Page 21: Android NDK and the x86 Platform

HAXM (Hardware Accelerated Execution Manager)

Page 22: Android NDK and the x86 Platform

Intel TBB (Threading Building Blocks)Specify tasks instead of manipulating threads

▪ Intel® Threading Building Blocks (Intel® TBB) maps your logical tasks onto threads with full support for nested parallelism

Targets threading for scalable performance

▪Uses proven efficient parallel patterns

▪Uses work-stealing to support the load balance of unknown execution time for tasks

Open source and licensed versions available on Linux*, Windows*, Mac OS X*, Android*…

Open Source version available on: threadingbuildingblocks.org Licensed version available on: software.intel.com/en-us/intel-tbb

Page 23: Android NDK and the x86 Platform

Graphics Performance Analyzer• Profiles performance and Power • Real-time charts of CPU, GPU and

power metrics • Conduct real-time experiments

with OpenGL-ES* (with state overrides) to help narrow down problems

• Triage system-level performance with CPU, GPU and Power metrics

Available at intel.com/software/gpa

Page 24: Android NDK and the x86 Platform

HTML5 Development Environment (XDK) • Great tools for free • Convenient, cloud-based build tool lets you target all popular

platforms & app stores • Write once, run anywhere; code once, debug once, publish everywhere

more on: html5dev-software.intel.com

Page 25: Android NDK and the x86 Platform

Part V: The Future

Page 26: Android NDK and the x86 Platform

The Future: SilvermontNew 22nm tri-gate microarchitecture~3X more peak performance or ~5X lower power than previous Atom microarchitecture

Intel® Atom™ Processor Z3000 Series (Bay Trail) Next Generation Tablets

Merrifield Next Generation Smartphones

Page 27: Android NDK and the x86 Platform

Q&A

Page 28: Android NDK and the x86 Platform

Thanks for your attention.