2. Agenda
• What is RenderScript and why
• How to use it with REAL example
• Show some data comparison
• Bad side…
• References
3. 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.
4. 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
5. How it works
1. Android app codes
2. RenderScript codes
(C99-derived
language)
• Reflected Layer Classes
Developer’s job
System generated
8. Two important component
• compute kernels: written in a C99-derived language.
• Java codes:
• managing the lifetime of RenderScript resources
• controlling kernel execution.
10. • 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
12. • 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
13. Step 3: get data & clean memory
• Get the data from OutAllocation
• Manage memory in java codes
=> Destroy allocations and RenderScript instance
16. 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?)
using (1 is the only value for now).
. The next feature is the in argument and its type. In a RenderScript kernel, this is a special argument that is automatically filled in based on the input Allocation passed to the kernel launch. By default, the kernel is run across an entire Allocation, with one execution of the kernel body per Element in the Allocation. The third notable feature is the return type of the kernel.
An optional init() function. An init() function is a special type of invokable function that is run when the script is first instantiated.
119: an application will have only a single RenderScript context at a time. => You should consider context creation to be a potentially long-running operation, since it may create resources on different pieces of hardware;
Methods to launch a given kernel will be reflected in the same ScriptC_filename class with methods named forEach_kernelname().
Argb_8888
an application will have only a single RenderScript context at a time