Павел Чупин_Development and optimization android x86 applications от Intel

36
Development and optimization Android* x86 applications Pavel Chupin Staff Software Engineer October 2013

Transcript of Павел Чупин_Development and optimization android x86 applications от Intel

Page 1: Павел Чупин_Development and optimization android x86 applications от Intel

Development andoptimizationAndroid* x86 applications

Pavel ChupinStaff Software Engineer

October 2013

Page 2: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Agenda

• Where we are on Android*

• Tools to start development on IA

• Get full speed with Android* NDK

• Tips and tricks on porting from ARM* to IA

• Resources and contacts

2

Page 3: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Devices

3

Page 4: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Devices detailsModel number (codename)

CPU CPU cache GPUMemory technology

Availability

Utilizing devices

Atom Z2460 (platform Medfield)[4][5]

1.6 GHz single-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB

PowerVR SGX 540 @ 400 MHz

32-bit Dual-channel 400 MHz LPDDR2-800 (6.4 GB/sec)

Q2 2012

Lenovo K800, Orange San Diego, Lava XOLO X900, MegaFon Mint, ZTE Grand X IN, Ramos W32, XOLO x910, Senkatel Maximus

Atom Z2480 (platform Medfield)

2 GHz single-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB

PowerVR SGX 540 @ 400 MHz

32-bit Dual-channel 400 MHz LPDDR2-800 (6.4 GB/sec)

2012Motorola RAZR i, XOLO X1000,

Casper Via A6108

Atom Z2420 (Lexington)[15]

1.2 GHz single-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB

PowerVR SGX 540 @ 400 MHz

32-bit Dual-channel 400 MHz LPDDR2-800 (6.4 GB/sec)

Q1, 2013Xolo X500, Yolo, Acer Liquid C1, Asus FonePad, Etisalat E-20, Prestigio Multiphone 5430

