vonaka
vonaka

Reputation: 953

Wait for OpenCL kernel termination, but only during some time

To wait for kernel termination on the host side I can do this:

error = clEnqueueNDRangeKernel(..., &event);
CHECK_ERROR(error);
clWaitForEvents(1, &event);

But is there a way to precise some maximal time of waiting? That is, if my kernel is not finished after, let's say, 10 seconds I'd like to continue, but if it takes only one second of execution I don't want to wait for the 9 remaining seconds.

Upvotes: 0

Views: 449

Answers (1)

DarkZeros
DarkZeros

Reputation: 8410

There is no way to wait only for a given amount of time, however you can:

  • Check if the event has finished every N seconds via clGetEventInfo() and a loop.
  • Use clSetEventCallback() to define a function that will be called when the event completes. Sleep the current thread for 10 seconds, and make the event callback wake the thread if it finishes quicker than 10 seconds.

Upvotes: 1

Related Questions