Ask Your Question

Weird behavior of ocl matrix in opencv

asked 2014-05-11 12:25:11 -0500

mainul gravatar image


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"

                "int gid=get_global_id(0);\n"
                "else \n"
                "int x = gid % steps;\n"
                "int y = gid / steps;\n"
                "int sum=0;\n"

                "for (int i=0;i<=x;i++)"
                    "sum=sum+src[y * steps + i];\n"

            "lm_sum[y*o_steps + x]=sum;\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"

            "printf(\"lm_sum [%d %d %d] %d  \",x,y,gid,lm_sum[y * o_steps+ x]);\n"

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-07-15 12:33:09 -0500

Neamah gravatar image

The 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:

Again, check to make sure after adding printf that your code is ACTUALLY calling the kernel successfully.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-05-11 12:25:11 -0500

Seen: 78 times

Last updated: Jul 15 '15