SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
High Performance
Graphics and Compute
OpenGLES and RenderScript

Arvind Devaraj

Limitless

Arvind Devaraj
slideshare.net/darvind/

Limitless

Arvind Devaraj
Agenda
●

Introduction : Graphics terms

●

Graphics on GPU

●

OpenGL Android Graphics

●

Graphics Pipeline

●

Shaders

●

High Performance Compute on GPU

●

RenderScript

Limitless

Arvind Devaraj
CPU versus GPU
●

CPU
–

good at executing sequential code

–

●

Handles branches well

–

Same code, multiple data

GPU

–

Limitless

Parallelism (ideal for image rendering)

Arvind Devaraj
Graphics Terms
●

●

●

OpenGLES : Graphics API for doing 3D operations on GPU /
CPU
Primitives : lines, point, triangles
Texture : make the image
realistic by adding bitmap

Limitless

Arvind Devaraj
Graphics on GPU

Wireframe of model
Polygonated
Limitless

Arvind Devaraj
Graphics Pipeline

Vertex

Pixel
operations

Vertex
Transformation
Rasterize the
triangle to pixels

Limitless

Arvind Devaraj
OpenGL Driver

Converts API call to commands
–

glDraw()

Commands executed in GPU / CPU
Implementation of the Graphics Pipeline
Limitless

Arvind Devaraj
OpenGLES Android Graphics
●

Graphics Library for 3D

Limitless

Arvind Devaraj
Android Graphics Classes
GLSurfaceView
GLSurfaceView.Renderer

➢

View

- connects SurfaceView to OpenGLES library

➢

Renderer - responsible for rendering a frame

Limitless

Arvind Devaraj
GLSurfaceView
    

    GLSurfaceView view = new GLSurfaceView(this);

    view.setRenderer(new SquareRenderer());

Limitless

Arvind Devaraj
GLSurfaceView.Renderer
public class SquareRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL10 unused, EGLConfig config) {
   
        Code when surface is created
    }
    public void onDrawFrame(GL10 unused) {
draw() - Code for drawing the frame ( Square )

    }
    public void onSurfaceChanged(GL10 unused, int width, int height)   {
        When surface is changed (rotated etc)
    }
}

Limitless

Arvind Devaraj
GLSurfaceView.Renderer

●

The renderer is responsible for making OpenGL calls to
render a frame.
–

onDrawFrame() responsible for drawing the
current frame

–

OnSurfaceChanged() called when surface size
changes

–

OnSurfaceCreated() called when surface is
created

Limitless

Arvind Devaraj
Drawing a Square
draw() {
 

float coords[] = { ....     };
vertex 'buffer' created with the coords
glVertexPointer(buffer) :

}

glDrawArrays(TRIANGLE_STRIP ...);
,

Limitless

Arvind Devaraj
Drawing a Square
draw() {
 

float squareCoords[] = { ....     };
ByteBuffer vbb = ....
  squareVB = vbb.asFloatBuffer(); 
 
squareVB.put(squareCoords); 
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

}

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3);
,

Full code:
https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java

Limitless

Arvind Devaraj
Drawing a Square
draw() {
 

float squareCoords[] = { ....     };
ByteBuffer vbb = ....
  squareVB = vbb.asFloatBuffer(); 
 
squareVB.put(squareCoords); 
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

}

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3);
,

Full code:
https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java

Limitless

Arvind Devaraj
OpenGL Rendering Pipeline

Limitless

Arvind Devaraj
Shaders
●

Shaders are programs that execute on the GPU

●

Shader programs operate on
–

Each vertex

–

Each pixel

Limitless

Arvind Devaraj
Shader Programs
• Vertex Shader – operates on each vertex
• Fragment Shader – operates on each pixel
• Shaders are compiled and linked ( like any program )
• Executable is sent to the GPU

Limitless

Arvind Devaraj
Limitless

Arvind Devaraj
Vertex Shader
attribute vec4 vertexPosition;
void main(){
     gl_Position = vertexPosition * 2;
 

}

Fragment Shader
precision mediump float;
void main(){
  
 gl_FragColor = ( color.r + color.g + color.b ) / 3;
}

Limitless

Arvind Devaraj
Program running on GPU/CPU

Limitless

Arvind Devaraj
CPU – GPU communication

Limitless

Arvind Devaraj
GPU for General Programs
●

Graphics is accelerated by the GPU

●

Can GPU accelerate other programs ?
–

●

e.g. Matrix multiply, encryption

OpenCL, CUDA, Renderscript are API
–

used for general purpose GPU

Limitless

Arvind Devaraj
RenderScript
●

