我正在尝试使用 Alea GPU 库中的 Gpu.Default.For
,但我一直收到异常:
i32 is not a struct type error.
这个错误是什么意思,为什么我用这个简单的 Gpu.Default.For
循环得到它?
for (Int32 j = 0; j <= TimePeriodArray.Length - 1; j++)
//Gpu.Default.For(0, TimePeriodArray.Length - 1, j =>
{
Int32 days = TimePeriodArray[j];
Double[] CalcResult = new Double[CloseArray.Length];
for (Int32 Index = days; Index <= CloseArray.Length - 1; Index++)
{
Gpu.Default.For(Index - 1, Index - days, i =>
{
CalcResult[Index] = CalcResult[Index] + CloseArray[i];
});
CalcResult[Index] = CalcResult[Index] / days;
}
CalcResultsList.Add(CalcResult);
//});
}
最佳答案
两件事:首先,您在 GPU 代码中新建了一个数组,这是不受支持的。其次,我猜 CalcResultsList
是 List
类型,同样不受支持。原因是,在 GPU 代码中分配新内存效率不高。 GPU 代码会被很多线程执行,不推荐在 GPU 代码内部分配。
关于c# - 抛出异常 : 'System.Exception' in Alea. dll“i32 不是结构类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44330186/