1

I'm a hobbyist and would like to utilize my GPU for my personal projects. I've gotten the Alea GPU package installed and working.

This below produces the same output:

    Dim y(10) As Integer
    For i = 0 To 10 - 1
        y(i) = i
    Next
    Dim y2(10) As Integer

    Array.Copy(y, y2, y.Length)

    Parallel.For(0, y.Length - 1, Sub(i) y(i) += i)
    Debug.WriteLine(y.Aggregate(Function(now, future) now + future))

    Alea.Gpu.Default.For(0, y2.Length - 1, Sub(i) y2(i) += i)
    Debug.WriteLine(y2.Aggregate(Function(now, future) now + future))

Both return 90. That's the most basic but what i need is a lot more.

I'm trying to convert my other more resource intensive parallel.foreach loops into GPU.Default.For, so i can utilize the full power of my PC.

Keep in mind that all this worked flawlessly as a parallel.foreach loop. The rest of the code is currently commented out, this is the thing that prevents it from working.

Gpu.Default.For(0, Inventory.ItemsInventory.Count - 1,
                Sub(i)
                        Dim Level_1 = Inventory.ItemsInventory.ElementAt(i) 'Exception on this line, doesn't happen if commented out.
                end sub)

'Inventory' is a custom class, where 'ItemsInventory' is a dictionary(of string, InventoryItem) 'InventoryItem' is also a custom class.

The exception i'm getting is:

ArgumentException thrown: 'System.Exception' in Alea.dll Additional information: Cannot get field "$VB$Local_Inventory".

Next i tried to define an Array of 'InventoryItem' as that was what i was interested in for this particular loop.

Dim ItemsArray() As InventoryItem = Inventory.ItemsInventory.Select(Function(f) f.Value).ToArray
                Gpu.Default.For(0, ItemsArray.Length - 1,
                Sub(i)
                        Dim Level_1 = ItemsArray(i)
                end sub)

This is what i get now:

Exception thrown: 'System.Exception' in Alea.dll Additional information: Non-blittable array MyApp.MainWindow+InventoryItem[] transferring is not allowed, you can change this by app.config.

But i don't know how that part looks like, that i 'can' add to the app.config file, i haven't found anything online to solve this.

VampireMonkey
  • 177
  • 2
  • 11
  • Why is this marked c#? –  Mar 07 '17 at 00:24
  • @MickyD It was one of the suggested tags, since vb.net and c# are so similar someone with the same problem could potentially find a solution here. If that's not the way to go with it, should i remove the tag? – VampireMonkey Mar 07 '17 at 00:26
  • That first error message seems to suggest that `Inventory` is a member variable and only local variables are supported in that context. Assuming that it is a field, try declaring a local and assign the field value to it and using that in your lambda. The reason for such a restriction could be that a field could be changed from elsewhere. – jmcilhinney Mar 07 '17 at 06:04
  • @jmcilhinney Isn't that what i've done in with the array? – VampireMonkey Mar 07 '17 at 19:03

1 Answers1

0

With regards to the second exception, the following page shows the basics of setting up Alea GPU in a .NET config file:

http://www.aleagpu.com/release/3_0_2/doc/faq.html

After reading that, I checked the documentation for the Alea.Settings type and found that it has a Memory property of type SettingElements.MemoryElement.

http://www.aleagpu.com/release/3_0_2/api/html/73614a0a-9c5c-cce6-7114-fc6833cb31f2.htm

That type has a Boolean property AllowNonBlittableMemoryTransfer.

That suggests that, to allow non-blittable types in your scenario, your config file should look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="aleaSettings" type="Alea.Settings, Alea"/>
  </configSections>
  <aleaSettings>
    <memory allowNonBlittableMemoryTransfer="true"/>
  </aleaSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
</configuration>
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • Okay so now i've gotten past of that bittable issue, now i'm getting this instead: `An unhandled exception of type 'System.Exception' occurred in mscorlib.dll Additional information: Unsupported of unmanaged marshaler for type MyApp.MainWindow+InventoryItem(i32).` If i understand this right, it says there's a problem at index 32, not sure what the additional information means. – VampireMonkey Mar 07 '17 at 18:53
  • That 'i32' part is probably referring to a 32-bit integer, i.e. an `Integer` in VB. I've never used Alea GPU and, in fact, never even heard of it before reading this question so I'm far from an expert. The fact that it doesn't support non-blittable (not bittable) types by default and this new error message about not supporting marshalling your custom type suggests that it is intended for use with simple type only. I don't know what the solution is but I do know that you probably need to do a bit more research on what it supports. – jmcilhinney Mar 07 '17 at 23:37