PDA

View Full Version : 2 dimensions' array



dollarzuke
05-21-2010, 12:07 AM
I'm still new to opencl and not used to the programming yet.
I'm just wondering that is it possible to use a 2 dimensions' array in Opencl...??
i tried to search in google but found nothing.
Ex:
Like we do in C " int array[][];"

help me out please.

dominik
05-21-2010, 12:16 AM
You can create 2-dimensional private or local arrays inside a kernel.
However, you cannot create 2-dimensional global arrays unless you want to use images. Buffers created with clCreateBuffer are always linear, but you can use macros to access them like 2-dimensional arrays, e.g.:


#define A(x,y) a[x*width + y]

Joky
10-19-2011, 01:29 AM
Is it stated in the standard that a kernel argument cannot be a 2-dimensional array ?

A kernel with a "float arg[10][10]" argument works with Nvidia implementation but not with AMD one.

I only find in the 1.1 standard that a buffer should be linear (A 2-dimensional array is a bunch of linear memory AFAIK), and that VLA array aren't supported.

david.garcia
10-19-2011, 02:55 PM
Is it stated in the standard that a kernel argument cannot be a 2-dimensional array?

Section 5.7.2. says that


"If the argument is declared to be a pointer of a built-in scalar or vector type, or a user defined structure type in the global or constant address space, the memory object specified as argument value must be a buffer object (or NULL)"

...but it doesn't say anything about arrays. I'll ask the Working Group for a clarification.

Joky
11-09-2011, 08:40 AM
Do you mean you'll ask for a clarification for a further release or will we get it for 1.1 ?

Joky
11-17-2011, 06:00 AM
Seems that 1.2 clarified the situation in 3.5 :


Memory objects are categorized into two types: buffer objects, and image objects. A buffer
object stores a one-dimensional collection of elements whereas an image object is used to store a
two- or three- dimensional texture, frame-buffer or image.