Results 1 to 2 of 2

Thread: reg kernel function

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    13

    reg kernel function

    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

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: reg kernel function

    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:
    Code :
    __kernel void foo()
    {
        __local int done;
     
        // The first work-item sets 'done=0'
        if(!get_global_id(0))
        {
            done = 0;
        }
     
        // Ensure all work items see 'done=0' before they start to do any work.
        barrier(CLK_LOCAL_MEM_FENCE);
     
        for(...)
        {
            // Do work here...
            if(this_work_item_found_the_solution)
            {
                done = 1;
            }
     
            // All work items check whether the solution has been found
            barrier(CLK_LOCAL_MEM_FENCE);
            if(done)
            {
                return;
            }
        }
    }

    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).
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. reg kernel function
    By paviraj_1989 in forum OpenCL
    Replies: 0
    Last Post: 04-25-2011, 05:46 AM
  2. reg kernel function
    By paviraj_1989 in forum OpenCL
    Replies: 0
    Last Post: 03-19-2011, 10:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •