OpenCL Kernel wait/delay

2019-09-05 22:39发布

问题:

I'am new to the OpenCL. How can i make a delay in OpenCL Kernel script without making loops? I have a code that's in some circumstances needs to wait for some time and then resume execution like so

__kernel void test(uint4 value,uint4 delay)
{
    uint id = get_global_id(0);

       //some code
       for(uint i=0;i<delay;i++) { //... do nothing like this? }
}

But i suppose that the loop will make gpu busy as hell, is there something i can use like sleep maybe in the kernel CL? I looked up in the sdk documentation, but haven't found anything yet. Help please.

回答1:

The OpenCL spec is designed for data crunching. Not for wait/sleeps. Even if you may achieve it, you will be breaking a lot of the good design rules of OpenCL.

In fact, many GPUs will crash or kill the execution if you try to sleep them.

Please reconsider what you need, and if it is suitable for parallel computing.



回答2:

Not typically. If you stall too long in a GPU kernel the driver TDRs and crashes. In general kernels aren't intended to sleep. See this question and this question.

Also, if you do want to induce a loop you'll have to be careful to make the code actually do something the compiler can't optimize away (write to a buffer).