C#/OpenCL - 2D array as kernel argumment

339 Views Asked by At

I'm using the Cloo libary for C#.

I can't figure out or find anything about how to add a 2D array as a kernel argument.

Here is my code:

ComputeBuffer<char> field = new ComputeBuffer<char>(Program.context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, veld);

It just gives me the error: 'Cannot convert from char[,] to long'. Implying it sees it as one of other the overloads.

What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

veld

variable should be contiguous memory area. Use 1D array but enough size to use as a 2D array on device side.

When you need host side operations, access with i+w*j indexing for imitating 2D access. This may not be a performance loss if you do this in an unsafe context using pinned array.