我有多个内核,它们按如下顺序启动:
clEnqueueNDRangeKernel(..., kernel1, ...);
clEnqueueNDRangeKernel(..., kernel2, ...);
clEnqueueNDRangeKernel(..., kernel3, ...);
并且,多个内核共享一个全局缓冲区。
现在,我通过在 clEnqueueNDRangeKernel 之后添加代码块来分析每个内核执行并总结它们以计算总执行时间:
clFinish(cmdQueue);
status = clGetEventProfilingInfo(...,&starttime,...);
clGetEventProfilingInfo(...,&endtime,...);
time_spent = endtime - starttime;
我的问题是如何通过一个 clFinish 一起分析三个内核?(就像在最后一次内核启动后添加一个 clFinish() )。
是的,我给每个 clEnqueueNDRangeKernel 不同的时间事件,并得到大的负数。详细信息:
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event1);
clFinish(cmdQueue);
clGetEventProfilingInfo(timing_event1,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime1,NULL);
clGetEventProfilingInfo(timing_event1,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime1,NULL);
time_spent1 = endtime1 - starttime1;
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event2);
clFinish(cmdQueue);
clGetEventProfilingInfo(timing_event2,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime2,NULL);
clGetEventProfilingInfo(timing_event2,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime2,NULL);
time_spent2 = endtime2 - starttime2;
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event3);
clFinish(cmdQueue);
clGetEventProfilingInfo(timing_event3,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime3,NULL);
clGetEventProfilingInfo(timing_event3,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime3,NULL);
time_spent3 = endtime3 - starttime3;
time_spent_all_0 = time_spent1 + time_spent2 + time_spent3;
time_spent_all_1 = endtime3 - starttime1;
如果我有每个 clFinish,所有分析值都是合理的,但是 time_spent_all_1 大约是 time_spent_all_0 的 2 倍。如果我删除除最后一个 clFinish 之外的所有 clFinish,则所有分析值都是不合理的。
感谢 Eric Bainville,我得到了我想要的结果:通过一个 clFinish 分析多个 clEnqueueNDRangeKernel。以下是我使用的最终代码:
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event1);
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event2);
clEnqueueNDRangeKernel(cmdQueue,...,&timing_event3);
clFinish(cmdQueue);
clGetEventProfilingInfo(timing_event1,CL_PROFILING_COMMAND_START,sizeof(cl_ulong),&starttime,NULL);
clGetEventProfilingInfo(timing_event3,CL_PROFILING_COMMAND_END,sizeof(cl_ulong),&endtime,NULL);
time_spent = endtime - starttime;