2

C# code:

    [GpuManaged, Test]
    public static void ActionFactoryWithClosure2()
    {

        var MyGPU = Gpu.Get(0);
        var arg1 = Enumerable.Range(0, Length).ToArray();
        var arg2 = Enumerable.Range(0, Length).ToArray();
        var result = new int[Length];

        Func<int[], Action<int>> opFactory = res => i =>
        {
            res[i] = arg1[i] + arg2[i];
        };

        MyGPU.For(0, arg1.Length, opFactory(result));
    }

VB.NET code:

    <GpuManaged>
    Public Shared Function GPU_TEST_VB_20170920()

        Dim MyGPU As Alea.Gpu = Gpu.Default

        Dim arg1 = Enumerable.Range(0, Length).ToArray()
        Dim arg2 = Enumerable.Range(0, Length).ToArray()
        Dim result = New Integer(Length - 1) {}
        Dim expected = New Integer(Length - 1) {}

        Dim opFactory As Func(Of Integer(), Action(Of Integer)) = Function(res) Function(i)
                                                                                    res(i) = arg1(i) + arg2(i)
                                                                                End Function


        Dim op As Action(Of Integer) = Function(i) InlineAssignHelper(result(i), arg1(i) + arg2(i))
        Dim op2 As Action(Of Integer) = Sub(i)
                                            result(i) = arg1(i) + arg2(i)
                                        End Sub

        MyGPU.[For](0, result.Length, Function(i) InlineAssignHelper(result(i), arg1(i) + arg2(i))) 'Error : The given key was not present in the dictionary.
        MyGPU.For(0, arg1.Length, opFactory(result)) 'Error : The given key was not present in the dictionary.
        MyGPU.For(0, arg1.Length, op) 'Error : The given key was not present in the dictionary.
        MyGPU.For(0, arg1.Length, op2) 'Error : Cannot get field ""$VB$Local_result. Possible reasons: -> Static field Is Not supported."

End Sub

In case of C#, I can run sample code, but in VB, I Got error message (please see above code lines) What Should I Do

Same condition : VS 2017, Windows 10, AleaGPU 3.0.3

talonmies
  • 70,661
  • 34
  • 192
  • 269
Icetiger
  • 23
  • 5
  • hi ice, this parallel for doesn't work in VB yet, (if you check the file, the test is ignored), in vb, currently you cannot use delegate, you can only code a static kernel like the first example in that file. That is why we say vb has some issue. – Xiang Zhang Sep 22 '17 at 09:09
  • Ok. As you said "you can only code a static kernel like the first example in that file." UsingKernel Method is working. UsingFor Method is now working. System.Exception: ... (Maybe KeyNotFoundException. There is no Key in Dictionary) Source location stack: -> at MyTest.TransformTest_AleaGPU+_Closure$__3-0.[Void _Lambda$__R1(Int32)] ' I will use kernel method. Thank You Very Much. – Icetiger Sep 26 '17 at 19:22

0 Answers0