0

我需要将传递给函数的数组声明为 volatile,Cudafy.NET 支持吗?

例如(在 C# 中):

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

1 回答 1

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 声明。

于 2016-11-26T22:25:00.470 回答