Thanks, Tesan and Heribert.
Although my question is really why doesn't the OpenCL implementation give the same results as VEX given the same initial conditions? And why would the openCL vary even when just pressing "Reset Simulation", as all the parameters are the same?
I have tried using different combinations of int and float, but the rules should result in 1 or 0 given the number of neighbours. I can't see where the error would creep in.
Please see attached file, it should work, I am using Houdini 18.0.287. The openCL code is below:
float convolve(int idx, int resx, int resy, global float* a)
{
// Mirror coords.
int l = 1;
int r = 1;
if (idx % resx == 0)
l = -l;
else if (idx % resx == resx - 1)
r = -r;
int b = resx;
int t = resx;
if (idx < resx)
b = -b;
else if (idx >= resx * (resy - 1))
t = -t;
// Return weighted sum.
return a[idx+t-l] * 2 +
a[idx+t] * 2 +
a[idx+t+r] * 2 +
a[idx-l] * 2 +
a[idx] * 1 +
a[idx+r] * 2 +
a[idx-b-l] * 2 +
a[idx-b] * 2 +
a[idx-b+r] * 2;
}
kernel void gol(
int ca_length,
global float * ca ,
int resx_length,
global int * resx ,
int resy_length,
global int * resy
){
int idx = get_global_id(0);
if (idx >= ca_length)
return;
int array[] = {0,0, // number of neighbours = 0
0,0, // number of neighbours = 1
0,1, // number of neighbours = 2
1,1, // number of neighbours = 3
0,0,
0,0,
0,0,
0,0,
0,0};
float neighbours = convolve(idx, resx[idx], resy[idx], ca);
int rule = int(neighbours);
ca[idx] = array[rule];
}
GOL_openCL_vex_02.hipnc