Hi.
Im trying to create an 3D array and then having the kernel to iterate over it and do some calculations.
Its like a cube formated as 10x10x10 positions.
As a template I using Marco13s very good 2D example that Im trying to convert into 3D.
As of now the the kernel just calculates like every 100th value for some reason. I have been using different values in a[] (see kernel below)
but I not sure what the correct is. I need to get values between 0-999 but I cant figure out how globalId can do that when all three get_global_id() needs to be combined.
The kernel look like
__kernel void sampleKernel(__global float *a)
{
int gidX = get_global_id(0);
int gidY = get_global_id(1);
int gidZ = get_global_id(2);
a[???] *= 2; //just doubles the values to get the example to work
}
Creating the 3D array and also filling it with data(exluded in this post)
int arrayXLength = 10;
int arrayYLength = 10;
int arrayZLength = 10;
float array[][][] = new float[arrayXLength][arrayYLength][arrayZLength];
Im allocating memory as:
cl_mem mem = clCreateBuffer(context, CL_MEM_READ_WRITE, Sizeof.cl_float * arrayXLength * arrayYLength * arrayZLength, null, null);
Im executing the kernel as:
clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(mem));
clEnqueueNDRangeKernel(commandQueue, kernel, 2, null, new long[]{arrayXLength + ??? + ??? + ???}, null, 0, null, null);
Im writing and reading to buffer as below, I guess there are some issues here with the loop and arrays length
private static void writeBuffer3D(cl_command_queue commandQueue, cl_mem buffer, float array[][][])
{
long byteOffset = 0;
for (int y = 0; y < array.length; y++)
{
for (int x = 0; x < array.length; x++)
{
int bytes = array[x][y].length * Sizeof.cl_float;
clEnqueueWriteBuffer(commandQueue, buffer, CL_TRUE, byteOffset, bytes, Pointer.to(array[y][x]), 0, null, null);
byteOffset += bytes;
}
}
}
private static void readBuffer3D(cl_command_queue commandQueue, cl_mem buffer, float array[][][])
{
long byteOffset = 0;
for (int y = 0; y < array.length; y++)
{
for (int x = 0; x < array.length; x++)
{
int bytes = array[x][y].length * Sizeof.cl_float;
clEnqueueReadBuffer(commandQueue, buffer, CL_TRUE, byteOffset, bytes,Pointer.to(array[y][x]), 0, null, null);
byteOffset += bytes;
}
}
}
Anyone got some good tips how I can solve this?
Thanks
//Fredrik