My kernel returns # of bytes instead of value of variable

Hi,

I’ve setups my kernel to return a simple value to test wether the kernel is working, but I think its returning bits instead of the value.

In main, I prepped the variable passing like this:

double distances[NUM_ATOMS];

memObjects[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, NUM_RAYSsizeof(double), rayA, NULL);
memObjects[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, NUM_ATOMS
sizeof(double), NULL, NULL);

errNum = clSetKernelArg(CheckKernel, 0, sizeof(cl_mem), &memObjects[0]);
errNum |= clSetKernelArg(CheckKernel, 1, sizeof(cl_mem), &memObjects[1]);

size_t globalWorkSize[1] = { NUM_ATOMS };
size_t localWorkSize[1] = { 1 };

errNum = clEnqueueNDRangeKernel(commandQueue, CheckKernel, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, NULL);

clFinish(commandQueue);

errNum = clEnqueueReadBuffer(commandQueue, memObjects[1], CL_TRUE, 0, NUM_ATOMS*sizeof(double), distances, 0, NULL, NULL);

for(t=0;t<NUM_ATOMS;t++)
{
cout << distances[t] << endl;
}

The kernel:

__kernel void Check_for_intersection(__global const double rayA,
__global double *distances){
int gid = get_global_id(0);
distances[gid] = 0;
}

I’ve tried many different values for distances and got this:

distances[gid] = 0; returns 0.0078125
distances[gid] = 1; returns 32
distances[gid] = 2; returns 2048
distances[gid] = 3; returns 32768
distances[gid] = 4; returns 262144
distances[gid] = 5; returns 1.04858e+06
distances[gid] = 6; returns 4.19431e+06
distances[gid] = 7; returns 1.67772e+07
distances[gid] = 8; returns 5.03317e+07
distances[gid] = 9; returns 1.00663e+08

Also, if I do math in the kernel with a passed variable like:

double a = 1;
distances[AtomID] = a + rayA;

I get this error:

Error in kernel:
<program source>:16:27: error: invalid operands to binary expression (‘double’ and ‘double const attribute((address_space(1))) *’)
distances[AtomID] = a + rayA;
’ ~ ^ ~~~~

Does anyone have a clue what’s wrong?

So I switched the double to float and solved that problem, but I’m having trouble passing anything of int type. Any suggestions?

int index = 0;
memObjects[9] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &index, NULL);

__kernel void hello_kernel(__global const float *phiC,
__global const float *psiC,
__global float *distances,
__global const float *phiS,
__global const float *psiS,
__global const float *atomX,
__global const float *atomY,
__global const float *atomZ,
__global const float *radii,
__global const int *index){
int gid = get_global_id(0);
distances[gid] = index;
}

The rest of my variables work fine

Error in kernel:
<program source>:12:20: error: incompatible type assigning ‘int const attribute((address_space(1))) *’, expected ‘float attribute((address_space(1)))’
distances[gid] = index;