how to get index reading in RenderScript's kernels

104 views Asked by At

I am a perfect noob of RenderScript, I have just began to play with, I managed to parallel process some algo but I am really not using it properly.

Here's the java code :

    Allocation input = Allocation.createSized(renderScript, Element.I32(renderScript), some_input_image.length); // where renderScript is an instance of RenderScript 
    input.copyFrom(some_input_image);


    Allocation output = Allocation.createSized(renderScript, Element.I32(renderScript), image.length);
    output.copyFrom(some_image);
    scriptC_algo.bind_output(output);

scriptC_algo.invoke_process(input,output);

and the RenderScript code

uint32_t *input;
uint32_t *output;

void RS_KERNEL algo(uint32_t in, uint32_t out) {
  rsAtomicInc(&counter);
  // some code

}

void process(rs_allocation input, rs_allocation output) {
  rsForEach(algo, input, output);
}

The think is that I need inside the algo function to get the index related the values of input or output that are read. But, I can't use counter since I notice that the index of reading input or output are not the increasing order. Someone know how to do that ?

1

There are 1 answers

0
sakridge On

Your kernel should be like this:

#pragma rs_fp_relaxed
uint32_t RS_KERNEL algo(uint32_t in, uint32_t x) {
     // << x will be the location of 'in' and 'out' element
     return in;  // write input to output
}

Also, bad idea to have global/local versions of input/output variables and avoid the bind api. Use global rs_allocation object and rsGetElement_*/rsSetElementAt_* apis.