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

时间:2016-10-03 04:03:12

标签: cudafy.net

我需要声明一个传递给函数的数组作为volatile,Cudafy.NET是否支持这个?

例如(在C#中):

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

1 个答案:

答案 0 :(得分:0)

答案是否定的,截至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上使用volatile声明。