1. Technology Consulting and Engineering
GPGPU Programming
on Android devices
Alten droidconNL 2012
ALTEN | 11/22/12
2. Welcome
• Alten PTS; leading service provider in the field of technical
consultancy and engineering
Eindhoven, Capelle aan de IJssel and Apeldoorn
• ir. Arjan Somers
Alten-droidconNL 2012 Slide 2
3. Goals
●What is GPGPU?
●How is it done on current Android devices?
●When is GPGPU programming useful?
Alten-droidconNL 2012 Slide 3
5. What
●GPGPU programming is using the GPU to
perform general purpose calculations
● Data manipulation using the graphic card
Alten-droidconNL 2012 Slide 5
6. What
A little bit of history
●
● GPU's and OpenGL
● Parallel vector based operations
● Programmable (Shaders)
Battlezone (1980) Crysis 3 (2013)
Alten-droidconNL 2012 Slide 6
7. What
A little bit of history
●
● GPU's and OpenGL
● Parallel vector based operations
● Programmable (Shaders)
Alten-droidconNL 2012 Slide 7
19. What
A CPU program vs a GPU Program
●
int[] a; int[] b=F(a); int[] b;
Texture draw() pixel-buffer
int[] a; int[] b;
Alten-droidconNL 2012 Slide 19
20. Why
●Additional computational power
● Can run in parallel with CPU
●Greater computational power
● Galaxy S2
● CPU 4 GFlops
● GPU 10 GFlops
Alten-droidconNL 2012 Slide 20
21. How
1) Parallelize code
2) Data packing
3) Implement OpenGL ES 2.0 Shaders
4) Drawing and Input/Output
Alten-droidconNL 2012 Slide 21
22. How: Parallelize code
Pixel-shader parallel code:
public void foo(int[] a, int[] b){
int[] c = new int[a.length];
for(int i=0; i<a.length; i++){
c[i] = a[i] + 2*b[i];
}
}
Alten-droidconNL 2012 Slide 22
23. How: Parallelize code
Not Pixel-shader parallel code:
(Mobile GPU have no geometry shaders)
public int[] bar(int[] a, int[] b, int[] c){
int[] d = new int[a.length];
for(int i=0; i<a.length; i++){
d[b[i]] += a[i];
d[c[i]] += a[i];
}
return d;
}
Alten-droidconNL 2012 Slide 23
24. How: Parallelize code
Not Pixel-shader parallel code:
● Sequence of calculations
Alten-droidconNL 2012 Slide 24
25. How: Data packing
Current mobile GPU's only have
● 8bpp buffers and textures
● single render target
Alten-droidconNL 2012 Slide 25
27. How: Implement Shaders
Will be shown later in detail
●
● Use OpenGL ES 2.0
● No CUDA, OpenCL or similar
Alten-droidconNL 2012 Slide 27
28. How: Drawing and Input/Output
Transfer is slow
●
Texture draw() pixel-buffer
Int[] a; Int[] b;
Alten-droidconNL 2012 Slide 28
29. When: What works, what not
●Parallelism
● No geometry shaders
●Limited precision / Single Render Target
●Limited data transfer
●Not yet as fast a desktop
Alten-droidconNL 2012 Slide 29
30. Example
AES encryption on the GPU
●
“Hello droiconNL!”
Encryption
U2FsdGVkX18UAXwN1I7bomP0kuKNXwQ8h
2NHb8lZ5sAG6uaLjZxzkn/ik9QPv8Pq
Decryption
“Hello droiconNL!”
Alten-droidconNL 2012 Slide 30
31. Example
Encoding Decoding
Alten-droidconNL 2012 Slide 31
32. Example
Encoding Decoding
Not GPU-Parallel GPU-Parallel
Alten-droidconNL 2012 Slide 32
34. Example
Are all parts implementable on gpu?
Alten-droidconNL 2012 Slide 34
35. Example
Are all parts implementable on gpu?
Parallelizable?
Packing required?
Alten-droidconNL 2012 Slide 35
36. Example
Implementing shader
Dec Hex
0 00
25 19
255 FF
Alten-droidconNL 2012 Slide 36
37. Example
Implementing shader
Dec Hex
0 00
25 19
255 FF
Alten-droidconNL 2012 Slide 37
38. Example
Implementing shader
●Parallelizable?
●Packing?
●Steps:
● Find row/column using hex-digits
● Find new value in substitution table
Alten-droidconNL 2012 Slide 38
46. My experiences
●OpenGL ES is limited vs Desktop
● Geometry shaders
● Buffer formats / no MRT's
●Sometimes difficult to debug
● Dithering
● NPOT
●Complex algorithms are possible
● Computer vision implemented
●Large speed gains are possible
Alten-droidconNL 2012 Slide 46
47. Conclusion
●How is GPGPU programming performed on
Android devices?
● Trough the use of shaders and textures
●When is GPGPU a viable option?
● Calculations are consuming too much time
● Calculations are parallelizable
● Can be implemented using 32 bit buffers
● Limited transfer GPU-CPU memory
required
Alten-droidconNL 2012 Slide 47
48. Conclusion
●GPGPU programming has high potential
●Mobile GPU are becoming faster
●GPGPU programming is fun
Alten-droidconNL 2012 Slide 48