1

I am trying to use Gpu.Default.For from the Alea GPU library, but I keep getting an exception:

i32 is not a struct type error.

What does this error mean, and why am I getting it with this simple Gpu.Default.For loop?

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);
//});
}
BDL
  • 21,052
  • 22
  • 49
  • 55
  • Is [this](http://www.aleagpu.com/release/3_0_3/doc/gpu_programming_csharp.html#parallel_for) the method you are asking about? – Knowledge Cube Jun 02 '17 at 13:34
  • Yes, the error happens once the code tries to execute the Gpu.Default.For loop Gpu.Default.For(Index - 1, Index - days, i => { CalcResult[Index] = CalcResult[Index] + CloseArray[i]; }); – user2808755 Jun 02 '17 at 16:26
  • Please [edit] your question to be on-topic: include a [mcve] that duplicates the problem. Questions seeking debugging help ("why isn't this code working the way I want?") must include: (1) the desired behavior, (2) a specific problem or error and (3) the shortest code necessary to reproduce it *in the question itself*. Please also see: [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [ask]. Along with enough code to duplicate the problem, this, in part, means providing the *exact* error text produced when running the code (as text in `code format`). – Makyen Jun 04 '17 at 21:00
  • Could you humor me and set the inclusive value to 1 (the first param) of the For extension method, and the exclusive value to 10 (the second param) and tell me what happens. – WBuck Jun 05 '17 at 12:07

1 Answers1

3

Two things: first, you new an array inside GPU code, which is not supported. Second, I guess CalcResultsList is of type List, which is also not supported. The reason is, it is not efficient to allocate new memory within GPU code. GPU code will be executed with many threads, allocation inside GPU code is not recommended.

Xiang Zhang
  • 2,831
  • 20
  • 40