OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 15 Jul 2015 12:33:09 -0500Weird behavior of ocl matrix in opencvhttp://answers.opencv.org/question/33132/weird-behavior-of-ocl-matrix-in-opencv/
Hi,
I am faciong a qweird problem. I have two matrix, input and output. For each element i in a row r in the input matrix,
it sums all element before i in that row and put the sum in i th column and r th row in output matrix.
When I do this for small matrix, it gives me no problem. But for a big matrix (604x454),
the output matrix contains GRARBAGE value in all output matrix rows except the first row.
"__kernel void "
" v2_integral_cols_sum(__global uchar *src,\n"
"int rows,int cols,__global int *lm_sum, int pixels,int steps,int o_steps)\n"
"{\n"
"int gid=get_global_id(0);\n"
"if(gid>=pixels)"
"return;\n"
"else \n"
"{"
"int x = gid % steps;\n"
"int y = gid / steps;\n"
"int sum=0;\n"
"for (int i=0;i<=x;i++)"
"{\n"
"sum=sum+src[y * steps + i];\n"
"}\n"
"lm_sum[y*o_steps + x]=sum;\n"
"}"
"}\n"
interestingly if I use the printf statement after the output assignment statement as in this block,I get correct output matrix.
I do not find any explanation of this weird behavior. Anyone can help me?
"lm_sum[y*o_steps + x]=sum;\n"
"if(gid==640)\n"
"{"
"printf(\"lm_sum [%d %d %d] %d \",x,y,gid,lm_sum[y * o_steps+ x]);\n"
"}\n"Sun, 11 May 2014 12:25:11 -0500http://answers.opencv.org/question/33132/weird-behavior-of-ocl-matrix-in-opencv/Answer by Neamah for <p>Hi,</p>
<p>I am faciong a qweird problem. I have two matrix, input and output. For each element i in a row r in the input matrix,
it sums all element before i in that row and put the sum in i th column and r th row in output matrix.
When I do this for small matrix, it gives me no problem. But for a big matrix (604x454),
the output matrix contains GRARBAGE value in all output matrix rows except the first row.</p>
<pre><code>"__kernel void "
" v2_integral_cols_sum(__global uchar *src,\n"
"int rows,int cols,__global int *lm_sum, int pixels,int steps,int o_steps)\n"
"{\n"
"int gid=get_global_id(0);\n"
"if(gid>=pixels)"
"return;\n"
"else \n"
"{"
"int x = gid % steps;\n"
"int y = gid / steps;\n"
"int sum=0;\n"
"for (int i=0;i<=x;i++)"
"{\n"
"sum=sum+src[y * steps + i];\n"
"}\n"
"lm_sum[y*o_steps + x]=sum;\n"
"}"
"}\n"
</code></pre>
<p>interestingly if I use the printf statement after the output assignment statement as in this block,I get correct output matrix.
I do not find any explanation of this weird behavior. Anyone can help me?</p>
<pre><code>"lm_sum[y*o_steps + x]=sum;\n"
"if(gid==640)\n"
"{"
"printf(\"lm_sum [%d %d %d] %d \",x,y,gid,lm_sum[y * o_steps+ x]);\n"
"}\n"
</code></pre>
http://answers.opencv.org/question/33132/weird-behavior-of-ocl-matrix-in-opencv/?answer=66406#post-id-66406The printf probably makes the kernel fail to compile and defaults to using the CPU. This happened to me when I tried adding a printf statement. There's a certain way printf's need to be added. Check this link out: https://www.khronos.org/registry/cl/extensions/arm/cl_arm_printf.txt
Again, check to make sure after adding printf that your code is ACTUALLY calling the kernel successfully. Wed, 15 Jul 2015 12:33:09 -0500http://answers.opencv.org/question/33132/weird-behavior-of-ocl-matrix-in-opencv/?answer=66406#post-id-66406