RenderScript闭锁功能invokation [英] RenderScript blocking function invokation

查看:107
本文介绍了RenderScript闭锁功能invokation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到renderScript,仍然有不阻塞/非阻塞从Java层的话费性质,以便不错的主意。一般的问题是:哪些情况下阻止code和允许RenderScript完成。特别是:

  1. 从我的Java调用使用 forEach_kernel()并没有阻止内核 - 我不得不添加一个额外的 Allocation.copyTo(),这样我可以使用的结果。是否有另一种方式?
  2. 在我读的地方,如果有2个内核,然后调用第二个将阻塞,直到第一个将完成。什么条件导致这 - ?也许只有在相同的分配工作时
  3. 将可调用功能块一)对方,B)内核?特别是,我有我需要prepare一些数据,稍后将用于内核自定义初始可调用函数。这preparation可能需要一些时间,所以我想知道这是否是危险的在Java中调用 script.invoke_somefunc(),然后立即打电话 script.forEach_kernel()
解决方案

1)你可以使用rs.finish(),以确保您的内核来完成等待。内核执行的确是异步的RS。

2)我们只允许一个内核在一个时间(忽略ScriptGroup,那就是你有内核的DAG执行,因此也许一些额外的空间优化)。在这种情况下,你的第二个内核将无法启动运行,直到第一个内核完成。

3)从Java可调用函数(运行与调用_ *(即东西))是的没有的异步的。您将阻塞,直到他们完成在Java端。因此,它们将相互阻塞,或内核。如果你有一个内核来一个调用,您将异步启动内核,但调用不会开始,直到内核完成。然后,您将等待调用完成为好。

还有一个细节。如果你的初始化不需要参数,你可以把它放在一个实际的无效的init(无效)功能。创建ScriptC当那些获得运行一次。

I am new to RenderScript and still have not so good idea on blocking/non-blocking nature of the calls from Java layer. The general question is: which situations block the code and allow RenderScript to finish. Particularly:

  1. From Java I invoked a kernel using forEach_kernel() and that was not blocking - I had to add an extra Allocation.copyTo() so that I could use the result. Was there another way?
  2. I read somewhere that if there are 2 kernels then calling second will block until the first one will finish. What conditions result in this - maybe only when working on the same allocation?
  3. Will the invokable functions block a) each other, b) kernel? Particularly, I have a custom initializer invokable function which I need to prepare some data which will be later used by the kernel. This preparation might take some time so I would like to know if it is dangerous to call in Java script.invoke_somefunc() and then immediately call script.forEach_kernel()?

解决方案

1) You could use rs.finish() to make sure you wait for the kernel to finish. Kernel execution is indeed asynchronous in RS.

2) We only allow one kernel to execute at a time (ignoring ScriptGroup, where you have a DAG of kernels, and thus maybe some additional room for optimizations). In this case, your second kernel won't start running until the first kernel completes.

3) Invokable functions (i.e. things you run with invoke_*() from Java) are not asynchronous. You will block until they complete on the Java side. Thus, they will block each other, or kernels. If you have a kernel followed by an invoke, you will asynchronously start the kernel, but the invoke won't begin until the kernel finishes. You will then be waiting for the invoke to finish as well.

One more detail. If your initializer doesn't require parameters, you can put it in an actual "void init(void)" function. Those get run once when the ScriptC is created.

这篇关于RenderScript闭锁功能invokation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