Same function in kernel returning different values.

Hi

I have a program that passes a matrix into a kernel does some maths and then returns the new matrix. It worked fine in CUDA but have had this slight problem in OpenCL. However it does not always return the same value and if I return the matrix through two different variables as shown in the code through data and t_data I get slightly different numbers.

Why do test and data return different values, when they are defined in exactly the same way and have the same calculation done on them in the kernel?

What kind of problem could cause this to happen? Sorry about the poor description any thoughts at all would be greatly appreciated.

This is the maths thats not giving the same value for every point in the matrix, through some are correct and it changes from time to time.


test[loc] = data[loc] -1 ;
data[loc] = data[loc] -1;

Are you certain that no other work-items are changing data[loc] while you do this? You can test by doing:

temp a = data[loc];
test[loc] = a -1;
data[loc] = a -1;

This will eliminate questions about data[loc] being modified between the two statements, but not what happens later. (E.g., could another work-item write to data[loc] after your last write?)

This could result in different results from CUDA if the thread scheduling is different due to different work-group sizes or thread code generation. Does your CUDA code rely on any synchronization between warps? Has that been ported over to OpenCL? Are you trying to synchronize between work-groups through global variables perhaps?