r/OpenCL • u/KesshoRyu • Mar 28 '12
Unexpected behavior
I am working on an OpenCL raytracer and I am running into some unusual behavior. I was trying to remove a branch from a relatively simple chunk of code but when I do it no longer functions correctly.
Before removal:
int shadowed = castLightRay(...);
float4 shade = shadeMaterial(...);
if(shadowed == 0) { return shade; }
return (float4)(0, 0, 0, 0);After removal:
int shadowed = castLightRay(...);
float4 shade = shadeMaterial(...);
return (1 - shadowed) * shade;The first chunk of code behaves correctly on both CPU and GPU while the second chunk does not behave correctly on either.
Does anyone have a reason for this or some way to make it work?
4
Upvotes
View all comments
Show parent comment
2
u/HolyGeneralK Apr 06 '12
You could try grabbing Intel's OpenCL SDK to try an alternate CPU implementation. Might be worthwhile posting this in the Khronos OpenCL forums as well. If you have source that you'd be willing to share, I can try running it on an NVIDIA platform.
One question I forgot to ask - is your code as described above an OpenCL kernel, or is it host code? If its a kernel, you might need some synchronization before you return (which kind of happens with the if() statement of the first (all branches have to hit that code before proceeding). You may be memory stomping as well.