Atom Z2760 (Cloverview,[23] platform Clover Trail[24]

1.8 GHz dual-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB (per core)

PowerVR SGX 545 @ 533 MHz

32-bit Dual-channel 400 MHz LPDDR2-800 (6.4 GB/sec)

Q4 2012

Asus VivoTab, Asus VivoTab Smart, HP Envy x2, HP ElitePad 900, Dell Latitude 10 Lenovo Thinkpad Tablet 2, Lenovo IdeaTab Lynx, Samsung Series 5 Slate Acer Iconia W510 ZTE V98, Acer Iconia W3, Samsung ATIV Tab 3

Atom Z2560 (Clover Trail+)[41]

1.6 GHz dual-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB (per core)

PowerVR SGX 544 MP2 @ 400 MHz

32-bit Dual-channel 533 MHz LPDDR2-1066 (8.5 GB/sec)

Q2 2013

ASUS FonePad Note FHD 6, Asus Memo Pad FHD 10,

Samsung Galaxy Tab 3 10.1-inch

Atom Z2580 (Clover Trail+)[46]

2 GHz dual-core Saltwell

L1: 32kB Instruction + 24kB Data, L2: 512kB (per core)

PowerVR SGX 544 MP2 @ 533 MHz

32-bit Dual-channel 533 MHz LPDDR2-1066 (8.5 GB/sec)

Q2 2013Lenovo K900, ZTE Grand X2 In

4

Page 5: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Next gen: Silvermont™ architecture

• 22nm SoC process using 3-D Tri-gate transistors• Out of order execution• Scalable up to 8x cores• SIMD support up to SSE4.2• Up to ~3x peak performance at ~5x lower power over

the current-generation Intel® Atom™ processor core*• Will appear in 2013

• *More details here: http://newsroom.intel.com/community/intel_newsroom/blog/2013/05/06/intel-launches-low-power-high-performance-silvermont-microarchitecture

Coming soon

5

Page 6: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Agenda

• Where we are on Android*

• Tools to start development on IA

• Get full speed with Android* NDK

• Tips and tricks on porting from ARM* to IA

• Resources and contacts

6

Page 7: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

A Development Environment for Native Android* Appson ARM* & Intel® Atom™ Devices

Beacon Mountain Preview v0.6.1

Free download at:intel.com/software/BeaconMountain

Intel & Third-Party Tools

Host Support for

Microsoft Windows* 7 & 8

and Apple OS X*

Android* Support for Jelly

Bean 4.2 and up

7

Page 8: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Comprehensive Android* Development Environment For Intel® Atom™ & ARM* Smartphones, Tablets App Tools for Design, Code, Debug & Acceleration Update Notifications and Optional installation Helps Shorten the Android* App Development Cycle

Intel Tools for x86 Intel® Hardware Accelerated Execution

Manager Intel® Graphics Performance Analyzers

System Analyzer Intel® Integrated Performance Primitives

Preview Intel® Threading Building Blocks Intel® Software Manager

Third-Party Tools for ARM/x86

Google* Android* SDK (ADT Bundle) Android* NDK Eclipse* Integrated Development

Environment Android* Design Cygwin* (for Microsoft* Windows operating

systems)

Free and Easy installation:intel.com/software/BeaconMountain

A Development Environment for Native Android* Appson ARM* & Intel® Atom™ Devices

Beacon Mountain Preview v0.6.1

8

Page 9: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Intel ToolsSupporting Intel® AtomTM Devices

Intel® Hardware Accelerated Execution ManagerA hardware-assisted virtualization engine that uses Intel® Virtualization Technology to speed up Android* emulation in a host environment.

Intel® Graphics Performance Analyzers System AnalyzerOptimize OpenGL* ES 1.0/2.0 workloads by providing a real-time view of over two dozen critical system metrics covering the CPU, GPU, and the OpenGL* ES API.

Intel® Threading Building Blocks C++ template library of pre-tested algorithms and features allow developers to efficiently thread C++ mobile applications for performance, while lowering system energy.

Intel® Integrated Performance Primitives Preview A library of pre-optimized image processing functions supporting Intel® smartphone and tablet platforms running Android* OS.  The preview release is a subset of the full Intel IPP product.

Intel® Software ManagerA utility that pushes messages about tool updates and other communications to developers.

9

Page 10: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Third-Party ToolsSupporting Intel® Atom™ & ARM* Devices

Google* Android* SDK (ADT Bundle for Microsoft Windows*)API libraries and developer tools to build, test, and debug apps for Android

Android* NDK for x86 Supports implementation of application code using native C++/C

Eclipse* Integrated Development Environment Part of the ADT bundle. Provides an integrated environment to build applications

Android* DesignStencils, icons, styles and more to use within apps without restriction

Cygwin*Linux-like environment for mixing Java and C/C++ code on Windows* systems

Oracle* Java SE Development Kit A tool for building applications and components using Java1

1Beacon Mountain checks your system to ensure you have the JDK installed. If you don’t, Beacon Mountain directs you to the Oracle site to download the correct version

10

Page 11: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Pre-built Atom Images• Android* SDK manager has x86 emulation

images built-in• To emulate an Atom-based Android*

phone, install the “Intel Atom x86 System Image” available in the Android* SDK Manager

Much Faster Emulation• Intel® Hardware Accelerated Execution

Manager (HAXM) for Mac and Windows uses Intel® Virtualization Technology (VT) to accelerate Android* emulator by 2-4x

• Intel VT is already supported in Linux* (KVM) for x86.

See www.intel.com/software/Android* for demo videos & installation tips

Intel x86 Emulator Accelerator

Faster Android* Emulation using an IA-based host PC

Intel x86 Atom System Image

11

Page 12: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Intel® Graphics Performance AnalyzersSystem Analyzer for Android

• Real-time system-level performance analysis for Intel-based Android* devices

• Immediate experiments and overwrites enable developers to isolate CPU and GPU performance problems

• Metrics for CPU, GPU, API, memory, network, power, etc.Drag ‘n Drop Metrics

Real-time Experiments

12

Page 13: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

For on-device app testing: Intel® GPA System AnalyzerReal-time Remote Performance and Power Profiling

Intel® GPA System Analyzer running on a PC

Android* Smart Phone

USB adb ConnectionWi-Fi Connection

Data

Real-time charts:• CPU metrics• Graphics API level metrics• Processor graphics hardware metrics• Power metrics

Download Intel® GPA for FREE at intel.com/software/GPA

13

Page 14: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

FREEfor

limitedtime

Intel® C++ Compiler for Android*

• Based on Intel® C/C++ Compiler XE 13.0 for Linux*

• Integrates into the Android* NDK as additional toolchain which can be used from the command-line

• Supports Intel® Atom™ processor optimizationAvailable on http://software.intel.com/c-compiler-android

14

Page 15: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Agenda

• Where we are on Android*

• Tools to start development on IA

• Get full speed with Android* NDK

• Tips and tricks on porting from ARM* to IA

• Resources and contacts

15

Page 16: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Android* Native Development Kit (NDK)Why use it?• Performance intensive tasks• signal-processing, complex algorithms, physics

simulation, graphics, etc.

• Take advantage of direct CPU/HW access• write hot code using SIMD instructions

• Reuse code• e.g. from PC segment

• Start from here: http://developer.android.com/tools/sdk/ndk/index.html

16

Page 17: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

C/C++Code

Makefile

ndk-build

Java calls

GDB debug

Java Framework

Java ApplicationSDK APIs

JNI

Native Libs

Android* Applications

NDK APIs

Bionic C Library

APP_ABI := allor APP_ABI := x86

NDK Application Development

through JNI

17

Page 18: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Fat binaries build and install

libs/x86/mylib.so

libs/arm/mylib.so

libs/arm-v7a/mylib.so

libs/mips/mylib.so

libs/?/mylib.so

myapp.apk

libs/x86/mylib.solibs/arm-v7a/mylib.so

18

Page 19: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

NDK compiler

• x86 is supported from NDK r6• Get latest and greatest NDK-r9 (July 2013)!• Support for Android* 4.3 (API level 18)• GCC-4.8 included with Silvermont™ tuning available (-

march=slm/-mtune=slm switches)• Bugfixes

19

Page 20: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Android* C++ supportBy default, libstdc++ is used. It lacks: - Standard C++ Library support (except some headers)- C++ exceptions support- RTTI support

Fortunately, you have other libs available with the NDK:

Runtime Exceptions RTTI STL

system No No No

gabi++ Yes Yes No

stlport Yes Yes Yes

gnustl Yes Yes Yes

Choose which library to compile against in your Makefile (Application.mk file):

APP_STL := gnustl_shared

Postfix the runtime with _static or _shared

For using C++ features, you also need to enable these in your Makefile:LOCAL_CPP_FEATURES += exceptions rtti

20

Page 21: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Why should I update GCC x86 compiler?EEMBC® CoreMark® example(higher = better)

• base: • -O2 -ffast-math -mfpmath=sse -m32 -march=atom

• base + if conversion• -O2 -ffast-math -mfpmath=sse -ftree-loop-if-convert -

m32 -march=atom

• peak• -Ofast -funroll-loops -mfpmath=sse -m32 -

march=atom

for 4.4 and 4.5 versions “-Ofast” is replaced with -O3 -ffast-math

http://software.intel.com/en-us/blogs/2013/05/28/why-should-i-update-gcc-x86-compiler-or-gcc-compiler-performance-on-intel-atom-from

21

Page 22: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Recommended GCC compiler options

• Optimization level:• use -O2 at least, -Ofast for peak

• Architecture:• -march=atom –mtune=atom –mssse3 to target Atom• -march=slm –mtune=slm –msse4.2 to target Silvermont• Note: -march=atom turns on -mmovbe which is not supported on all x86. To

avoid add –mno-movbe.

• Math:• -ffast-math – fast but less accurate. Usually you don’t care• -mfpmath=sse – use sse for FP calculations instead of i387

• Even more performance:• -flto

• -funroll-loops

More: http://software.intel.com/blogs/2012/09/26/gcc-x86-performance-hints

22

Page 23: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Recommended ICC compiler options

• Optimization level:• -O2 is default, -fast for peak (implies -static)

• Architecture:• -xATOM_SSSE3 to target Atom• -xATOM_SSE4.2 to target Silvermont (not available yet in 13.0)

• Math:• -no-prec-div – fast but less accurate. Usually you don’t care• -mfpmath=sse – use sse for FP calculations instead of i387

• Even more performance:• -O3• -ansi-alias

• -ipo• -auto-p32• -parallel

23

Page 24: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Agenda

• Where we are on Android*

• Tools to start development on IA

• Get full speed with Android* NDK

• Tips and tricks on porting from ARM* to IA

• Resources and contacts

24

Page 25: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Compatibility

• You already done for Java & HTML• NDK based apps usually just needs a recompilation

“I want my app to run on all architectures”

APP_ABI := all

Application.mk

25

Page 26: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Target compiler options

• NDK-build system Android.mk file evaluated for each architecture

• Variable TARGET_ARCH_ABI describes actual architecture

TARGET_ARCH_ABI

x86

armeabi

armeabi-v7a

mips

ifeq ($(TARGET_ARCH_ABI),x86)LOCAL_CFLAGS := -mtune=atom -mssse3endif

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)LOCAL_CFLAGS := -march=armv7-aEndif

