dwootton

Missing loop condition test in OpenCL for loop

Discussion created by dwootton on Dec 30, 2009
Latest reply on Jan 4, 2010 by genaganna
Generated code in for loop for CPU device missing loop conditon test

I am trying to learn about OpenCL and have a kernel that isn't working correctly. I'm running a program compiled with Visual Studio 2008 on Windows 7 using the 12/21/09 OpenCL version I downloaded.

When I invoke my program in debug mode I get an exception in the dll generated for my code. When I look at the disassembly view in Visual Studio, I see code for the for loop which seems to be updating the arrays correctly. I can also see where I is incremented, where it's been optimized into register eax and eax is incremented by 4 each loop iteration. However, I don't see any loop test in the generated code, which I think explains the exception since eax no longer points to valid memory.

The code is attached


I'm invoking this via clEnqueueTask.

The odd thing is I thought I had code where the loop test was present before I rewrote this code to get rid of some pointers, but now I can't get the compiler to generate any loop test.

 

Am I doing something wrong?

Thanks

 

__kernel void computeHistogram(__global unsigned int *imageData, global int *redCounts, global int *greenCounts, global int *blueCounts, int globalCount, int threads, int index) { int count; int threads; int index; int histogramBase; int imageOffset; count = globalCount / threads; histogramBase = index * 256; imageOffset = count * index; for (int i = 0; i < count; i++) { unsigned char r; unsigned char g; unsigned char b; unsigned int pixel; pixel = imageData[imageOffset + i++]; r = pixel >> 16; g = pixel >> 8; b = pixel; redCounts[histogramBase + r]++; greenCounts[histogramBase + g]++; blueCounts[histogramBase + b]++; } }

Outcomes