How to create a new object in C# Hybridizer CUDA code

0

As mentioned in Hybridizer's documentation, you can't use the new x() method of instantiating an object in Hybridizer CUDA code.

I tried to use this method, but it would give an error related to the use of typeof(x)

[ERROR] : 0X6079 : EnrichMethodDependencyGraph failed for method System.Type -- Exception: System.NullReferenceException: Object reference not set to an instance of an object.

I also tried just using it like this:

Activator.CreateInstance<x>()

But that would just give a different error that I can find no information on online.

[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)

Instantiating an object should be a very simple thing, but I can't find any way to do it online... Does anyone know how?

c#
hybridizer
asked on Stack Overflow Apr 5, 2020 by Caleb Johnson • edited Apr 5, 2020 by talonmies

1 Answer

1

Using typeof(x) requires object type information, which is not made available on the GPU side. Activator.CreateInstance<x> is essentially the same thing.

The limitation does not come from the new keyword, it comes from the fat that garbage collection is not implemented on the GPU side.

Possible workarounds for your issue:

  1. Your type can be replaced by primitives : you may allocate array of primitive types on the GPU.

  2. You may define your own allocator based on a preallocated array of instances and an atomic index.

answered on Stack Overflow Apr 6, 2020 by Florent DUGUET

User contributions licensed under CC BY-SA 3.0