【发布时间】:2016-07-17 06:31:54
【问题描述】:
在 OpenCL 中运行一些测试代码(使用 Cloo C#)时,我开始从 OpenCL 收到这些 OutOfResource 错误,有时 Unity 在我收到异常之前就完全崩溃了。我基本上是用不同数量的全局/本地工作项一遍又一遍地重新调用内核函数来检查时间。我将参数保持不变,并以 2x2x2 全局和 2x2x2 局部开始调用内核,并向上迭代,仅检查有效大小。它偶尔可以正常工作,但大多数时候它会完成大约 30 或 40 次 Execute() 调用,然后在下一次 Execute() 调用时崩溃。
注意:执行是指计算机上的 OpenCL.dll。由于本机代码,我假设 Unity 返回的堆栈跟踪为 NULL。
有人知道是什么原因造成的吗?
注意:这个版本的 Cloo 是来自 GitHub 的 Cloo-Unity,我在 Unity 中使用它。当我收到错误时调用的等效 OpenCL 函数是 clEnqueueNDRangeKernel(),但在 Cloo 中它被称为 Execute()。
代码示例:
//Setup inputs one time...
foreach (var input in p_inputs)
{
inputs.Add(input.Function, input);
profiles.Add(input.Function, new RunProfile(input.Function, input.Weight));
input.Input.Prepare(package[input.Function]);
}
//Profile...
DateTime start;
int g_state = 0;
int l_state = 0;
long[] g = new long[3] { 2, 2, 2 };
long[] l = new long[3] { 2, 2, 2 };
while(g[0] * g[1] * g[2] < Device.MaxWorkGroupSize)
{
l[0] = 2; l[1] = 2; l[2] = 2; l_state = 0; //Reset locals
bool proceed = true;
while(proceed)
{
proceed = (l[0] != g[0] || l[1] != g[1] || l[2] != g[2]);
if (CLUtilities.ValidateExecutionParameters(Device, g, l))
{
Debug.Log("Profiling Start: " + g.ToEnumeratedString() + " / " + l.ToEnumeratedString());
foreach (var profile in profiles)
{
start = DateTime.Now;
//Exception here when on (g=6x4x4, l=6x4x4)
package.Execute(package[profile.Key], g, l);
package.Commands.Flush();
package.Commands.Finish();
float time = (float)(DateTime.Now - start).TotalMilliseconds;
profile.Value.AddRun(g, l, time);
}
Debug.Log("Profiling Ending: " + g.ToEnumeratedString() + " / " + l.ToEnumeratedString());
}
l[l_state] += 2;
l_state = (l_state == 2) ? 0 : l_state + 1;
}
g[g_state] += 2;
g_state = (g_state == 2) ? 0 : g_state + 1;
}
【问题讨论】:
-
'它开始抛出这个错误' => 至少提供堆栈跟踪以及它在代码示例中发生的位置(即我假设在 package.Execute 但谁知道)。
-
我会编辑它,但问题是我评论它发生在执行时,但是,堆栈跟踪 Unity 输出说堆栈跟踪为空。 (我假设因为它发生在本机 OpenCL DLL
-
unity 是否在某个扩展名下使用任何其他 opencl 作为加速...
-
好吧,OpenCL 没有在任何地方统一使用,但 gpu 可以。但是,我的分析器说还剩下 5GB 内存