In the following snippet I’m trying to use printf() in the code to try and print out the result of the input[i] calculation so I can see that it’s working correctly.
This isn’t working as I had hoped however because the quotation marks in printf() mess with the string format for the kernel such that the entire program won’t compile. I’ve tried using the escape character \" which does allow me to type the string for the kernel but when compiled gives me expected expression and missing character errors.
Does anyone know how to solve this? And is this the best way to check kernel code results?
const char *KernelSource = "\n"
"__kernel void relax( \n"
" __global double* input, \n"
" __global double* output, \n"
" __global int N) \n"
"{ \n"
" int i = get_global_id(0); \n"
" if(i > 0 && i < N-1){ \n"
" input[i] = 0.25*input[i-1]+0.5*input[i]+0.25*input[i+1]; \n"
" printf("input[%d] %f \n", i, input[i] )\n"
" } \n"
"} \n"
"\n";
You need to escape the quotes and you need to escape the
\for the\ninside the format string.