Reputation: 3072
First, i'm relativly new to OpenCL.
Question 1: Is there a way to determine at runtime if a device is already running another kernel.
My Use-Case: i've a host programm asynchron calling different OpenCL function, which may or may not use the same Device. There a functions which can run acceptable fast on CPU, so waiting for the Device to be ready can be a bottleneck. I want to determine if the Device is already in use, and if so run a fallback function on the CPU.
Question 2: If the anwser to Question 1 is no. Is there any other possibility, than writing my own Device-Class?
Upvotes: 0
Views: 386
Reputation: 9925
There is no dedicated API for querying whether a device is currently executing a kernel, but you can implement this yourself using event objects.
Whenever you enqueue a kernel, you can optionally retrieve an event object which identifies that command. Using clGetEventInfo
and the CL_EVENT_COMMAND_EXECUTION_STATUS
query, you can check whether a particular command has finished executing. By keeping a reference to the event object for the most recently enqueued kernel, you can use this API to check whether or not a device currently has pending kernel commands in its queue.
Of course, this only allows you to determine if there are pending kernels from your application - there is no way to check whether there are pending kernels from other OpenCL applications that might also be running on the system.
Upvotes: 1