سؤال

I want to do this in a kernel:

int count[8];

I'm almost positive you can declare fixed size arrays within CUDA GPU kernels. So how do I go about doing this while using Cudafy? This does not work:

[Cudafy]
public static void kernelFunction(int[] input, int[] output)
{
  int count[8];
  // ....other stuff
}

The above code results in a C# error: "Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)."

هل كانت مفيدة؟

المحلول

According to the Cudafy.NET forums and as of 03/20/2014, this is not currently supported. So I added this answer in order to alleviate future people from the futile search for a solution. The thread where the above is stated is here.

Note that the person in the thread who suggests the proper way to do it is to use shared memory is wrong. You can declare fixed size arrays in GPU kernels, Cudafy just does not currently support it. Shared memory is for increasing the scope of variables such that all threads within a block have access to them. It also acts as a spill-over location for variable storage when registry storage is full. Stating that shared memory is the sole location for array declarations is incorrect.

نصائح أخرى

In C#, you would do something like this:

int[] count = new int[8];

Or if you are using unsafe code, you can also create fixed size buffers:

fixed int count[8];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top