yewei
yewei

Reputation: 241

is there some method in OpenCL to count kernel time like cuda's time function

In cuda there is a function named time() in kernel to test latency between some functions; for example,

__global__ void kmulu_dep512() {
start_time = clock(); 
repeat256(t *= t2 ; t2 *= t ; )
stop_time = clock();
}

I cannot find OpenCL have similar function, is there some method to workround in OpenCL in order to get the similar effect?

Upvotes: 1

Views: 111

Answers (1)

Alexey Sachkov
Alexey Sachkov

Reputation: 11

AFAIK, there is no such built-in in OpenCL, but you can do that via host API: look for information about event profiling info in OpenCL.

Briefly, you will need to create a command queue with profiling info enabled and then query command start/end time points from the event corresponding to a kernel you are interested in:

g_cmd_queue = clCreateCommandQueue(... CL_QUEUE_PROFILING_ENABLE, NULL);
clEnqueueNDRangeKernel(g_cmd_queue, ..., &perf_event);
clWaitForEvents(1, &perf_event);
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);

Upvotes: 1

Related Questions