The following code snippet measures kernel execution using the OpenCL™
profiling events (error handling is omitted):
g_cmd_queue = clCreateCommandQueue(…CL_QUEUE_PROFILING_ENABLE, NULL);
cl_ulong start = 0, end = 0;
clGetEventProfilingInfo(perf_event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL);
clGetEventProfilingInfo(perf_event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end, NULL);
//END-START gives you hints on kind of “pure HW execution time”
//the resolution of the events is 1e-09 sec
g_NDRangePureExecTimeMs = (cl_double)(end - start)*(cl_double)(1e-06);
Also consider the following:
Enable the queue for profiling by use of the
property in creation time.
Explicitly synchronize the operation using
because device time counters for the
profiled command are associated with the specified event.
Using the profiling operations, you can profile operations on both memory
objects and kernels. Refer to section 5.12 of the OpenCL 1.2 Specification
for the detailed description of profiling events.
: The host-side wall-clock time might
return different results. For the CPU device, the difference is typically
OpenCL 1.2 Specification at