Android.mk

26

Page 27: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Compiler macros

• Directly inside source code• No runtime overhead• Works with all build configurations

#ifdef __i386__strlcat(buf, "__i386__", sizeof(buf));

#endif#ifdef __arm__

strlcat(buf, "__arm__", sizeof(buf));#endif#ifdef __mips__

strlcat(buf, "__mips__", sizeof(buf));

#endif

source.c

27

Page 28: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Porting Native (C/C++) Android* Apps to x86

Native Apps

• Optimized NDK for Intel Atom based devices available on http://developer.android.com/sdk/ndk/index.html since July’11.

• For most apps, changing the make file and a recompile should be sufficient to port to Intel Atom devices.

• If ARM-specific features are used, Intel SSE equivalents should be added (build flag)

• Developer recompiles, re-packages and publishes.

http://software.intel.com/en-us/articles/ndk-android-application-porting-methodologies/

28

Page 29: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

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;};

29

Page 30: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

ARM* NEON to Intel® SSE

• Single Instruction Multiple Data (SIMD)• Most ARM NEON functions have a 1:1 equivalent in

Intel® SSE• Intel provides C++ header file to do the mapping

http://software.intel.com/en-us/blogs/2012/12/12/from-arm-neon-to-intel-mmxsse-automatic-porting-solution-tips-and-tricks

