问题描述
我是一个业余爱好者,想将我的 GPU 用于我的个人项目.我已经安装并运行了 Alea GPU 包.
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.
下面产生相同的输出:
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))
两者都返回 90.这是最基本的,但我需要更多.
Both return 90. That's the most basic but what i need is a lot more.
我正在尝试将我的其他资源密集型 parallel.foreach 循环转换为 GPU.Default.For,以便我可以充分利用我的 PC.
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.
请记住,所有这些都可以完美地作为 parallel.foreach 循环运行.其余代码目前已被注释掉,这是阻止它工作的原因.
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'是一个自定义类,其中'ItemsInventory'是一个字典(字符串,InventoryItem)'InventoryItem'也是一个自定义类.
'Inventory' is a custom class, where 'ItemsInventory' is a dictionary(of string, InventoryItem) 'InventoryItem' is also a custom class.
我得到的例外是:
ArgumentException 抛出:Alea.dll 中的System.Exception"附加信息:无法获取字段$VB$Local_Inventory".
接下来,我尝试定义一个InventoryItem"数组,因为这是我对这个特定循环感兴趣的内容.
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)
这就是我现在得到的:
抛出异常:Alea.dll 中的System.Exception"附加信息:不允许非 blittable 数组 MyApp.MainWindow+InventoryItem[] 传输,您可以通过 app.config 更改此设置.
但我不知道那部分是什么样子的,我可以"添加到 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.
推荐答案
关于第二个例外,以下页面显示了在 .NET 配置文件中设置 Alea GPU 的基础知识:
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
阅读后,我检查了 Alea.Settings
类型的文档,发现它具有 SettingElements.MemoryElement
类型的 Memory
属性>.
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
该类型具有 Boolean
属性 AllowNonBlittableMemoryTransfer
.
That type has a Boolean
property AllowNonBlittableMemoryTransfer
.
这表明,为了在您的场景中允许非 blittable 类型,您的配置文件应如下所示:
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>
这篇关于使用 Alea GPU 迭代一组自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!