0

I'm trying to convert a kernel written for Cudafy to Alea. Cudafy lets you allocate multiple arrays of different types in shared memory. Example:

int[,] paths = thread.AllocateShared<int>("path", 128, 9);
float[] best = thread.AllocateShared<float>("best", 128);

It seems in Alea, you can only allocate a single array in shared memory. I'm only seeing the following:

var lp = new LaunchParam(128, 128, 1024);
...
int[,] paths = __shared__.Array2D<int>(128, 9);

Am I missing something? Is there a way to allocate multiple arrays in shared memory in Alea?

Wil
  • 3
  • 2

1 Answers1

0

__shared__.Array2D is used in kernel to define compile-time fixed size 2D array. It cannot be used outside of kernel. Here are some examples: https://github.com/quantalea/AleaGPUTutorial/blob/master/src/csharp/examples/matrix_multiplication/MatrixMult.cs#L52

Xiang Zhang
  • 2,831
  • 20
  • 40
  • Thanks Xiang. So, what you are saying is that calling methods on shared actually creates a new allocation each time? I guess it was confusing because it requires specifying the amount of shared memory during launch. – Wil Nov 08 '15 at 16:34
  • The `__shared__.Array2D` is used to create a compile-time fixed size array. The lengths of that 2 dimension must be determined at compile-time. While you are talking about the dynamic shard memory, which is allocated during launching time. That need another API `__shared__.ExternArray();`, and this support only 1 dimension linear memory. If you need to do 2D, you have to calculate the linear address youself. Please check [here](http://quantalea.com/static/app/manual/programming_gpus-using_gpu_memories.html) for an example of dynamic shared memory usage. – Xiang Zhang Nov 08 '15 at 20:07
  • `__shared__.Array2D` actually is _defining_ a kernel fixed size array, it doesn't mean any runtime allocation. If you need extern shared array, you need _declare_ it in kernel via `__shared__.ExternArray` and then you specify the amount of shared array in `LaunchParam`. – Xiang Zhang Nov 08 '15 at 20:11