What does OpenCL kernel execution time includes in OpenCL code?
我想问一个简单的问题。在 OpenCL 代码中创建 OpenCL 上下文和执行 OpenCL 内核之间的时间差可以称为内核时间吗?并且是
time_t start1,end1;
1 2 3 4 5 | clock_t start2,end2; start1=time(NULL); start2=clock(); |
有能力计算这个时间吗?
简单地说——不。测量内核时间的正确方法是获取与内核相关联的 OpenCL 事件并收集分析信息。这样做是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 | cl_int ret; cl_command_queue queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &ret); ... cl_event my_event; ret = clEnqueueNDRangeKernel(queue, kernel, 1, global_offset, global_size, local_size, num_events, wait_list, &my_event); clWaitForEvents(1, &my_event); cl_ulong start, finish; ret = clGetEventProfilingInfo(my_event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL); ret = clGetEventProfilingInfo(my_event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &finish, NULL); cl_ulong time_ns = finish - start; |