[英]how to get index reading in RenderScript's kernels
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. 我是RenderScript
的完美入门者,我刚刚开始使用它,我设法并行处理了一些算法,但是我确实没有正确使用它。
Here's the java code : 这是java代码:
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 和RenderScript
代码
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. 我的想法是,我需要在algo
函数内部获取与读取的input
或output
值相关的索引。 But, I can't use counter
since I notice that the index of reading input
or output
are not the increasing order. 但是,我不能使用counter
因为我注意到读取input
或output
的索引不是递增顺序。 Someone know how to do that ? 有人知道该怎么做吗?
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. 同样,拥有输入/输出变量的全局/本地版本并避免使用绑定API也是个坏主意。 Use global rs_allocation object and rsGetElement_*/rsSetElementAt_* apis. 使用全局rs_allocation对象和rsGetElement _ * / rsSetElementAt_ * API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.