Altera_Forum
Honored Contributor
8 years agonested loop error in OpenCL hardware run
Hello,
My openCL project produced wrong output in hardware run, and after several days debug, I finally found out the reason. The index in one of my nested loop structure is messed up and I really don't why this would ever happen. I have a nest loop structure like this: ****----------------------------------------------------------------------**** __kernel void some_kernel() { ........ ........ for (uint m = 0; m < m_bound; m++) { for(uint n = 0; n < n_bound; n++) { ........ printf("m = %d, n = %d", m, n); } } } ........ ........ ****-------------------------------------------------------------------------**** Of course the actual code is much more complicated than this simplified version. At the the beginning of this nested loop structure, m got incremented before n reaches its loop bound!! the output is like this: ****-------------------------------------------------------------------------**** m = 0, n = 0 m = 1, n = 0 m = 0, n = 1 m = 1, n = 1 m = 0, n = 2 m = 1, n = 2 ............. ............. ****-----------------------------------------------------------------------**** And this only happens at the first few iterations(Only when m is 0 or 1). This is extremly weird, since in simulation it worked perfectly. Any advice would be greatly appreciated!! Best regards, Lancer