renderscript
TRANSCRIPT
RenderScriptDaniel Kao <[email protected]>
Agenda
•What is RenderScript and why
•How to use it with REAL example
• Show some data comparison
•Bad side…
•References
What is RenderScript
• A framework for running computationally intensive tasks at high performance on Android.
• primarily oriented for use with data-parallel computation
• E.g., image processing, computational photography, or computer vision.
• run operations with automatic parallelization across all available processor cores, and supports different types of processors such as the CPU, GPU or DSP.
Why use it?
• If you use NDK
• Lack of portability
• Lack of performance (dealing with CPU, GPU, or DSP)
• Lack of usability (native code => harder, and JNI…)
• RenderScript did them all for you
How it works
1. Android app codes
2. RenderScript codes (C99-derived
language)
• Reflected Layer Classes
Developer’s job
System generated
Two important component
• compute kernels: written in a C99-derived language.
• Java codes:
• managing the lifetime of RenderScript resources
• controlling kernel execution.
• Line 1: declares the version of RenderScript that you are Line • Line 2: declares the package name of the .java reflection of this RenderScript• Line 4-6: global static variables that can be accessed from java codes by system
generated java reflected functions• Line 8: kernel function definition• Line 9-61: where we write our codes• Line 62: return the result
• 121: Initialize a RenderScript context
• 122-124: Create Allocation (a RS object that provides storage for a fixed amount of data)
• 126: Create RS script object
• 133, 135: System generated func. to invoke computation for each element
Step 3: get data & clean memory
• Get the data from OutAllocation
• Manage memory in java codes
=> Destroy allocations and RenderScript instance
Bad Side….
• A framework that only works on Android platform
• Lack of documentation
• Limited API set
• Hard to debug
• Crashes on Intel Atom devices (my problem?)
References
• http://developer.android.com/guide/topics/renderscript/compute.html
• http://android-developers.blogspot.tw/2011/02/introducing-renderscript.html
• http://android-developers.blogspot.tw/2011/03/renderscript.html
• http://android-developers.blogspot.tw/2013/01/evolution-of-renderscript-performance.html
• https://www.youtube.com/watch?v=3ynA92x8WQo
• https://software.intel.com/en-us/articles/how-to-use-renderscript-on-intel-based-devices