A high level API to access GPU

●

Provides high performance Compute

●

Provides uniform API across multiple SoC

●

Alternative is NDK (but NDK is platform
specific)

Limitless

Arvind Devaraj
RenderScript – Use cases
●

What functions can be accelerated
–

Graphics

–

Image Processing

–

Encryption

–

Signal processing

–

Mathematical functions

Limitless

Arvind Devaraj
RenderScript - Flow

Limitless

Arvind Devaraj
RenderScript – CPU side
Class Hello extends Activity {
Allocation input, output;
Allocation is how you get data to RS, so that it is processed by kernel

Create a script (kernel) that specifies the function
Run script for each element in allocation
}

Limitless

Arvind Devaraj
RenderScript – CPU side
Class Hello extends Activity {
Allocation input;
Allocation output;
RenderScript rs = new RenderScript()
ScriptC_func script = new ScriptC_func(...)
}

script.forEach_root(input, output)
Allocation is how you get data to RS,
so that it is processed by kernel
Limitless

Arvind Devaraj
Renderscript Java interaction

Limitless

Arvind Devaraj
RenderScript – GPU side
func.rs
void root (char *in , char *out) {
*out = *in * 2
}

Renderscript code is compiled to device independent Bitcode
Bitcode is dynamically interpreted by runtime for specifi GPU
Limitless

Arvind Devaraj
RenderScript
●

●

Advantages : Compared to NDK, provides an easy device
agnostic way to accelerate performance on GPU
Disadvantages : C99 standard, debugging is restricted

Limitless

Arvind Devaraj
Renderscipt - Summary
●

Renderscript is an API to access GPU

●

Used for High Performance

●

High Performance Compute / Graphics

●

Compute, Math , FFT, convolution, Signal processing

●

Support Graphics – but not a replacement for OpenGL

●

Works on all GPUs ( if supported by SoC ) otherwise on CPU

Limitless

Arvind Devaraj
Renderscript potential
Limitless
arvind.iisc@gmail.com
arvinddevaraj
github, linkedin,twitter

Limitless

Arvind Devaraj

Contenu connexe

Tendances

Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
changehee lee
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
changehee lee
 
Core Graphics & Core Animation
Core Graphics & Core AnimationCore Graphics & Core Animation
Core Graphics & Core Animation
Andreas Blick
 

Tendances (20)

vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan API
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
Siggraph 2016 - Vulkan and nvidia : the essentials
Siggraph 2016 - Vulkan and nvidia : the essentialsSiggraph 2016 - Vulkan and nvidia : the essentials
Siggraph 2016 - Vulkan and nvidia : the essentials
 
NvFX GTC 2013
NvFX GTC 2013NvFX GTC 2013
NvFX GTC 2013
 
Open Graphics Library
Open Graphics  Library Open Graphics  Library
Open Graphics Library
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforward
 
Universal Render Pipeline and the features used to create the Boat Attack dem...
Universal Render Pipeline and the features used to create the Boat Attack dem...Universal Render Pipeline and the features used to create the Boat Attack dem...
Universal Render Pipeline and the features used to create the Boat Attack dem...
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
OpenGL ES 2.x Programming Introduction
OpenGL ES 2.x Programming IntroductionOpenGL ES 2.x Programming Introduction
OpenGL ES 2.x Programming Introduction
 
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering SystemOpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
OpenGL ES 2.0 Programming and Cocos2d-x v3.3 Rendering System
 
Core Graphics & Core Animation
Core Graphics & Core AnimationCore Graphics & Core Animation
Core Graphics & Core Animation
 
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationRendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
 
Optimizing NN inference performance on Arm NEON and Vulkan
Optimizing NN inference performance on Arm NEON and VulkanOptimizing NN inference performance on Arm NEON and Vulkan
Optimizing NN inference performance on Arm NEON and Vulkan
 
Qt Programming on TI Processors
Qt Programming on TI ProcessorsQt Programming on TI Processors
Qt Programming on TI Processors
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qt
 
[Osxdev]metal
[Osxdev]metal[Osxdev]metal
[Osxdev]metal
 
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
 

Similaire à Android High performance in GPU using opengles and renderscript

Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_android
tamillarasan
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
David Galeano
 
Introduction To Geometry Shaders
Introduction To Geometry ShadersIntroduction To Geometry Shaders
Introduction To Geometry Shaders
pjcozzi
 

Similaire à Android High performance in GPU using opengles and renderscript (20)

Webrender 1.0
Webrender 1.0Webrender 1.0
Webrender 1.0
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Dx11 performancereloaded
Dx11 performancereloadedDx11 performancereloaded
Dx11 performancereloaded
 
FrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in FrostbiteFrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in Frostbite
 
Introduction to open_gl_in_android
Introduction to open_gl_in_androidIntroduction to open_gl_in_android
Introduction to open_gl_in_android
 
3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
GPU - An Introduction
GPU - An IntroductionGPU - An Introduction
GPU - An Introduction
 
Open gl
Open glOpen gl
Open gl
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Introduction to cuda geek camp singapore 2011
Introduction to cuda   geek camp singapore 2011Introduction to cuda   geek camp singapore 2011
Introduction to cuda geek camp singapore 2011
 
Your Game Needs Direct3D 11, So Get Started Now!
Your Game Needs Direct3D 11, So Get Started Now!Your Game Needs Direct3D 11, So Get Started Now!
Your Game Needs Direct3D 11, So Get Started Now!
 
Haskell Accelerate
Haskell  AccelerateHaskell  Accelerate
Haskell Accelerate
 
Cuda
CudaCuda
Cuda
 
The next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game EnginesThe next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game Engines
 
Open Standards for ADAS: Andrew Richards, Codeplay, at AutoSens 2016
Open Standards for ADAS: Andrew Richards, Codeplay, at AutoSens 2016Open Standards for ADAS: Andrew Richards, Codeplay, at AutoSens 2016
Open Standards for ADAS: Andrew Richards, Codeplay, at AutoSens 2016
 
RapidFire - the Easy Route to low Latency Cloud Gaming Solutions - AMD at GDC14
RapidFire - the Easy Route to low Latency Cloud Gaming Solutions - AMD at GDC14RapidFire - the Easy Route to low Latency Cloud Gaming Solutions - AMD at GDC14
RapidFire - the Easy Route to low Latency Cloud Gaming Solutions - AMD at GDC14
 
Introduction To Geometry Shaders
Introduction To Geometry ShadersIntroduction To Geometry Shaders
Introduction To Geometry Shaders
 

Plus de Arvind Devaraj

Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android Workshop
Arvind Devaraj
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
Arvind Devaraj
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
Arvind Devaraj
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier Transforms
Arvind Devaraj
 

Plus de Arvind Devaraj (20)

Deep learning for NLP and Transformer
 Deep learning for NLP  and Transformer Deep learning for NLP  and Transformer
Deep learning for NLP and Transformer
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Career hunt pitch
Career hunt pitchCareer hunt pitch
Career hunt pitch
 
Career options for CS and IT students
Career options for CS and IT studentsCareer options for CS and IT students
Career options for CS and IT students
 
Careerhunt ebook
Careerhunt ebookCareerhunt ebook
Careerhunt ebook
 
Static Analysis of Computer programs
Static Analysis of Computer programs Static Analysis of Computer programs
Static Analysis of Computer programs
 
Hyperbook
HyperbookHyperbook
Hyperbook
 
Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android Workshop
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
AIDL - Android Interface Definition Language
AIDL  - Android Interface Definition LanguageAIDL  - Android Interface Definition Language
AIDL - Android Interface Definition Language
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
Operating system
Operating systemOperating system
Operating system
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier Transforms
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006)
 
