2013-01-01 35 views
1

我正在使用CUDA C進行評估,現在開始使用cudafy .net。將Enum傳遞給使用Cudafy .Net的內核

讓我們假設我有以下枚舉

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

我想將它傳遞給內核

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

我分配內存

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

在運行時,程序崩潰在消息線與消息

Error Message

我需要解決什麼問題?

回答

1

你不需要自己分配內存。 只要告訴cudafy模塊你想使用什麼結構類型。從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); 
    } 
} 
1

試圖用簡單int取代enum