【问题标题】:How to create a new object in C# Hybridizer CUDA code如何在 C# Hybridizer CUDA 代码中创建新对象
【发布时间】:2020-07-17 01:51:46
【问题描述】:

正如Hybridizer's documentation, 中所述,您不能使用新的 x() 方法在 Hybridizer CUDA 代码中实例化对象。

我尝试使用this method,但它会给出与使用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)

实例化一个对象应该是一件很简单的事情,但是我在网上找不到任何方法......有谁知道怎么做?

【问题讨论】:

    标签: c# hybridizer


    【解决方案1】:

    使用typeof(x) 需要对象类型信息,这在 GPU 端不可用。 Activator.CreateInstance&lt;x&gt; 本质上是一样的。

    限制不是来自new关键字,而是来自GPU端没有实现垃圾收集的胖子。

    针对您的问题的可能解决方法:

    1. 您的类型可以被基元替换:您可以在 GPU 上分配基元类型数组。

    2. 您可以根据预先分配的实例数组和原子索引定义自己的分配器。

    【讨论】:

    • 感谢您的回答。不幸的是,原语无法满足我对此的需求,因此 1 对我不起作用。你能解释一下我会怎么做2吗?
    猜你喜欢
    • 2015-01-29
    • 2023-03-09
    • 2013-02-15
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多