android-Computation(RenderScript)

RenderScript与二进制文件 系统升级或APP升级 可扩展性 (CPU GPU DSP等)
》RenderScript provides a platform-independent computation engine that operates at the 

native level. Use it to accelerate your apps that require extensive computational horsepower.RenderScript is a framework for running computationally intensive tasks at high performance on Android. 


To begin with RenderScript, there are two main concepts you should understand:
High-performance compute kernels are written in a C99-derived language.

A Java API is used for managing the lifetime of RenderScript resources and controlling kernel execution.

》When developing an Android application that uses RenderScript, you can access its API in one of two ways:
android.renderscript - The APIs in this class package are available on devices running Android 3.0 (API level 11) and higher.android.support.v8.renderscript - The APIs in this package are available through a Support Library, which allows you to use them on devices running Android 2.2 (API level 8) and higher.

》Your RenderScript code is compiled and executed in a compact and well-defined runtime layer. The RenderScript runtime APIs offer support for intensive computation that is portable and automatically scalable to the amount of cores available on a processor.

》Note: The standard C functions in the NDK must be guaranteed to run on a CPU, so RenderScript cannot access these libraries, because RenderScript is designed to run on different types of processors.The example below allocates memory for both a primitive type pointer, intPointer, and a pointer to a struct,touchPoints. It also binds the memory to the RenderScript:


private RenderScript myRenderScript;
private ScriptC_example script;
private Resources resources;

public void init(RenderScript rs, Resources res) {
    myRenderScript = rs;
    resources = res;

    //allocate memory for the struct pointer, calling the constructor
    ScriptField_Point touchPoints = new ScriptField_Point(myRenderScript, 2);

    //Create an element manually and allocate memory for the int pointer
    intPointer = Allocation.createSized(myRenderScript, Element.I32(myRenderScript),2);
    //create an instance of the RenderScript, pointing it to the bytecode resource
    mScript = new ScriptC_example(myRenderScript, resources, R.raw.example);
    //bind the struct and int pointers to the RenderScript
    mScript.bind_touchPoints(touchPoints);
    script.bind_intPointer(intPointer);
   ...
}
Reading and writing to global variables is a straightforward process. You can use the accessor methods at the Android framework level or set them directly in the 
RenderScript code. Keep in mind that any changes that you make in your RenderScript code are not propagated back to the Android framework layer.

For example, given the following struct declared in a file named rsfile.rs:
typedef struct Point {
    int x;
    int y;
} Point_t;

Point_t point;


Once memory is already bound, you do not have to rebind the memory to the RenderScript runtime every time you make a change to a value.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值