SlideShare a Scribd company logo
1 of 30
Download to read offline
How to Use OpenMP on Native Activity
Noritsuna Imamura
noritsuna@siprop.org

©SIProp Project, 2006-2008

1
What’s Parallelizing Compiler?
Automatically Parallelizing Compiler
Don’t Need “Multi-Core” programming,
Compiler automatically modify “Multi-Core” Code.
Intel Compiler
Only IA-Arch

OSCAR(http://www.kasahara.elec.waseda.ac.jp)
Not Open

Hand Parallelizing Compiler
Need to Make “Multi-Core” programming,
But it’s easy to Make “Multi-Core” Code.
“Multi-Thread” Programming is so Hard.
Linda
Original Programming Language

OpenMP

©SIProp Project, 2006-2008

2
OpenMP

©SIProp Project, 2006-2008

3
What’s OpenMP?
Most Implemented Hand Parallelizing Compiler.
Intel Compiler, gcc, …
※If you use “parallel” option to compiler, OpenMP compile
Automatically Parallelizing.

Model: Join-Fork
Memory: Relaxed-Consistency

Documents
http://openmp.org/
http://openmp.org/wp/openmp-specifications/

©SIProp Project, 2006-2008

4
OpenMP Extensions

Parallel Control Structures
OpenMP Statement

Work Sharing, Synchronization
Thread Controlling

Data Environment
Value Controlling

Runtime
Tools
©SIProp Project, 2006-2008

5
OpenMP Syntax & Behavor
OpenMP Statements
parallel
single
Do Only 1 Thread

Worksharing Statements
for
Do for by Thread

sections
Separate Statements &
Do Once

single
Do Only 1 Thread

Clause
if (scalar-expression)
if statement

private(list)
{first|last}private(list)
Value is used in sections
only

shared(list)
Value is used Global

reduction({operator |
intrinsic_procedure_name}:
list)
Combine Values after All
Thread

schedule(kind[, chunk_size])
How about use Thread
©SIProp Project, 2006-2008

6
How to Use
“#pragma omp” + OpenMP statement
Ex. “for” statement parallelizing.
1.
2.
3.
4.

1.
2.
3.
4.
5.
6.

#pragma omp parallel for
for(int i = 0; i < 1000; i++) {
// your code
}

int cpu_num = step = omp_get_num_procs();
for(int i = 0; i < cpu_num; i++) {
START_THREAD {
FOR_STATEMENT(int j = i; j < xxx; j+step);
}
}
©SIProp Project, 2006-2008

7
IplImage Benchmark by OpenMP
IplImage
Write 1 line only

Device
Nexus7(2013)
4 Core

1.
2.
3.
4.
5.
6.
7.
8.
9.

IplImage* img;
#pragma omp parallel for
for(int h = 0; h < img->height; h++) {
for(int w = 0; w < img->width; w++){
img->imageData[img->widthStep * h + w * 3 + 0]=0;//B
img->imageData[img->widthStep * h + w * 3 + 1]=0;//G
img->imageData[img->widthStep * h + w * 3 + 2]=0;//R
}
}
©SIProp Project, 2006-2008

8
Hands On

©SIProp Project, 2006-2008

9
Hand Detector
Sample Source Code:
http://github.com/noritsuna/HandDetectorOpenMP

©SIProp Project, 2006-2008

10
Chart of Hand Detector
Calc Histgram of
Skin Color

Histgram

Detect Skin Area
from CapImage

Convex Hull

Calc the Largest
Skin Area

Labeling

Matching
Histgrams

Feature Point
Distance
©SIProp Project, 2006-2008

11
Android.mk
Add C & LD flags

1.
2.

LOCAL_CFLAGS += -O3 -fopenmp
LOCAL_LDFLAGS +=-O3 -fopenmp

©SIProp Project, 2006-2008

12
Why Use HoG?
Matching Hand Shape.
Use Feature Point Distance with Each HoG.

©SIProp Project, 2006-2008

13
Step 1/3
Calculate each Cell (Block(3x3) with Edge Pixel(5x5))
luminance gradient moment
luminance gradient degree=deg
1.
2.
3.
4.
5.
6.
7.

8.
9.
10.
11.
12.
13.
14.
15.
16.

#pragma omp parallel for
for(int y=0; y<height; y++){
for(int x=0; x<width; x++){
if(x==0 || y==0 || x==width-1 || y==height-1){
continue;
}
double dx = img->imageData[y*img>widthStep+(x+1)] - img->imageData[y*img->widthStep+(x-1)];
double dy = img->imageData[(y+1)*img>widthStep+x] - img->imageData[(y-1)*img->widthStep+x];
double m = sqrt(dx*dx+dy*dy);
double deg = (atan2(dy, dx)+CV_PI) * 180.0 / CV_PI;
int bin = CELL_BIN * deg/360.0;
if(bin < 0) bin=0;
if(bin >= CELL_BIN) bin = CELL_BIN-1;
hist[(int)(x/CELL_X)][(int)(y/CELL_Y)][bin] += m;
}
©SIProp Project, 2006-2008
}

14
Step 2/3
Calculate Feature Vector of Each Block
(Go to Next Page)

1.
2.
3.

#pragma omp parallel for
for(int y=0; y<BLOCK_HEIGHT; y++){
for(int x=0; x<BLOCK_WIDTH; x++){

4.
5.
6.
7.
8.
9.
10.

//Calculate Feature Vector in Block
double vec[BLOCK_DIM];
memset(vec, 0, BLOCK_DIM*sizeof(double));
for(int j=0; j<BLOCK_Y; j++){
for(int i=0; i<BLOCK_X; i++){
for(int d=0; d<CELL_BIN; d++){
int index =
j*(BLOCK_X*CELL_BIN) + i*CELL_BIN + d;
vec[index] =
hist[x+i][y+j][d];
}
}
}

11.
12.
13.
14.

©SIProp Project, 2006-2008

15
How to Calc Approximation
Calc HoG Distance of each block
Get Average.

©SIProp Project, 2006-2008

16
Step 1/1
𝑇𝑂𝑇𝐴𝐿_𝐷𝐼𝑀
|(𝑓𝑒𝑎𝑡1
𝑖=0

1.
2.
3.
4.
5.
6.

𝑖 − 𝑓𝑒𝑎𝑡2 𝑖 )2 |

double dist = 0.0;
#pragma omp parallel for reduction(+:dist)
for(int i = 0; i < TOTAL_DIM; i++){
dist += fabs(feat1[i] - feat2[i])*fabs(feat1[i]
- feat2[i]);
}
return sqrt(dist);
©SIProp Project, 2006-2008

17
However…
Currently NDK(r9c) has Bug…
http://recursify.com/blog/2013/08/09/openmp-onandroid-tls-workaround
libgomp.so has bug…

Need to Re-Build NDK…
or Waiting for Next Version NDK
1.
2.
3.
4.
5.
6.

double dist = 0.0;
#pragma omp parallel for reduction(+:dist)
for(int i = 0; i < TOTAL_DIM; i++){
dist += fabs(feat1[i] - feat2[i])*fabs(feat1[i]
- feat2[i]);
}
return sqrt(dist);
©SIProp Project, 2006-2008

18
How to Build NDK 1/2
1. Download Linux Version NDK on Linux
2. cd [NDK dir]
3. Download Source Code & Patches
1. ./build/tools/download-toolchain-sources.sh src
2. wget
http://recursify.com/attachments/posts/2013-0809-openmp-on-android-tlsworkaround/libgomp.h.patch
3. wget
http://recursify.com/attachments/posts/2013-0809-openmp-on-android-tlsworkaround/team.c.patch
©SIProp Project, 2006-2008

19
How to Build NDK 2/2
Patch to Source Code
cd & copy patches to ./src/gcc/gcc-4.6/libgomp/
patch -p0 < team.c.patch
patch -p0 < libgomp.h.patch
cd [NDK dir]

Setup Build-Tools
sudo apt-get install texinfo

Build Linux Version NDK
./build/tools/build-gcc.sh --verbose $(pwd)/src
$(pwd) arm-linux-androideabi-4.6

©SIProp Project, 2006-2008

20
How to Build NDK for Windows 1/4
1. Fix Download Script “./build/tools/buildmingw64-toolchain.sh”
1.

1.

1.

1.

run svn co https://mingww64.svn.sourceforge.net/svnroot/mingww64/trunk$MINGW_W64_REVISION $MINGW_W64_SRC
↓
run svn co svn://svn.code.sf.net/p/mingww64/code/trunk/@5861 mingw-w64-svn $MINGW_W64_SRC
MINGW_W64_SRC=$SRC_DIR/mingw-w64svn$MINGW_W64_REVISION2
↓
MINGW_W64_SRC=$SRC_DIR/mingw-w64svn$MINGW_W64_REVISION2/trunk
※My Version is Android-NDK-r9c
©SIProp Project, 2006-2008

21
How to Build NDK for Windows 2/4
1. Download MinGW
1. 32-bit
1.
2.

3.

./build/tools/build-mingw64-toolchain.sh --targetarch=i686
cp -a /tmp/build-mingw64-toolchain-$USER/installx86_64-linux-gnu/i686-w64-mingw32 ~
export PATH=$PATH:~/i686-w64-mingw32/bin

2. 64-bit
1.
2.
3.

./build/tools/build-mingw64-toolchain.sh --force-build
cp -a /tmp/build-mingw64-toolchain-$USER/installx86_64-linux-gnu/x86_64-w64-mingw32 ~/
export PATH=$PATH:~/x86_64-w64-mingw32/bin

©SIProp Project, 2006-2008

22
How to Build NDK for Windows 3/4
Download Pre-Build Tools
32-bit
git clone
https://android.googlesource.com/platform/prebuilts/gcc/li
nux-x86/host/i686-linux-glibc2.7-4.6
$(pwd)/../prebuilts/gcc/linux-x86/host/i686-linux-glibc2.74.6

64-bit
git clone
https://android.googlesource.com/platform/prebuilts/tools
$(pwd)/../prebuilts/tools
git clone
https://android.googlesource.com/platform/prebuilts/gcc/li
nux-x86/host/x86_64-linux-glibc2.7-4.6
$(pwd)/../prebuilts/gcc/linux-x86/host/x86_64-linuxglibc2.7-4.6
©SIProp Project, 2006-2008

23
How to Build NDK for Windows 4/4
Build Windows Version NDK
Set Vars
export ANDROID_NDK_ROOT=[AOSP's NDK dir]

32-bit
./build/tools/build-gcc.sh --verbose --mingw $(pwd)/src
$(pwd) arm-linux-androideabi-4.6

64-bit
./build/tools/build-gcc.sh --verbose --mingw --try-64
$(pwd)/src $(pwd) arm-linux-androideabi-4.6

©SIProp Project, 2006-2008

24
NEON

©SIProp Project, 2006-2008

25
Today’s Topic

Compiler
≠ Not Thread Programming

©SIProp Project, 2006-2008

26
Parallelizing Compiler for NEON
ARM DS-5 Development Studio
Debugger for Linux/Android™/RTOS-aware
The ARM Streamline system-wide performance analyzer
Real-Time system model Simulators
All conveniently Packaged in Eclipse.
http://www.arm.com/products/tools/software-tools/ds5/index.php

©SIProp Project, 2006-2008

27
IDE

©SIProp Project, 2006-2008

28
Analyzer

©SIProp Project, 2006-2008

29
Parallelizing Compiler for NEON No.2
gcc
Android uses it.

How to Use
Android.mk
1.

LOCAL_CFLAGS += -O3 -ftree-vectorize mvectorize-with-neon-quad

Supported Arch
1.

APP_ABI := armeabi-v7a
©SIProp Project, 2006-2008

30

More Related Content

What's hot

BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話Kohei Tokunaga
 
eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動Kohei Tokunaga
 
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
The overview of lazypull with containerd Remote Snapshotter & Stargz SnapshotterThe overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
The overview of lazypull with containerd Remote Snapshotter & Stargz SnapshotterKohei Tokunaga
 
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動するStargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動するKohei Tokunaga
 
Starting up Containers Super Fast With Lazy Pulling of Images
Starting up Containers Super Fast With Lazy Pulling of ImagesStarting up Containers Super Fast With Lazy Pulling of Images
Starting up Containers Super Fast With Lazy Pulling of ImagesKohei Tokunaga
 
containerdの概要と最近の機能
containerdの概要と最近の機能containerdの概要と最近の機能
containerdの概要と最近の機能Kohei Tokunaga
 
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話katsuya kawabe
 
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy PullingFaster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy PullingKohei Tokunaga
 
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...Kohei Tokunaga
 
Startup Containers in Lightning Speed with Lazy Image Distribution
Startup Containers in Lightning Speed with Lazy Image DistributionStartup Containers in Lightning Speed with Lazy Image Distribution
Startup Containers in Lightning Speed with Lazy Image DistributionKohei Tokunaga
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020 Bogusz Jelinski
 
DockerとKubernetesをかけめぐる
DockerとKubernetesをかけめぐるDockerとKubernetesをかけめぐる
DockerとKubernetesをかけめぐるKohei Tokunaga
 
Dev fest 2020 taiwan how to debug microservices on kubernetes as a pros (ht...
Dev fest 2020 taiwan   how to debug microservices on kubernetes as a pros (ht...Dev fest 2020 taiwan   how to debug microservices on kubernetes as a pros (ht...
Dev fest 2020 taiwan how to debug microservices on kubernetes as a pros (ht...KAI CHU CHUNG
 
The myths of deprecating docker in kubernetes
The myths of deprecating docker in kubernetesThe myths of deprecating docker in kubernetes
The myths of deprecating docker in kubernetesJo Hoon
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐KAI CHU CHUNG
 
Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)KAI CHU CHUNG
 
Reactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingReactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingYoshifumi Kawai
 
容器化後,持續交付不可缺的敲門磚 - Helm
容器化後,持續交付不可缺的敲門磚 - Helm容器化後,持續交付不可缺的敲門磚 - Helm
容器化後,持續交付不可缺的敲門磚 - HelmHung-Yen Chen
 
Lessons learned from the charts repo
Lessons learned from the charts repoLessons learned from the charts repo
Lessons learned from the charts repoVictor Iglesias
 

What's hot (20)

BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話BuildKitでLazy Pullを有効にしてビルドを早くする話
BuildKitでLazy Pullを有効にしてビルドを早くする話
 
eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動eStargzイメージとlazy pullingによる高速なコンテナ起動
eStargzイメージとlazy pullingによる高速なコンテナ起動
 
Resume
ResumeResume
Resume
 
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
The overview of lazypull with containerd Remote Snapshotter & Stargz SnapshotterThe overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
The overview of lazypull with containerd Remote Snapshotter & Stargz Snapshotter
 
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動するStargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
Stargz Snapshotter: イメージのpullを省略しcontainerdでコンテナを高速に起動する
 
Starting up Containers Super Fast With Lazy Pulling of Images
Starting up Containers Super Fast With Lazy Pulling of ImagesStarting up Containers Super Fast With Lazy Pulling of Images
Starting up Containers Super Fast With Lazy Pulling of Images
 
containerdの概要と最近の機能
containerdの概要と最近の機能containerdの概要と最近の機能
containerdの概要と最近の機能
 
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話
【CNDO2021】Calicoのデプロイをミスって本番クラスタを壊しそうになった話
 
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy PullingFaster Container Image Distribution on a Variety of Tools with Lazy Pulling
Faster Container Image Distribution on a Variety of Tools with Lazy Pulling
 
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
 
Startup Containers in Lightning Speed with Lazy Image Distribution
Startup Containers in Lightning Speed with Lazy Image DistributionStartup Containers in Lightning Speed with Lazy Image Distribution
Startup Containers in Lightning Speed with Lazy Image Distribution
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
DockerとKubernetesをかけめぐる
DockerとKubernetesをかけめぐるDockerとKubernetesをかけめぐる
DockerとKubernetesをかけめぐる
 
Dev fest 2020 taiwan how to debug microservices on kubernetes as a pros (ht...
Dev fest 2020 taiwan   how to debug microservices on kubernetes as a pros (ht...Dev fest 2020 taiwan   how to debug microservices on kubernetes as a pros (ht...
Dev fest 2020 taiwan how to debug microservices on kubernetes as a pros (ht...
 
The myths of deprecating docker in kubernetes
The myths of deprecating docker in kubernetesThe myths of deprecating docker in kubernetes
The myths of deprecating docker in kubernetes
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)Devfest 2021' - Artifact Registry Introduction (Taipei)
Devfest 2021' - Artifact Registry Introduction (Taipei)
 
Reactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingReactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event Processing
 
容器化後,持續交付不可缺的敲門磚 - Helm
容器化後,持續交付不可缺的敲門磚 - Helm容器化後,持續交付不可缺的敲門磚 - Helm
容器化後,持續交付不可缺的敲門磚 - Helm
 
Lessons learned from the charts repo
Lessons learned from the charts repoLessons learned from the charts repo
Lessons learned from the charts repo
 

Viewers also liked

Android based Object Detection and Classification
Android based Object Detection and ClassificationAndroid based Object Detection and Classification
Android based Object Detection and Classificationmatthewlweber
 
Семинар 7. Многопоточное программирование на OpenMP (часть 7)
Семинар 7. Многопоточное программирование на OpenMP (часть 7)Семинар 7. Многопоточное программирование на OpenMP (часть 7)
Семинар 7. Многопоточное программирование на OpenMP (часть 7)Mikhail Kurnosov
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsZvi Avraham
 
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel Software Brasil
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Luigi De Russis
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Luigi De Russis
 

Viewers also liked (9)

Scheduling for Parallel and Multi-Core Systems
Scheduling for Parallel and Multi-Core SystemsScheduling for Parallel and Multi-Core Systems
Scheduling for Parallel and Multi-Core Systems
 
Android based Object Detection and Classification
Android based Object Detection and ClassificationAndroid based Object Detection and Classification
Android based Object Detection and Classification
 
將DNA在廚房抽出的程序
將DNA在廚房抽出的程序將DNA在廚房抽出的程序
將DNA在廚房抽出的程序
 
Семинар 7. Многопоточное программирование на OpenMP (часть 7)
Семинар 7. Многопоточное программирование на OpenMP (часть 7)Семинар 7. Многопоточное программирование на OpenMP (часть 7)
Семинар 7. Многопоточное программирование на OpenMP (часть 7)
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
Introduccion a MPI
Introduccion a MPIIntroduccion a MPI
Introduccion a MPI
 
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013Intel® MPI Library e OpenMP* - Intel Software Conference 2013
Intel® MPI Library e OpenMP* - Intel Software Conference 2013
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)Introduction to OpenCV 3.x (with Java)
Introduction to OpenCV 3.x (with Java)
 

Similar to How to Use OpenMP on Native Activity

OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfOpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfssuser866937
 
Open Kode, Airplay And The New Reality Of Write Once Run Anywhere
Open Kode, Airplay And The New Reality Of Write Once Run AnywhereOpen Kode, Airplay And The New Reality Of Write Once Run Anywhere
Open Kode, Airplay And The New Reality Of Write Once Run Anywhereguest991eb3
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Kiwamu Okabe
 
Lecture02web 140phpapp01
Lecture02web 140phpapp01Lecture02web 140phpapp01
Lecture02web 140phpapp01letuan9999
 
Metasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OSMetasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OSKiwamu Okabe
 
Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For DevelopmentLaura Frank Tacho
 
EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18Xiaoli Liang
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIYoni Davidson
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceIntel® Software
 
Metasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDKMetasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDKKiwamu Okabe
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersAlexandre Moneger
 
React native development with expo
React native development with expoReact native development with expo
React native development with expoSangSun Park
 
Eclipse Training - RCP & Industrialization
Eclipse Training - RCP & IndustrializationEclipse Training - RCP & Industrialization
Eclipse Training - RCP & IndustrializationLuca D'Onofrio
 
GNAT GPL For Mindstorms
GNAT GPL For MindstormsGNAT GPL For Mindstorms
GNAT GPL For MindstormsAdaCore
 
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Embarcados
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkitCocoaHeads Tricity
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 

Similar to How to Use OpenMP on Native Activity (20)

OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfOpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
 
Open Kode, Airplay And The New Reality Of Write Once Run Anywhere
Open Kode, Airplay And The New Reality Of Write Once Run AnywhereOpen Kode, Airplay And The New Reality Of Write Once Run Anywhere
Open Kode, Airplay And The New Reality Of Write Once Run Anywhere
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"
 
Lecture02web 140phpapp01
Lecture02web 140phpapp01Lecture02web 140phpapp01
Lecture02web 140phpapp01
 
Metasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OSMetasepi team meeting #7: Snatch application on tiny OS
Metasepi team meeting #7: Snatch application on tiny OS
 
Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For Development
 
EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18EclipseOMRBuildingBlocks4Polyglot_TURBO18
EclipseOMRBuildingBlocks4Polyglot_TURBO18
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
The Next Leap in JavaScript Performance
The Next Leap in JavaScript PerformanceThe Next Leap in JavaScript Performance
The Next Leap in JavaScript Performance
 
Metasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDKMetasepi team meeting #8': Haskell apps on Android NDK
Metasepi team meeting #8': Haskell apps on Android NDK
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
 
React native development with expo
React native development with expoReact native development with expo
React native development with expo
 
Eclipse Training - RCP & Industrialization
Eclipse Training - RCP & IndustrializationEclipse Training - RCP & Industrialization
Eclipse Training - RCP & Industrialization
 
GNAT GPL For Mindstorms
GNAT GPL For MindstormsGNAT GPL For Mindstorms
GNAT GPL For Mindstorms
 
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
Webinar: Começando seus trabalhos com Machine Learning utilizando ferramentas...
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院)

More from Industrial Technology Research Institute (ITRI)(工業技術研究院, 工研院) (20)

What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?What is the world where you can make your own semiconductors?
What is the world where you can make your own semiconductors?
 
半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!半導体製造(TinyTapeout)に挑戦しよう!
半導体製造(TinyTapeout)に挑戦しよう!
 
Introduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPWIntroduction of ISHI-KAI with OpenMPW
Introduction of ISHI-KAI with OpenMPW
 
Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会Kernel/VMレイヤーを自分色に染める!By ISHI会
Kernel/VMレイヤーを自分色に染める!By ISHI会
 
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPiPrinciple Representation of The 8 Qubits Quantum Computer by RaspberryPi
Principle Representation of The 8 Qubits Quantum Computer by RaspberryPi
 
Microwaveguquantum
MicrowaveguquantumMicrowaveguquantum
Microwaveguquantum
 
The easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on WindowsThe easiest way of setup QuTiP on Windows
The easiest way of setup QuTiP on Windows
 
GNU Radio Study for Super beginner
GNU Radio Study for Super beginnerGNU Radio Study for Super beginner
GNU Radio Study for Super beginner
 
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
The Self-Contained SDR Satellite Grand Station with Raspberry Pi 3
 
Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3Self‐Contained SDR Grand Station with Raspberry Pi 3
Self‐Contained SDR Grand Station with Raspberry Pi 3
 
衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記衛星追尾用パラボラアンテナ建設記
衛星追尾用パラボラアンテナ建設記
 
All list of the measuring machines for microwave
All list of the measuring machines for microwaveAll list of the measuring machines for microwave
All list of the measuring machines for microwave
 
5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局5000円で誰でも作れる新世代衛星地上局
5000円で誰でも作れる新世代衛星地上局
 
How to setup mastodon in chinese
How to setup mastodon in chineseHow to setup mastodon in chinese
How to setup mastodon in chinese
 
Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-Radiation Test -Raspberry PI Zero-
Radiation Test -Raspberry PI Zero-
 
Protocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in KitchenProtocol of the DNA Extraction in Kitchen
Protocol of the DNA Extraction in Kitchen
 
3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop3D Printed Google Cardboard for workshop
3D Printed Google Cardboard for workshop
 
計算機(物理)
計算機(物理)計算機(物理)
計算機(物理)
 
How to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in ChineseHow to Make a Scanning Drone in Chinese
How to Make a Scanning Drone in Chinese
 
How to Make Android Native Application
How to Make Android Native ApplicationHow to Make Android Native Application
How to Make Android Native Application
 

Recently uploaded

20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 

Recently uploaded (20)

20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 

How to Use OpenMP on Native Activity

  • 1. How to Use OpenMP on Native Activity Noritsuna Imamura noritsuna@siprop.org ©SIProp Project, 2006-2008 1
  • 2. What’s Parallelizing Compiler? Automatically Parallelizing Compiler Don’t Need “Multi-Core” programming, Compiler automatically modify “Multi-Core” Code. Intel Compiler Only IA-Arch OSCAR(http://www.kasahara.elec.waseda.ac.jp) Not Open Hand Parallelizing Compiler Need to Make “Multi-Core” programming, But it’s easy to Make “Multi-Core” Code. “Multi-Thread” Programming is so Hard. Linda Original Programming Language OpenMP ©SIProp Project, 2006-2008 2
  • 4. What’s OpenMP? Most Implemented Hand Parallelizing Compiler. Intel Compiler, gcc, … ※If you use “parallel” option to compiler, OpenMP compile Automatically Parallelizing. Model: Join-Fork Memory: Relaxed-Consistency Documents http://openmp.org/ http://openmp.org/wp/openmp-specifications/ ©SIProp Project, 2006-2008 4
  • 5. OpenMP Extensions Parallel Control Structures OpenMP Statement Work Sharing, Synchronization Thread Controlling Data Environment Value Controlling Runtime Tools ©SIProp Project, 2006-2008 5
  • 6. OpenMP Syntax & Behavor OpenMP Statements parallel single Do Only 1 Thread Worksharing Statements for Do for by Thread sections Separate Statements & Do Once single Do Only 1 Thread Clause if (scalar-expression) if statement private(list) {first|last}private(list) Value is used in sections only shared(list) Value is used Global reduction({operator | intrinsic_procedure_name}: list) Combine Values after All Thread schedule(kind[, chunk_size]) How about use Thread ©SIProp Project, 2006-2008 6
  • 7. How to Use “#pragma omp” + OpenMP statement Ex. “for” statement parallelizing. 1. 2. 3. 4. 1. 2. 3. 4. 5. 6. #pragma omp parallel for for(int i = 0; i < 1000; i++) { // your code } int cpu_num = step = omp_get_num_procs(); for(int i = 0; i < cpu_num; i++) { START_THREAD { FOR_STATEMENT(int j = i; j < xxx; j+step); } } ©SIProp Project, 2006-2008 7
  • 8. IplImage Benchmark by OpenMP IplImage Write 1 line only Device Nexus7(2013) 4 Core 1. 2. 3. 4. 5. 6. 7. 8. 9. IplImage* img; #pragma omp parallel for for(int h = 0; h < img->height; h++) { for(int w = 0; w < img->width; w++){ img->imageData[img->widthStep * h + w * 3 + 0]=0;//B img->imageData[img->widthStep * h + w * 3 + 1]=0;//G img->imageData[img->widthStep * h + w * 3 + 2]=0;//R } } ©SIProp Project, 2006-2008 8
  • 10. Hand Detector Sample Source Code: http://github.com/noritsuna/HandDetectorOpenMP ©SIProp Project, 2006-2008 10
  • 11. Chart of Hand Detector Calc Histgram of Skin Color Histgram Detect Skin Area from CapImage Convex Hull Calc the Largest Skin Area Labeling Matching Histgrams Feature Point Distance ©SIProp Project, 2006-2008 11
  • 12. Android.mk Add C & LD flags 1. 2. LOCAL_CFLAGS += -O3 -fopenmp LOCAL_LDFLAGS +=-O3 -fopenmp ©SIProp Project, 2006-2008 12
  • 13. Why Use HoG? Matching Hand Shape. Use Feature Point Distance with Each HoG. ©SIProp Project, 2006-2008 13
  • 14. Step 1/3 Calculate each Cell (Block(3x3) with Edge Pixel(5x5)) luminance gradient moment luminance gradient degree=deg 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. #pragma omp parallel for for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ if(x==0 || y==0 || x==width-1 || y==height-1){ continue; } double dx = img->imageData[y*img>widthStep+(x+1)] - img->imageData[y*img->widthStep+(x-1)]; double dy = img->imageData[(y+1)*img>widthStep+x] - img->imageData[(y-1)*img->widthStep+x]; double m = sqrt(dx*dx+dy*dy); double deg = (atan2(dy, dx)+CV_PI) * 180.0 / CV_PI; int bin = CELL_BIN * deg/360.0; if(bin < 0) bin=0; if(bin >= CELL_BIN) bin = CELL_BIN-1; hist[(int)(x/CELL_X)][(int)(y/CELL_Y)][bin] += m; } ©SIProp Project, 2006-2008 } 14
  • 15. Step 2/3 Calculate Feature Vector of Each Block (Go to Next Page) 1. 2. 3. #pragma omp parallel for for(int y=0; y<BLOCK_HEIGHT; y++){ for(int x=0; x<BLOCK_WIDTH; x++){ 4. 5. 6. 7. 8. 9. 10. //Calculate Feature Vector in Block double vec[BLOCK_DIM]; memset(vec, 0, BLOCK_DIM*sizeof(double)); for(int j=0; j<BLOCK_Y; j++){ for(int i=0; i<BLOCK_X; i++){ for(int d=0; d<CELL_BIN; d++){ int index = j*(BLOCK_X*CELL_BIN) + i*CELL_BIN + d; vec[index] = hist[x+i][y+j][d]; } } } 11. 12. 13. 14. ©SIProp Project, 2006-2008 15
  • 16. How to Calc Approximation Calc HoG Distance of each block Get Average. ©SIProp Project, 2006-2008 16
  • 17. Step 1/1 𝑇𝑂𝑇𝐴𝐿_𝐷𝐼𝑀 |(𝑓𝑒𝑎𝑡1 𝑖=0 1. 2. 3. 4. 5. 6. 𝑖 − 𝑓𝑒𝑎𝑡2 𝑖 )2 | double dist = 0.0; #pragma omp parallel for reduction(+:dist) for(int i = 0; i < TOTAL_DIM; i++){ dist += fabs(feat1[i] - feat2[i])*fabs(feat1[i] - feat2[i]); } return sqrt(dist); ©SIProp Project, 2006-2008 17
  • 18. However… Currently NDK(r9c) has Bug… http://recursify.com/blog/2013/08/09/openmp-onandroid-tls-workaround libgomp.so has bug… Need to Re-Build NDK… or Waiting for Next Version NDK 1. 2. 3. 4. 5. 6. double dist = 0.0; #pragma omp parallel for reduction(+:dist) for(int i = 0; i < TOTAL_DIM; i++){ dist += fabs(feat1[i] - feat2[i])*fabs(feat1[i] - feat2[i]); } return sqrt(dist); ©SIProp Project, 2006-2008 18
  • 19. How to Build NDK 1/2 1. Download Linux Version NDK on Linux 2. cd [NDK dir] 3. Download Source Code & Patches 1. ./build/tools/download-toolchain-sources.sh src 2. wget http://recursify.com/attachments/posts/2013-0809-openmp-on-android-tlsworkaround/libgomp.h.patch 3. wget http://recursify.com/attachments/posts/2013-0809-openmp-on-android-tlsworkaround/team.c.patch ©SIProp Project, 2006-2008 19
  • 20. How to Build NDK 2/2 Patch to Source Code cd & copy patches to ./src/gcc/gcc-4.6/libgomp/ patch -p0 < team.c.patch patch -p0 < libgomp.h.patch cd [NDK dir] Setup Build-Tools sudo apt-get install texinfo Build Linux Version NDK ./build/tools/build-gcc.sh --verbose $(pwd)/src $(pwd) arm-linux-androideabi-4.6 ©SIProp Project, 2006-2008 20
  • 21. How to Build NDK for Windows 1/4 1. Fix Download Script “./build/tools/buildmingw64-toolchain.sh” 1. 1. 1. 1. run svn co https://mingww64.svn.sourceforge.net/svnroot/mingww64/trunk$MINGW_W64_REVISION $MINGW_W64_SRC ↓ run svn co svn://svn.code.sf.net/p/mingww64/code/trunk/@5861 mingw-w64-svn $MINGW_W64_SRC MINGW_W64_SRC=$SRC_DIR/mingw-w64svn$MINGW_W64_REVISION2 ↓ MINGW_W64_SRC=$SRC_DIR/mingw-w64svn$MINGW_W64_REVISION2/trunk ※My Version is Android-NDK-r9c ©SIProp Project, 2006-2008 21
  • 22. How to Build NDK for Windows 2/4 1. Download MinGW 1. 32-bit 1. 2. 3. ./build/tools/build-mingw64-toolchain.sh --targetarch=i686 cp -a /tmp/build-mingw64-toolchain-$USER/installx86_64-linux-gnu/i686-w64-mingw32 ~ export PATH=$PATH:~/i686-w64-mingw32/bin 2. 64-bit 1. 2. 3. ./build/tools/build-mingw64-toolchain.sh --force-build cp -a /tmp/build-mingw64-toolchain-$USER/installx86_64-linux-gnu/x86_64-w64-mingw32 ~/ export PATH=$PATH:~/x86_64-w64-mingw32/bin ©SIProp Project, 2006-2008 22
  • 23. How to Build NDK for Windows 3/4 Download Pre-Build Tools 32-bit git clone https://android.googlesource.com/platform/prebuilts/gcc/li nux-x86/host/i686-linux-glibc2.7-4.6 $(pwd)/../prebuilts/gcc/linux-x86/host/i686-linux-glibc2.74.6 64-bit git clone https://android.googlesource.com/platform/prebuilts/tools $(pwd)/../prebuilts/tools git clone https://android.googlesource.com/platform/prebuilts/gcc/li nux-x86/host/x86_64-linux-glibc2.7-4.6 $(pwd)/../prebuilts/gcc/linux-x86/host/x86_64-linuxglibc2.7-4.6 ©SIProp Project, 2006-2008 23
  • 24. How to Build NDK for Windows 4/4 Build Windows Version NDK Set Vars export ANDROID_NDK_ROOT=[AOSP's NDK dir] 32-bit ./build/tools/build-gcc.sh --verbose --mingw $(pwd)/src $(pwd) arm-linux-androideabi-4.6 64-bit ./build/tools/build-gcc.sh --verbose --mingw --try-64 $(pwd)/src $(pwd) arm-linux-androideabi-4.6 ©SIProp Project, 2006-2008 24
  • 26. Today’s Topic Compiler ≠ Not Thread Programming ©SIProp Project, 2006-2008 26
  • 27. Parallelizing Compiler for NEON ARM DS-5 Development Studio Debugger for Linux/Android™/RTOS-aware The ARM Streamline system-wide performance analyzer Real-Time system model Simulators All conveniently Packaged in Eclipse. http://www.arm.com/products/tools/software-tools/ds5/index.php ©SIProp Project, 2006-2008 27
  • 30. Parallelizing Compiler for NEON No.2 gcc Android uses it. How to Use Android.mk 1. LOCAL_CFLAGS += -O3 -ftree-vectorize mvectorize-with-neon-quad Supported Arch 1. APP_ABI := armeabi-v7a ©SIProp Project, 2006-2008 30