0

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.

Vanya
  • 411
  • 1
  • 5
  • 21
  • does it have to wait for a specific amount of time, or can you use an interrupt like `clWaitForEvents`? – cegfault Jun 19 '14 at 02:21
  • Yes it does need to wait for a specific amount of time, i already looked at the `clWaitForEvents` – Vanya Jun 19 '14 at 02:24
  • I'm not too familiar with opencl, but doesn't `sleep` work? – cegfault Jun 19 '14 at 02:31
  • but it requires `include ` – Vanya Jun 19 '14 at 03:22
  • Ok i will try to include the default header in the CL and see what happens. – Vanya Jun 19 '14 at 13:08
  • Hmm i did place Sleep in the code like so `Sleep(10000);` and it seems that the kernel is built successfully with `clBuildProgram`. Is there way i can debug the CL script to see if the `Sleep` is called successfully? – Vanya Jun 19 '14 at 13:21

2 Answers2

3

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.

DarkZeros
  • 8,235
  • 1
  • 26
  • 36
  • So i should use `clWaitForEvents` then? what i want to achieve is basically a throttling. – Vanya Jun 19 '14 at 16:32
  • All the execution control of the device has to be done at host side. The device has to care only about completing the queued jobs, as fast as possible. That's all. If you intent to slow down the execution then do it at host side. – DarkZeros Jun 19 '14 at 16:48
1

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).

Community
  • 1
  • 1
Tim
  • 2,708
  • 1
  • 18
  • 32