kics2013-winter-biomp-slide-20130127-1340
TRANSCRIPT
05/01/2023 11:26 PM
BioMP: 안드로이드 플랫폼이 멀티코어를 인지할 수 있도록OpenMP 를 Bionic 에 동작시키는 기술에 관한 연구
Geunsik Limhttp://leemgs.fedorapeople.org
Sungkyunkwan UniversitySamsung Electronics Co., Ltd.
2/13
Introduction Design and Implementation Evaluation Related works Conclusion
Outline
3/13
Introduction1) CPU 와 Memory 가 제한적인 임베디드 디바이스에서 애플리케이션 스토어의 등장
2) 고성능 및 저전력을 위하여 임베디드 디바이스에 멀티코어의 채택
3) 기존에 이미 개발된 대용량 애플리케이션을 멀티코어 환경에 맞도록 개선하기 위한 기술이 중요
High-perfor-mance Appli-cations
싱글코어 듀얼코어 쿼드코어
4/13
Introduction
19881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
Chare Kernel
Threaded-C
JSR-166
STAPL
ECMA CLI
McRT
OpenMP 1.0
OpenMP 2.0
For C/C++
OpenMP 2.5
OpenMP 3.0
OpenMP 3.1
Intel TBB 1.0
Intel TBB 2.0
Intel TBB 3.0
Intel TBB 4.0
Intel Ct
+ RapidMindIntel ArBB
beta
Beta End
Cilk (MIT)
Cilk++Intel Cilk
Plus
CUDA 1.0OpenCL 1.0
MS PPLOpenCL 1.2CUDA 4.1
Intel Parallel Building Blocks
* Source : 글로벌 활용사례와 함께하는 TBB 도입전략 , WikiPedia
Evolution of Parallel Programming
OpenMP 4.1 RC1
5/13
Architecture of BioMP
DVFS-aware OpenMP
Toolchain for Android NDK (--enable-
libgomp)
Bionic
Dalvik VM JNI Inter-face
Multicore H/W
Multicore –Aware Android Java Applications
Multicore Scheduler
Functional Library Layer(C/C++ Native Libraries) Biomp
Auto-Build-Manaer
ARM Cus-tomizer
Deubgger Component
Android NDK8
Automatic Parallelizer
sysfs
omp_get_thread_num()
6/13
Implementation of BioMP
ARM EABI interface (ANDROID_LIB_SPEC GNU_USER_TARGET_LIB_SPEC )
Linux Android(Bind with Android C library)
OpenMP for Bionic(pthread: -lc)
Env. for OpenMP(Setting with android page
size)
Step 1
BioMP Core
DVFS-aware Plug-in(omp_get_thread_num with sysfs)
Android Applica-tion
(By linking biomp)
BioMP Core BioMP Framework
Step 2 Step 3
BioMP Framework BioMP System
7/13
Source codes for BioMP • http://biomp.googlecode.-com
GCC CommunityAOSP Community
Linaro Community
8/13
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Here we give our module name and source file(s)LOCAL_MODULE := streamLOCAL_SRC_FILES := stream.cLOCAL_LDLIBS := -lgomp
LOCAL_CFLAGS := -O3 -fopenmp #include $(BUILD_SHARED_LIBRARY)include $(BUILD_EXECUTABLE)
How to write a source codeA tests/device/test-openmp/BROKEN_BUILD 1 lineA tests/device/test-openmp/jni/Android.mk 9 linesA tests/device/test-openmp/jni/Application.mk 1 lineA tests/device/test-openmp/jni/openmp.c 22 lines
9/13
$ cat ./openmptest.c #include <omp.h> /* for openmap */#include <stdio.h> int main (int argc, char *argv[ ]) { int id, nthreads; #pragma omp parallel private(id) { id = omp_get_thread_num(); printf("Hello World from thread %d n", id); #pragma omp barrier if ( id == 0 ) { nthreads = omp_get_num_threads(); printf("There are %d threadsn",nthreads); } } return 0; } /* end of main() */
How to write a source code
$ ./arm-linux-androideabi-gcc openmptest.c -L/usr/local/ktoolchain-cortexa9-ver2.5-20120515-bionic/arm-linux-androideabi/lib -lgomp -o openmptest [ENTER]$$ file ./openmptest./openmptest: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped$
10/13
An example of 40 pieces of Fibonacci numbers - http://en.wikipedia.org/wiki/Fibonacci_number
How to write a source code for evalua-tion
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <omp.h>#include <unistd.h> /* for open/close.. */#include <fcntl.h> /* for O_RDONLY */#include <sys\ioctl.h> /* for ioctl */#include <sys\types.h> /* for lseek() */
int Fibonacci(int n){ int x, y; if (n < 2) return n; else { x = Fibonacci(n - 1); y = Fibonacci(n - 2); return (x + y);} }
int FibonacciTask(int n){ int x, y; if (n < 2) return n; else {#pragma omp task shared(x) x = Fibonacci(n - 1);#pragma omp task shared(y) y = Fibonacci(n - 2);#pragma omp taskwait return (x + y); } }
#define MAX 41int main(int argc, char * argv[]){ int FibNumber[MAX] = {0}; struct timeval time_start, time_end; int i = 0; // omp related print message printf(\"Number of CPUs=%d\n\", omp_get_num_procs()); printf(\"Number of max threads=%d\n\", omp_get_max_threads());
gettimeofday(&time_start, NULL);#pragma omp parallel {#pragma omp single private(i) for(i = 1; i < MAX; i++) { FibNumber[i] = FibonacciTask(i); } } gettimeofday(&time_end, NULL);
time_end.tv_usec = time_end.tv_usec-time_start.tv_usec; time_end.tv_sec = time_end.tv_sec-time_start.tv_sec; time_end.tv_usec += (time_end.tv_sec*1000000); printf(\"Time of Fibonacci with OpenMP : %lf sec\n\", time_end.tv_usec / 1000000.0);
for(i = 0; i < MAX; i++) printf(\"%d \", FibNumber[i]); printf(\"\n--------------------------------------\n\"); return
(1)
(2)
(3)
11/13
Evaluation
Singlecore Dualcore Quadcore0
1
2
3
4
5
6
7
8
Fibonacci comparison between before (w/o biomp) and after (w/ biomp)
Exec
utio
n Ti
me
(Sec
onds
)
• 40 numbers of Fibonacci sequence
41% reduced over Singlecore
64% reduced over Sin-glecore
12/13
Related Works
Ap-proach
Merits Demerits
BioMP • 기존 코드를 재 사용할 수 있다 . • BioMP 을 사용하기 위해서 플랫폼의 변경이 필요없다 . ( 플랫폼의 수정 필요없이 안드로이드 앱개발자들이 BioMP /JNI 를 사용하여 구글스토어에서 앱을 판매할수 있도록 돕는다 . )• 자바 애플리케이션 레벨에서 BioMP 를 적용가능하다 . • 오픈소스이다 .
• 고급 병렬화를 위해서는 OpenMP 에 대한 깊은 지식이 필요하다 .
OpenMP • 기존 코드를 재 사용할 수 있다 . • 오픈소스이다 .
• 안드로이드 플랫폼에서는 지원하지 않는다 . • 고급 병렬화를 위해서는 OpenMP 에 대한 깊은 지식이 필요하다 .
Bionic • pthread 프로그래밍을 통해 쓰레드 애플리케이션의 Portability 를 높일수 있다 .• 오픈소스이다 .
• pthread API 를 이용하여 병렬화 프로그래밍을 하려면 쉽지 않다 . • 기존의 작성된 코드를 멀티코어에 맞게 수정하려면 많은 시간이 소요된다 .
13/13
Threaded Applications for Task Parallelism
Future Work
OPenMP on Bionic
CPU0 CPU1 CPU2 CPU3
On-line
On-line
Off -line
Off -line
Linux Kernel
T0 T0 T0 T0 T0
CPU DVFSCPU Hot-
Plug
BEFORE
Threaded Applications for Task Parallelism
OPenMP on Bionic
CPU0 CPU1 CPU2 CPU3
On-line
On-line
Off -line
Off -line
Linux Kernel
T0 T0 T0 T0 T0
CPU DVFSCPU Hot-
Plug
AFTER
sysFS
BioMP Agent
It Recognize Tem-poral Offline CPUs
OOPS!!! It doesn’t Recognizing Tem-poral Offline CPUs
?/proc/
cpuinfo
DVFS-Aware BioMP for Mobile Devices
Galaxy Nexus7
Galaxy Nexus7
User-Space
Kernel-Space
Hardware
User-Space
Kernel-Space
Hardware
14/13
Conclusion
1. BioMP 는 툴체인 기술에 기반하는 모듈방식의 시스템이므로 안드로이드 플랫폼의 어떠한 수정도 필요치 않다 .
2. 안드로이드 NDK Toolkit 과 BioMP 를 이용하여 자바 애플리케이션 레벨에서의 병렬화한 소프트웨어를 앱스토어에 업로드 / 다운로드 실행이 가능하다 .
3. 오픈소스이므로 , (biomp.googlecode.com) 추가적인 아이디어를 자유롭게 수정하여 활용할 수 있다 .
15/13
ThanksAny questions?