0

I am just starting with ALEA and I am curious how you can access other types and references inside a given gpu parallel.for. when i do the following i get a runtime error that states "Cannot get field random. Possible reasons: 1) Static field is not supported.2) The field type is not supported. 3) In closure class, the field doesn't have [GpuParam] attribute."

This error makes sense but I am not sure what the correct implementation would be

    [GpuManaged]
    public void InitPoints()
    {
        var gp = Gpu.Default;
        gp.For(1, (10), (i) =>
        {
            int pointStart = random.Next(totalPoints) + 1;
            Pt point = new Pt(pointStart, ptAt[i]);
            point.Process();
        });
     }
skevthedev
  • 447
  • 1
  • 7
  • 20

1 Answers1

1

You try to call the System.Random.Next. This is .NET library code and cannot be compiled to GPU. There is no MSIL behind that function that could be accessed and compiled to run on the GPU. Also the System.Random.Next is a random number generator implemented for serial applications. You should use the parallel random number generators provided in cuRand, which are also exposed in Alea GPU.

Daniel
  • 1,522
  • 1
  • 12
  • 25
  • Thanks for the answer @Daniel. I did understand this to be the issue, what I am confused about is the correct implementation/interface to get non supported gpu types to work? is it even possible. you state cuRand is able to be compiled by the GPU and that is great, but is there a way for the GPU to properly compile my custom "Pt" type. also is there a list of supported types for the GPU and where could i find this. I really appreciate the guidance – skevthedev Dec 09 '17 at 19:21
  • There are many [samples](http://www.aleagpu.com/gallery.html) on the [Alea GPU](http://www.aleagpu.com) web page. In particular work through [this sample](http://www.aleagpu.com/release/3_0_4/doc/samples/aleasample_cs_financeasianoptionmontecarlo.html). It is more complex than what you need but should give you enough understanding how you should think if you program GPUs. – Daniel Jan 05 '18 at 09:15
  • Hi @skevthedev did you ever find a suitable way of doing this? I am running in exactly the same issues on my side, and there is not a lot of examples out there on how to use alea. – woofwoof Nov 27 '18 at 20:09