Show navigation Hide navigation

RenderScript Kernel Invocation Functions and Types

Overview

The rsForEach() function can be used to invoke the root kernel of a script.

Summary

Types
rs_for_each_strategy_t Suggested cell processing order
rs_script_call_t Cell iteration information
Functions
rsForEach Invoke the root kernel of a script

Types

rs_for_each_strategy_t : Suggested cell processing order

An enum with the following values:     

RS_FOR_EACH_STRATEGY_SERIAL = 0Prefer contiguous memory regions.
RS_FOR_EACH_STRATEGY_DONT_CARE = 1No prefrences.
RS_FOR_EACH_STRATEGY_DST_LINEAR = 2Prefer DST.
RS_FOR_EACH_STRATEGY_TILE_SMALL = 3Prefer processing small rectangular regions.
RS_FOR_EACH_STRATEGY_TILE_MEDIUM = 4Prefer processing medium rectangular regions.
RS_FOR_EACH_STRATEGY_TILE_LARGE = 5Prefer processing large rectangular regions.

This type is used to suggest how the invoked kernel should iterate over the cells of the allocations. This is a hint only. Implementations may not follow the suggestion.

This specification can help the caching behavior of the running kernel, e.g. the cache locality when the processing is distributed over multiple cores.

rs_script_call_t : Cell iteration information

A structure with the following fields:     

rs_for_each_strategy_t strategyCurrently ignored. In the future, will be suggested cell iteration strategy.
uint32_t xStartStarting index in the X dimension.
uint32_t xEndEnding index (exclusive) in the X dimension.
uint32_t yStartStarting index in the Y dimension.
uint32_t yEndEnding index (exclusive) in the Y dimension.
uint32_t zStartStarting index in the Z dimension.
uint32_t zEndEnding index (exclusive) in the Z dimension.
uint32_t arrayStartStarting index in the Array0 dimension.
uint32_t arrayEndEnding index (exclusive) in the Array0 dimension.
uint32_t array1StartStarting index in the Array1 dimension.
uint32_t array1EndEnding index (exclusive) in the Array1 dimension.
uint32_t array2StartStarting index in the Array2 dimension.
uint32_t array2EndEnding index (exclusive) in the Array2 dimension.
uint32_t array3StartStarting index in the Array3 dimension.
uint32_t array3EndEnding index (exclusive) in the Array3 dimension.

This structure is used to provide iteration information to a rsForEach call. It is currently used to restrict processing to a subset of cells. In future versions, it will also be used to provide hint on how to best iterate over the cells.

The Start fields are inclusive and the End fields are exclusive. E.g. to iterate over cells 4, 5, 6, and 7 in the X dimension, set xStart to 4 and xEnd to 8.

Functions

rsForEach : Invoke the root kernel of a script

void rsForEach(rs_script script, rs_allocation input, rs_allocation output); Added in API level 14
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData); Removed from API level 14
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, const rs_script_call_t* sc); Removed from API level 14
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, size_t usrDataLen); API level 14 - 20
void rsForEach(rs_script script, rs_allocation input, rs_allocation output, const void* usrData, size_t usrDataLen, const rs_script_call_t* sc); API level 14 - 20
Parameters
scriptScript to call.
inputAllocation to source data from.
outputAllocation to write date into.
usrDataUser defined data to pass to the script. May be NULL.
scExtra control information used to select a sub-region of the allocation to be processed or suggest a walking strategy. May be NULL.
usrDataLenSize of the userData structure. This will be used to perform a shallow copy of the data if necessary.

Invoke the kernel named "root" of the specified script. Like other kernels, this root() function will be invoked repeatedly over the cells of the specificed allocation, filling the output allocation with the results.

When rsForEach is called, the root script is launched immediately. rsForEach returns only when the script has completed and the output allocation is ready to use.

The rs_script argument is typically initialized using a global variable set from Java.

The kernel can be invoked with just an input allocation or just an output allocation. This can be done by defining an rs_allocation variable and not initializing it. E.g.
rs_script gCustomScript;
void specializedProcessing(rs_allocation in) {
  rs_allocation ignoredOut;
  rsForEach(gCustomScript, in, ignoredOut);
}

If both input and output allocations are specified, they must have the same dimensions.