I am writing a rather large OpenCL program with lots of function calls. I've been having problems with CL_OUT_OF_RESOURCES errors, but I managed to fix the problem with a simple printf statement. This is the code fragment in question:
...
const float color = raytrace(depthMap, triangles, ...tonMoreParameters...);
if (i == 1234) {
printf("hello\n");
}
outImage[i] = color;
...
This works fine, but if I remove the printf function, the program crashes. If I keep it in, it doesn't. When it crashes, it gives a CL_OUT_OF_RESOURCES error. Can anyone explain why adding printf makes the program not run out of resources? How can I make this work without this useless printf?
Relevant specs:
EDIT:
I've noticed that putting printf statements in other places changes the way the code operates. Some printf statements cause the program to output different numeric results, while others cause it to crash.
Even changing code that is never executed hugely changes the calculations. It's as if changing any code randomizes the way it executes.
Is this a sign of a faulty graphics card? Or perhaps a bug in the OpenCL compiler?
EDIT 2
As it turns out, recursion is not the problem. I removed all recursive calls, but printfs and other harmless changes sill change the way the code runs depending on where they are put.
This is definitely a problem rooted during compilation time.
I found the solution to my own problem.
The problem was caused by a simple array out-of-bounds error. Apparently, OpenCL does not catch these types of errors. So any attempts to read or write out of bounds could cause a silent memory corruption as it did in my case. The memory that got corrupted were the instructions for the program itself, hence the random results of execution.
The problem was also partially caused by the illegal use of recursion as mogu mentioned. Again, the OpenCL compiler lets this silently corrupt the program memory.
So be careful OpenCL developers.