Can I use RenderScript rsForEach for a non-root kernel?

Is it possible to use a kernel without RenderScript using rsForEach ? There are many examples of using rsForEach to invoke the root kernel from the built-in RenderScript function:

They bind the script itself to a variable in the context of RenderScript, and then call the root kernel from RenderScript. For example, in the Activity class:

 ... mScript = new ScriptC_gradient(mRS); // bind Allocations and mScript to variables in the RenderScript context: mScript.set_gIn(mImageAllocation); mScript.set_gOut(mGradientAllocation); mScript.set_gScript(mScript); // invoke gradient function: mScript.invoke_gradient(); ... 

And in gradient.rs :

 #pragma version(1) #pragma rs java_package_name(com.example.android.rs.hellocompute) rs_allocation gOut; rs_allocation gIn; rs_script gScript; void gradient() { rsForEach(gScript, gIn, gOut); } void root(const uchar4 *v_in, uchar4 *v_out, ... 

But if I have another gray kernel, can I call it after root , inside gradient ?

 // I thought it would look like this: void gradient() { rsForEach(gScript, gIn, gOut); rsForEach(gScript, gIn, gOut, NULL, NULL, gExportForEachIdx_gray); } // Or: void gradient() { rsForEach(gScript, gIn, gOut); rsSetMainKernel(&gScript, "gray"); rsForEach(gScript, gIn, gOut); } 

But the documentation for rsForEach seems to indicate that it does not support anything like this. Perhaps this can be done by setting something in rs_script_call_t , but the document is quite sharp in this type: (Checked September 20, 2013)

 typedef struct rs_script_call rs_script_call_t** 

Structure for providing additional information for calling rsForEach. Originally used to limit the call to a subset of cells in a distribution.

This question is mainly out of curiosity. I expect the preferred method is to call them from Java:

 ... mScript = new ScriptC_gradient(mRS); // bind Allocations and mScript to variables in the RenderScript context: mScript.forEach_root(mImageAllocation, mGradientAllocation); mScript.forEach_gray(mGradientAllocation, mGrayGradientAllocation); ... 

They seem to be in sync. If you define root and gray as follows:

 void root(...) { rsDebug("root", 0,0); } void gray(...) { rsDebug("gray", 1,1); } 

then calling forEach_root and then forEach_gray causes "root, {0,0}" to register in NxM times before it starts to register "gray, {1,1}" - I did not find any documentation that guarantees that, though. Does anyone know where this is?

+4
source share
1 answer

Unfortunately, we have no way to call the kernel without RenderScript using rsForEach () from the script. You will have to directly access it from Java. You can also put the second core in another Script as root () and then associate it with rs_script (for example, you can have gScriptGradient and gScriptGray and execute them sequentially from one call in your main Script).

I first skipped your second question about synchronization between parallel cores. They are really ordered. Although the kernels start asynchronously, the second kernel does not start until the completion of the first kernel.

+4
source

All Articles