Renderscript rs.finish(), allocation.syncAll(), copyTo() : wait till kernel execution finishes

元气小坏坏 提交于 2019-12-11 12:12:23

问题


I am writing android renderscript code which requires back to back kernel calls (sometimes output of one kernel become input of other). I also have some global pointers, binded to memory from Java layer. Each kernel updates those global pointers and outputs something. I hav e to make sure that execute of kernel1 is finished, before kernel2 starts execution.

I looked at android renderscript docs, but couldn't understand syncAll(Usage) and finish() well. Can anyone clarify how to achieve this behaviour?

Thanks

mScript.forEach_kernel1(mColorImageAllocation, tempAlloc);

// make sure kernel1 finishes, from android rs doc, copyTo should block 
tempAlloc.copyTo(testOutputBitmap);

for (short i = 0; i < NUM_DIST; i++) {
            mScript.set_gCurrentDistanceIndex(i);
            mScript.forEach_kernel2(tempAlloc);    
        mRS.finish(); // wait till kernel2 finishes
}

In the above example, same kernel2 is called with different global parameters on kernel1's output.


回答1:


For this code you don't need either. RS is a pipeline model so any work which could impact the result of a later command must be finished first by the driver.

syncAll() is used to sync memory spaces not execution. For example to propagate changes from script memory to graphics memory.



来源:https://stackoverflow.com/questions/22158853/renderscript-rs-finish-allocation-syncall-copyto-wait-till-kernel-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!