1

I was using CUDA C for evaluation and now started using cudafy .net.

Lets assume that I have the following enum

    [Cudafy]
    public enum MyEnum
    {
       mon = 0,tue=1,wed=2,thu=3,fri=4,sat=5
    }

I want to pass it to a Kernel

    [Cudafy]
    public static void Enum_Kernel(GThread thread, MyEnum[] en)
    {
        MyEnum day = en[thread.threadIdx.x];
    }     

I am allocating memory

        MyEnum [] enum1 = new MyEnum[10];
        for (int i = 0; i < 10; i++)
        {
            enum1[i] = MyEnum.mon; 
        }
        MyEnum [] d_enum1 = gpu.CopyToDevice<MyEnum>(enum1);

During runtime, the program crashes at the aboce line with the message

Error Message

Whats the issue i need to address ?

Arjun K R
  • 427
  • 1
  • 6
  • 25

2 Answers2

1

You do not need to allocate memory by yourself. Just tell the cudafy module what struct type you want to use.

Example from cudafy:

// in your main execution method
CudafyModule km = CudafyTranslator.Cudafy(typeof(ComplexFloat));
GPGPU gpu = CudafyHost.GetDevice(eGPUType.Cuda);
gpu.LoadModule(km);

 // the struct 
 [Cudafy]
 public struct ComplexFloat
 {
    public ComplexFloat(float r, float i)
    {
        Real = r;
        Imag = i;
    }
    public float Real;
    public float Imag;
    public ComplexFloat Add(ComplexFloat c)
    {
        return new ComplexFloat(Real + c.Real, Imag + c.Imag);
    }
 }
Georges
  • 335
  • 2
  • 13
1

Try to replace enum with simple int.

Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80