View Full Version : reg kernel function
03-31-2011, 09:37 AM
Suppose in Kernel function there will be n work items performing some task, if one of the work item finishes its task early then it has to terminate and all other work item must also terminate. Can you help me how to do this
03-31-2011, 05:13 PM
There's no good way to do that. You could use something like a __local integer variable and force work-items to poll the value of that variable. When a work-item finishes it will set the variable to 1, and when other work-items find that the variable is set to 1 they will return.
The kernel would look something like this:
__kernel void foo()
__local int done;
// The first work-item sets 'done=0'
done = 0;
// Ensure all work items see 'done=0' before they start to do any work.
// Do work here...
done = 1;
// All work items check whether the solution has been found
There may be better ways to do it. You could use atomics instead of barriers, although I don't know which one will be slower (it will depend on the implementation).
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.