Reputation: 107
Let's say there are two Command Queues and I want to synchronize them using events. It can be done like this:
cl_event event1;
clEnqueueNDRangeKernel(queue1, <..params..>, 0, NULL, &event1);
cl_event event2;
clEnqueueNDRangeKernel(queue2, <..params..>, 0, NULL, &event2);
clEnqueueNDRangeKernel(queue1, <..params..>, 1, &event2, NULL);
clEnqueueNDRangeKernel(queue2, <..params..>, 1, &event1, NULL);
Is there a possibility to achive similar results but with a different order of clEnqueueNDRangeKernel calls? For example:
cl_event event1;
cl_event event2;
clEnqueueNDRangeKernel(queue1, <..params..>, 0, NULL, &event1);
clEnqueueNDRangeKernel(queue1, <..params..>, 1, &event2, NULL); //it fails here because event2 does not exist
clEnqueueNDRangeKernel(queue2, <..params..>, 0, NULL, &event2);
clEnqueueNDRangeKernel(queue2, <..params..>, 1, &event1, NULL);
Upvotes: 0
Views: 297
Reputation: 1119
Is it possibile in OpenCL to wait for an event that has not been returned by clEnqueueNDRangeKernel yet?
Not really, but there's a different approach possible.
You could create a user event (clCreateUserEvent
) and use the returned userEvent
instead of event2
argument in the enqueue call. Then, after enqueueing a kernel that creates event2
, you add a callback (clSetEventCallback
) on event2
, and from that callback you call clSetUserEventStatus(userEvent, CL_COMPLETE)
.
There are only two problems with this, 1) even if the most common OpenCL implementations weren't horrible WRT user events, you're introducing unnecessary userspace trips (= slowdown), 2) they are horrible WRT user events. By which i mean, the callback will be called... at some point. It's not unusual to see it called with 10-200ms delay after the event has actually finished.
You could get more useful answers if you said what is the problem you're trying to solve.
Upvotes: 1