1

我正在尝试Gpu.Default.For从 Alea GPU 库中使用,但我不断收到异常:

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);
//});
}
4

1 回答 1

3

两件事:首先,您在 GPU 代码中新建了一个数组,这是不受支持的。其次,我猜CalcResultsList是 type List,也不支持。原因是,在 GPU 代码中分配新内存效率不高。GPU 代码将使用多个线程执行,不建议在 GPU 代码内部分配。

于 2017-06-06T11:48:54.763 回答