Computer Systems
Computer SystemsComputer Systems
Computer Systems
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Android High performance in GPU using opengles and renderscript

  • 1. High Performance Graphics and Compute OpenGLES and RenderScript Arvind Devaraj Limitless Arvind Devaraj
  • 3. Agenda ● Introduction : Graphics terms ● Graphics on GPU ● OpenGL Android Graphics ● Graphics Pipeline ● Shaders ● High Performance Compute on GPU ● RenderScript Limitless Arvind Devaraj
  • 4. CPU versus GPU ● CPU – good at executing sequential code – ● Handles branches well – Same code, multiple data GPU – Limitless Parallelism (ideal for image rendering) Arvind Devaraj
  • 5. Graphics Terms ● ● ● OpenGLES : Graphics API for doing 3D operations on GPU / CPU Primitives : lines, point, triangles Texture : make the image realistic by adding bitmap Limitless Arvind Devaraj
  • 6. Graphics on GPU Wireframe of model Polygonated Limitless Arvind Devaraj
  • 8. OpenGL Driver Converts API call to commands – glDraw() Commands executed in GPU / CPU Implementation of the Graphics Pipeline Limitless Arvind Devaraj
  • 9. OpenGLES Android Graphics ● Graphics Library for 3D Limitless Arvind Devaraj
  • 10. Android Graphics Classes GLSurfaceView GLSurfaceView.Renderer ➢ View - connects SurfaceView to OpenGLES library ➢ Renderer - responsible for rendering a frame Limitless Arvind Devaraj
  • 11. GLSurfaceView          GLSurfaceView view = new GLSurfaceView(this);     view.setRenderer(new SquareRenderer()); Limitless Arvind Devaraj
  • 12. GLSurfaceView.Renderer public class SquareRenderer implements GLSurfaceView.Renderer {     public void onSurfaceCreated(GL10 unused, EGLConfig config) {             Code when surface is created     }     public void onDrawFrame(GL10 unused) { draw() - Code for drawing the frame ( Square )     }     public void onSurfaceChanged(GL10 unused, int width, int height)   {         When surface is changed (rotated etc)     } } Limitless Arvind Devaraj
  • 13. GLSurfaceView.Renderer ● The renderer is responsible for making OpenGL calls to render a frame. – onDrawFrame() responsible for drawing the current frame – OnSurfaceChanged() called when surface size changes – OnSurfaceCreated() called when surface is created Limitless Arvind Devaraj
  • 14. Drawing a Square draw() {   float coords[] = { ....     }; vertex 'buffer' created with the coords glVertexPointer(buffer) : } glDrawArrays(TRIANGLE_STRIP ...); , Limitless Arvind Devaraj
  • 15. Drawing a Square draw() {   float squareCoords[] = { ....     }; ByteBuffer vbb = ....   squareVB = vbb.asFloatBuffer();    squareVB.put(squareCoords);  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); } gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3); , Full code: https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java Limitless Arvind Devaraj
  • 16. Drawing a Square draw() {   float squareCoords[] = { ....     }; ByteBuffer vbb = ....   squareVB = vbb.asFloatBuffer();    squareVB.put(squareCoords);  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); } gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3); , Full code: https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java Limitless Arvind Devaraj
  • 18. Shaders ● Shaders are programs that execute on the GPU ● Shader programs operate on – Each vertex – Each pixel Limitless Arvind Devaraj
  • 19. Shader Programs • Vertex Shader – operates on each vertex • Fragment Shader – operates on each pixel • Shaders are compiled and linked ( like any program ) • Executable is sent to the GPU Limitless Arvind Devaraj
  • 21. Vertex Shader attribute vec4 vertexPosition; void main(){      gl_Position = vertexPosition * 2;   } Fragment Shader precision mediump float; void main(){     gl_FragColor = ( color.r + color.g + color.b ) / 3; } Limitless Arvind Devaraj
  • 22. Program running on GPU/CPU Limitless Arvind Devaraj
  • 23. CPU – GPU communication Limitless Arvind Devaraj
  • 24. GPU for General Programs ● Graphics is accelerated by the GPU ● Can GPU accelerate other programs ? – ● e.g. Matrix multiply, encryption OpenCL, CUDA, Renderscript are API – used for general purpose GPU Limitless Arvind Devaraj
  • 25. RenderScript ● A high level API to access GPU ● Provides high performance Compute ● Provides uniform API across multiple SoC ● Alternative is NDK (but NDK is platform specific) Limitless Arvind Devaraj
  • 26. RenderScript – Use cases ● What functions can be accelerated – Graphics – Image Processing – Encryption – Signal processing – Mathematical functions Limitless Arvind Devaraj
  • 28. RenderScript – CPU side Class Hello extends Activity { Allocation input, output; Allocation is how you get data to RS, so that it is processed by kernel Create a script (kernel) that specifies the function Run script for each element in allocation } Limitless Arvind Devaraj
  • 29. RenderScript – CPU side Class Hello extends Activity { Allocation input; Allocation output; RenderScript rs = new RenderScript() ScriptC_func script = new ScriptC_func(...) } script.forEach_root(input, output) Allocation is how you get data to RS, so that it is processed by kernel Limitless Arvind Devaraj
  • 31. RenderScript – GPU side func.rs void root (char *in , char *out) { *out = *in * 2 } Renderscript code is compiled to device independent Bitcode Bitcode is dynamically interpreted by runtime for specifi GPU Limitless Arvind Devaraj
  • 32. RenderScript ● ● Advantages : Compared to NDK, provides an easy device agnostic way to accelerate performance on GPU Disadvantages : C99 standard, debugging is restricted Limitless Arvind Devaraj
  • 33. Renderscipt - Summary ● Renderscript is an API to access GPU ● Used for High Performance ● High Performance Compute / Graphics ● Compute, Math , FFT, convolution, Signal processing ● Support Graphics – but not a replacement for OpenGL ● Works on all GPUs ( if supported by SoC ) otherwise on CPU Limitless Arvind Devaraj