Setting up Array in Local Memory

So here is my story: I started using the other JOCL, and had some difficulties with seg faults when running kernels with it so I’ve decided to switch over to this one.

And the question: I have a kernel that computes a single generation of the Game of Life, in this kernel I use arrays in the local memory for work groups to cache data from an array in global memory. How is the code for setting up this kernel argument different from that for setting up an array in global memory?

Here is the header for the kernel function:

__kernel void Generation( constant char* i, global char* o, local char* localMem, int numElements, int localSize)

and here is how I am currently (failing) trying to setup my kernel arguments:

clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(memObjects[0]));
        clSetKernelArg(kernel, 1, Sizeof.cl_mem, Pointer.to(memObjects[1]));
        clSetKernelArg(kernel, 2, Sizeof.cl_mem, Pointer.to(memObjects[2]));
        clSetKernelArg(kernel, 3, Sizeof.cl_uint, Pointer.to(new int[] { elementCount }));
        clSetKernelArg(kernel, 4, Sizeof.cl_uint, Pointer.to(new int[] { localArray.length }));

Hello

There is nothing to be passed to a kernel as an argument to set up local memory. You just have to specify the size. So for the kernel you posted, it should be

clSetKernelArg(kernel, 2, localMemorySize, null);

BTW, concerning the SegFaults: They may have many, many reasons, of course. But there seems to be a general problem with JNI on Linux, and here is how it may be solved:
http://code.google.com/p/javacl/wiki/TroubleShootingJavaCLOnLinux
Just in case you also want to give the other JOCL another try.

bye
Marco

Thank you very much for the help. And for the tip as to why I might have been having issues with the other JOCL (or linux rather).

Since you brought that up, is that particular issue why you stay away from using linux as your host environment? I remember you saying something about using windows for opencl programming.

I thought of another question:
What is the significance of the Sizeof.cl_mem tag? In the sample you provide that just multiplies two small arrays, the two source arrays are similarly to this

clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(memObjects[0])); 

while arrays that are written to are set using the size of the array. I assume clSetKernelArg figures out how big the input arrays are using it’s associated Pointer?

At the moment I’m mainly using Windows, but not because of this specific issue.

The third argument of clSetKernelArg is the size of the argument. This is NOT the size of the buffer or array, but only the size of the argument that is passed in. (In fact, Sizeof.cl_mem is usually equal to Sizeof.POINTER)

Some examples:

// For __kernel void k(short oneShort) { ... } :
clSetKernelArg(kernel, 0, Sizeof.cl_short, pointerToOneShort);

// For __kernel void k(int *intPointer) { ... } :
clSetKernelArg(kernel, 0, Sizeof.cl_mem, pointerToOneClMem);

// For __kernel void k(float4 oneFloat4) { ... } :
clSetKernelArg(kernel, 0, Sizeof.cl_float4, pointerToFourFloats);

Ok thank you very much this clears up much confusion on my end.
Cheers