是否可以在Cudafy.NET中使用volatile关键字?

问题描述:

我需要声明一个数组传递给一个函数,volatile是否Cudafy.NET支持这个?是否可以在Cudafy.NET中使用volatile关键字?

例如(在C#):

[Cudafy] 
private static void doStuffOnGPU(GThread thread, volatile int[] output) 
{ 
    //do a whole bunch of stuff 
} 

答案是否定的,如2016年11月26日,Cudafy.NET不支持volatile关键字。但是,您可以将Cudafy.NET放到允许某些情况下。

例:

//declare a dummy in global scope 
public static int[] volatileArray = new int[256]; 
[Cudafy] 
private static void doStuffOnGPU(GThread thread, int[] output) 
{ 
    //use the GThread.InsertCode() function to declare in CUDA 
    GThread.InsertCode("__shared__ volatile int volatileArray[256];"); 
    //do a whole bunch of stuff 
} 

这段代码时将使用的测试顺序运行全局声明,并且将使用GPU上的挥发性声明。