// VADD.I8 d0,d0,d0int8x8_t vadd_s8(int8x8_t a, int8x8_t b); #ifdef USE_MMX

#define vadd_s8 _mm_add_pi8 //MMX#else

#define vadd_s8 _mm_add_epi8#endif

NEONtoSSE.h

30

Page 31: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Agenda

• Where we are on Android*

• Tools to start development on IA

• Get full speed with Android* NDK

• Tips and tricks on porting from ARM* to IA

• Resources and contacts

31

Page 32: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Beacon Mountain on the WebYour Source for Beacon Mountain Information & Support

Free Download

Product Brief

Support Form

Follow us

@IntelSoftware

Free download at:intel.com/software/BeaconMountain

32

Page 33: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

For More Information on Individual ToolsPRODUCT URL Intel® Hardware Accelerated Execution Manager

http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager

Intel® Graphics Performance Analyzers www.intel.com/software/gpa

Intel® Threading Building Blocks software.intel.com/vcsource/tools/threading-building-blocks

Intel® Integrated Performance Primitives software.intel.com/intel-ipp

Intel® Software Manager www.software.intel.com

Google* Android* SDK www.developer.android.com

Android* NDK for x86 www.developer.android.com

Eclipse* Integrated Development Environment http://www.eclipse.org/

Android* Design www.developer.android.com

Cygwin* http://cygwin.com/

Oracle* Java SE Development Kit www.oracle.com

33

Page 34: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

Single entry point to remember

http://software.intel.com/android/

34

Page 35: Павел Чупин_Development and optimization android x86 applications от Intel

Copyright© 2013, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

INFORMATION IN THIS DOCUMENT IS PROVIDED “AS IS”. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO THIS INFORMATION INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products.

Copyright © , Intel Corporation. All rights reserved. Intel, the Intel logo, Xeon, Xeon Phi, Core, VTune, and Cilk are trademarks of Intel Corporation in the U.S. and other countries.

Optimization Notice

Intel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804

Legal Disclaimer & Optimization Notice

Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners.

35

Page 36: Павел Чупин_Development and optimization android x86 applications от Intel