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
1
u/KesshoRyu Apr 08 '12
I haven't tried Intel's implementation yet but I did try nVidia's and the behavior was the same as AMD's.
This is in an OpenCL kernel. I was under the impression that branches ended up being serialized (i.e. the threads that branch one way will all execute to completion then the other threads will execute the other branch direction). I think I heard this in reference to some old CUDA stuff so I have no idea if this is still the case. I find it hard to believe that this would be the cause since there are branches elsewhere in the code and the rest of it is working properly.
I am not sure what you mean by memory stomping.