c# - 如何在 C# Hybridizer CUDA 代码中创建新对象
问题描述
如Hybridizer 的文档中所述,您不能使用新的 x() 方法在 Hybridizer CUDA 代码中实例化对象。
我尝试使用此方法,但它会给出与使用 typeof(x) 相关的错误
[ERROR] : 0X6079 : EnrichMethodDependencyGraph failed for method System.Type -- Exception: System.NullReferenceException: Object reference not set to an instance of an object.
我也试过像这样使用它:
Activator.CreateInstance<x>()
但这只会给出一个不同的错误,我在网上找不到任何信息。
[ERROR] : 0X6079 : EnrichMethodDependencyGraph failed for method System.Activator -- Exception: System.ArgumentException: A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
实例化一个对象应该是一件很简单的事情,但是我在网上找不到任何方法......有谁知道怎么做?
解决方案
使用typeof(x)
需要对象类型信息,这在 GPU 端不可用。Activator.CreateInstance<x>
本质上是一样的。
限制不是来自new
关键字,而是来自GPU端没有实现垃圾收集的胖子。
您的问题的可能解决方法:
您的类型可以替换为原始类型:您可以在 GPU 上分配原始类型数组。
您可以根据预先分配的实例数组和原子索引定义自己的分配器。
推荐阅读
- python - 为什么我找不到 lsvirtualenv 命令?
- anylogic - SelectOutput 基于条件(自定义分布)
- python - 检查目标时出错:预期 concatenate_1 的形状为 (1,) 但得到的数组的形状为 (851,)
- asp.net - 反序列化、编辑和保存 JSON 文件
- c# - Azure ASP.NET WebAPI 性能
- r - devtools::check() 在 devtools::test() 通过时失败,因为并非 test 中的所有测试文件都复制到 [r]
- python - “'int' 对象不可迭代” Tkinter 按钮
- r - 带有colorRampPalette的viridis在R中输出不同的向量长度
- winapi - 媒体基金会捕获反转图像
- python - 在 Python 中的函数外部设置变量